mapbox / mapnik-pool

manage a pool of mapnik map instances
Other
20 stars 22 forks source link

add the ability to create map pool from the array of layers #12 #13

Closed stepankuzmin closed 7 years ago

stepankuzmin commented 7 years ago

This PR will add fromLayers(arr, initOptions) method, wich allows to create map pool from array of Mapnik Layers like this:

var mapnik = require('mapnik'),
    mapnikPool = require('mapnik-pool')(mapnik),
    fs = require('fs');

var datasource = new mapnik.Datasource(...);
var layer = new mapnik.Layer(...);
layer.datasource = datasource;

var pool = mapnikPool.fromLayers([layer], { size: 256, srs: '...' });

pool.acquire(function(err, map) {
    // pooled map
    pool.release(map);
});

See #12 for issue.

springmeyer commented 7 years ago

👋 @stepankuzmin - thanks for providing this PR. I think I understand your usecase, but to make sure let me try to describe what you are doing:

If all of those things are true, then this PR looks good. However another alternative would be to:

I think this latter idea might sound odd and you might not like XML. However it has the advantage that is is fast and well tested. The node-mapnik API for dynamically adding layers is not a commonly used code pathway whereas the fromString is bombproof.

stepankuzmin commented 7 years ago

Wow, thanks @springmeyer! That's actually what I need! I did the trick like this: https://github.com/stepankuzmin/tilelive-postgis/blob/master/index.js#L40-L47

I didn't find the map.toXML() method in documentation http://mapnik.org/documentation/node-mapnik/, maybe we should add it? Nevertheless, you can close this PR. Thanks!

springmeyer commented 7 years ago

@stepankuzmin glad that helps. I've added docs for map.toXML in https://github.com/mapnik/node-mapnik/commit/89c0d43ce55329cd4bf32887717ad5612e16bbaf.