javascript - Choropleth in Leaflet -
i'm new leaflet (and stackoverflow) , i've been trying choropleth show on map. have basic leaflet map shows up, when try geojson display, thrown error.
var map; window.onload = initialize(); function initialize(){ setmap(); }; function setmap() { map = l.map('map').setview([45, -90], 7); var layer = l.tilelayer('http://{s}.acetate.geoiq.com/tiles/acetate/{z}/{x}/{y}.png',{ attribution: 'acetate tileset geoiq', }).addto(map); var mylayer = l.geojson().addto(map); mylayer.adddata(counties); };
"counties" refers name of geojson file created. need style in anyway show up?
any great appreciated.
thanks!
to show yes. start with:
function getcolor(d) { return d > 1000 ? '#800026' : d > 500 ? '#bd0026' : d > 200 ? '#e31a1c' : d > 100 ? '#fc4e2a' : d > 50 ? '#fd8d3c' : d > 20 ? '#feb24c' : d > 10 ? '#fed976' : '#ffeda0'; //you pick own colors using css color wheel etc }
followed by:
function style(feature) { return { fillcolor: getcolor(feature.properties.density), //based on value in data weight: 2, opacity: 1, color: 'white', dasharray: '3', fillopacity: 0.7 }; } l.geojson(statesdata, {style: style}).addto(map);
in case wondering additional info on map. try this: http://leafletjs.com/examples/choropleth.html
Comments
Post a Comment