Created
May 10, 2011 07:34
-
-
Save MaZderMind/964045 to your computer and use it in GitHub Desktop.
Thinking about a rendering framework in js, following http://blog.jochentopf.com/2011-03-22-new-approaches-for-map-rendering.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var style = require('./style.js'); | |
// postgres reader | |
var r = new PostgresReader({ | |
db: 'mapnik', | |
user: 'osm', | |
pass: 'pass', | |
// one could query imposm-like tables, too | |
tables: { | |
point: { | |
name: 'planet_osm_point', | |
select: '*', | |
geom: 'way' | |
}, | |
line: { | |
name: 'planet_osm_line', | |
select: '*', | |
geom: 'way' | |
} | |
} | |
}); | |
// canvas to paint to | |
var c = new Canvas(); | |
style.apply(r, c); | |
r.on('ended', function() { | |
c.save('out.png'); | |
}); | |
r.start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.apply = function(r, c) { | |
// some boundingbox | |
var germany = new BBox(1, 2, 3, 4); | |
// render cities | |
r.on('point').tag({'place': 'city'}).on(function(point) { | |
c.drawText({ | |
text: point.attr.title, | |
geom: point.geom, | |
style: { | |
// use a different color in germany | |
'font-color': germany.contains(point.geom) ? 'blue' : 'red' | |
} | |
}); | |
}); | |
// alternatively one could specify a different rule for germany using the filter chain | |
// render villages inside germany | |
r.on('point').tag({'place': 'village'}).inside(germany).on(function(point) { | |
c.drawText({ | |
text: point.title, | |
geom: point.geom, | |
style: { | |
'font-color': 'green' | |
} | |
}); | |
}); | |
// render villages outside germany | |
r.on('point').tag({'place': 'village'}).outside(germany).on(function(point) { | |
c.drawText({ | |
text: point.attr.title, | |
geom: point.geom, | |
style: { | |
'font-color': 'yellow' | |
} | |
}); | |
}); | |
// add highways to highway grid | |
var highways = new Grid(); | |
r.on('line').tag('highway').on(function(line) { | |
highways.add(line); | |
}); | |
// render highway grid | |
r.on('ending', function() { | |
c.drawGrid({ | |
grid: highways, | |
style: { | |
'stroke-color': 'red' | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment