Skip to content

Instantly share code, notes, and snippets.

@yhahn
Last active August 29, 2015 14:07
Show Gist options
  • Save yhahn/57bf4435f0fcd05af3af to your computer and use it in GitHub Desktop.
Save yhahn/57bf4435f0fcd05af3af to your computer and use it in GitHub Desktop.
mapnik markersnapping testcase
<Map srs="+init=epsg:3857" background-color="#ffffff">
<Style name="points" filter-mode="first">
<Rule>
<Filter>[mapnik::geometry_type]=point</Filter>
<MarkersSymbolizer
file="pin-m.png"
allow-overlap="true"
ignore-placement="true"
/>
</Rule>
</Style>
<Layer name="layer" srs="+init=epsg:4326">
<StyleName>points</StyleName>
<Datasource>
<Parameter name="type">geojson</Parameter>
<Parameter name="inline"><![CDATA[{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-90,-8]},"properties":{}}]}]]></Parameter>
</Datasource>
</Layer>
</Map>
{
"name": "gist-pointsymbolizer",
"private": true,
"dependencies": {
"mapnik": "3.0.1",
"sphericalmercator": "1.0.x"
},
"scripts": {
"test": "node test.js"
}
}
<Map srs="+init=epsg:3857" background-color="#ffffff">
<Style name="points" filter-mode="first">
<Rule>
<Filter>[mapnik::geometry_type]=point</Filter>
<PointSymbolizer
file="pin-m.png"
allow-overlap="true"
ignore-placement="true"
/>
</Rule>
</Style>
<Layer name="layer" srs="+init=epsg:4326">
<StyleName>points</StyleName>
<Datasource>
<Parameter name="type">geojson</Parameter>
<Parameter name="inline"><![CDATA[{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[-90,-8]},"properties":{}}]}]]></Parameter>
</Datasource>
</Layer>
</Map>
var fs = require('fs');
var mapnik = require('mapnik');
var sm = new (require('sphericalmercator'))();
mapnik.register_default_input_plugins();
function test(name) {
var map = new mapnik.Map(256,256);
map.fromStringSync(fs.readFileSync(__dirname + '/' + name + '.xml', 'utf8'));
map.bufferSize = 64;
map.extent = sm.bbox(0,0,1,false,'900913');
var img1 = map.renderSync('png', new mapnik.Image(256,256));
map.extent = sm.bbox(0,1,1,false,'900913');
var img2 = map.renderSync('png', new mapnik.Image(256,256));
mapnik.blend([
{ buffer: img1, x:0, y:0 },
{ buffer: img2, x:0, y:256 }
], function(err, joined) {
if (err) throw err;
fs.writeFileSync(__dirname + '/' + name + '.png', joined);
});
}
test('marker');
test('point');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment