Giter Site home page Giter Site logo

Getting 'TypeError: cannot access 'dbname' of undefined while running examples\server.js and using examples\viewer\index.html about windwalker HOT 10 CLOSED

bhare1985 avatar bhare1985 commented on June 29, 2024
Getting 'TypeError: cannot access 'dbname' of undefined while running examples\server.js and using examples\viewer\index.html

from windwalker.

Comments (10)

BHare1985 avatar BHare1985 commented on June 29, 2024

Sorry about that, in my latest commits I added a setupMap function that is run when you want to setup more than one map/tileroute and forgot to do it for the default tileRoute (This plugin is used as an add-on to another node app that I made for work, so sometimes priority isn't on general usability).

Let me know if you have any issues or need any help setting anything up.

We are currently running this on windows server 2012 (development) and Amazon Linux (production) both with Sql Server 2012 as the datasource.

Try version 0.0.7 and see if that works better for you.

from windwalker.

BHare1985 avatar BHare1985 commented on June 29, 2024

FYI you'll want to run test\fixtures\mssql.test.sql to load test data for SQL server or test\fixtures\postgis.test.sqlfor PostGres/PostGIS

from windwalker.

arethasamuel avatar arethasamuel commented on June 29, 2024

[Wow,]
screen shot 2016-02-24 at 7 42 09 pm
thanks for your help. it works. You're brilliant, thank you for making this solution. it works great,
(i probably will have more questions, but how many cores and memory do you have running for your production environment? What would you recommend for let's say 500 tables?) thanks so much again

from windwalker.

BHare1985 avatar BHare1985 commented on June 29, 2024

Our production just has a t2.medium EC2 (4GB ram and I believe the core usage is probably shared) from amazon running elasticbeanstalk node (Beanstalk uses nginx as a frontend and will keep you node on 24/7 incase it crashes. You can also take advantage of nginx proxy_cache and AWS cloudfront/loadbalancing). We have just 4 tables running 4 main maps, but the content is all dynamic and we style on the fly based on user settings. It has no problem doing every road in the USA (~200 million geometries). The key to sql server is to make sure you set up spatial indices and tweak them. I normally use AUTO_GRID with ~4000 cells per object

from windwalker.

BHare1985 avatar BHare1985 commented on June 29, 2024

The example is a bit limited and I am bad at documenting new features so here is another example scrapped from work. Code doesnt compile because I took a lot of proprietary stuff out just to give you an idea how it can be customized:

I define a map called map1 and setup a route /:dbname/tiles/:session/:z/:x/:y.* which takes in a session id from the request. I have custom map styles saved in map1-default.css and load that in as a string and pass it along in the parameterParser

So in processTileRoute you a map key (map1), the request (req) and response (res) but also 3 optional functions you can define that state the behavior what to do when a new request comes in (parameterParser) what to do before a tile is rendered (beforeTileRender) and what to do after it's rendered (afterTileRender)

In my beforeTileRender I actually do a check if the data for the map has been updated, if it hasnt been updated then I throw a 304 not modified and complete skip over rendering the tile. If it does fallthrough and hit mapnik I set a cache-control in the header in afterTileRender.

These 3 functions allow you do anything you want as a request comes in such as dynamically change the SQL passed to Windwalker (in my example it renders a different map based on the sessionId sent in from the request) and also define extra steps before and after a tile is made.

(For example in our beforeTileRender we have a cache checker that checks Amazon s3 for the tile to see if its been download before it is, then we just use the S3 image rather than hitting Windwalker).

var map1 = {};


map1.defaultStyle = fs.readFileSync(path.resolve(__dirname, 'map1-default.css'), "UTF-8");


var config = {
    cacheMaxAge: 10 * 60,
    connection: global.environment.connection,
    windwalker: {
        dbtype: 'mssql',
        geom_type: 'polygon',
        enableCors: false,
        logRequests: true,
        logErrors: true,
        logErrorTrace: true,
        showErrors: false,
        grainstore: {
            mapnik_version: '2.3.0',
            default_style_version: '2.3.0',
            map: {srid: 3857},
            datasource: {
                host: global.environment.connection.host,
                port: global.environment.connection.port,
                user: global.environment.connection.user,
                password: global.environment.connection.password,
                geometry_field: "Geometry",
                extent: "-180,-90,180,90",
                srid: 4326,
                max_size: 10,
                use_filter: false,
                trace_flag_4199: false
            }
        }
    }
};

var app = new Windwalker.Server(config.windwalker);


app.setupMap('map1', { 
    grainstore: { 
        properties: { 
            'cache-features':  'on'
        }
    }
});

app.get('/:dbname/tiles/:session/:z/:x/:y/.*', function (req, res) {
    app.processTileRoute('map1', req, res, map1.parameterParser, app.beforeTileRender, app.afterTileRender);
});

app.getLastModified = function(sql, req, callback){
    SoSomeMagic(config.connection, sql, req, function(err, state) {
        if (err) callback(err);
        if(!state) callback(null);

        var lastModified = new Date(state);
        callback(null, lastModified);
    });
};

app.isNotModified = function(lastModified, req) {
    if (req.headers["if-modified-since"]) {
        if( new Date(req.headers["if-modified-since"]).getTime() == lastModified.getTime()) {
            return true;
        }
    }

    return false;
};

map1.parameterParser = function(req, callback){
    var style = null;
    var sql = null;
    var interactivity = null;

    style = map1.defaultStyle;
    sql = "SELECT [Geometry],[StyleIndex],[IsOneWay] FROM MAPNIK WHERE SessionId = " + req.params.session   
    interactivity = "Name";

    req.params.sql = "("+sql+") as map1"; 
    req.params.table = config.connection.table;
    req.params.interactivity = req.query.interactivity || interactivity;
    req.params.style = req.query.style || style;

    callback(null, req);
};


app.beforeTileRender = function(req, res, callback) {
    Step(
        function getLastModified(){
            var sql = null;
            sql = "SELECT lastModified FROM TABLE"
            app.getLastModified(sql, req, this);
        },
        function attempt304Tile(err, lastModified) {
            if (err) throw err;
            if(!lastModified) throw "LastModified was not found"; 

            res.setHeader('Last-Modified', lastModified.toUTCString());
            if(app.isNotModified(lastModified, req)) {
                res.statusCode = 304;
                return this(null, "Tile");
            }

            return this(null, null);
        },
        function handleErrors(err, tile, headers) {
            if(err) {
                callback(err);
            } else {
                callback(null, tile, headers);
            }
        }
    );
};


app.afterTileRender = function(req, res, tile, headers, callback) {

    if (config.cacheMaxAge){
        res.setHeader('Cache-Control', 'public, max-age='+config.cacheMaxAge);
    }

    return callback(null, tile, headers);
};


var port = process.env.PORT || 4000;
app.listen(port);

console.log("map tiles are now being served out of: http://localhost:" + port);` 

from windwalker.

arethasamuel avatar arethasamuel commented on June 29, 2024

Wow, you're really nice, thank you for helping me with this.

I'm taking my time digesting this, i will definitely use the algorithm you pasted.

one question, is it possible to to change this somewhere so that we can combine different layers into one image?

thanks again for your help

from windwalker.

arethasamuel avatar arethasamuel commented on June 29, 2024

Actually i just put a long sql union query, still so fast
screen shot 2016-02-26 at 2 40 21 pm

from windwalker.

BHare1985 avatar BHare1985 commented on June 29, 2024

If you dont need dynamic maps / style/ sql take a look at https://github.com/naturalatlas/tilestrata it uses mapnik too and has more features than Windwalker (Adding 2+ maps into one, vector tiles).

from windwalker.

arethasamuel avatar arethasamuel commented on June 29, 2024

Sorry, figured it out: had to take the mssql-win32.input file and place it in this folder: C:\Windwalker\node_modules\mapnik\lib\binding\node-v14-win32-x64\mapnik\input

from windwalker.

arethasamuel avatar arethasamuel commented on June 29, 2024

Hi, actually sql server is very fast, internet was slow at the office, sorry to bother you, everything is working great, thanks for all your help and advice. really appreciate it

from windwalker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.