|
var map = L.map('map-canvas'); |
|
|
|
L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', { |
|
attribution: 'Referentiekaart © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors', |
|
maxZoom: 19 |
|
}).addTo(map); |
|
|
|
map.attributionControl.setPrefix(''); |
|
|
|
var info = L.control(); |
|
|
|
info.onAdd = function (map) { |
|
this._div = L.DomUtil.create('div', 'info'); |
|
this.update(); |
|
return this._div; |
|
}; |
|
|
|
info.update = function (props) { |
|
var value,value1,value2,value3,value4; |
|
for (i = 0; i < kinderen.length; i++){ |
|
if (props && props.postcode == kinderen[i].postcode) { |
|
value = kinderen[i].postcode |
|
value1 = kinderen[i].kind0 |
|
value2 = kinderen[i].kind13 |
|
value3 = kinderen[i].kind34 |
|
value4 = kinderen[i].kind412 |
|
} |
|
} |
|
this._div.innerHTML = '<h4>Aantal kinderen</h4>' + (props ? |
|
'<b>' + value + '</b><br />' + '0 jaar:' + " " + value1 + '</b><br />' + |
|
'1-3 jaar:' + " " + value2 +'</b><br />' + |
|
'3-4 jaar:' + " " + value3 + '</b><br />' + |
|
'4-12 jaar:' +" " + value4 : 'Hover over de kaart'); |
|
}; |
|
|
|
info.addTo(map); |
|
|
|
function getColor(d) { |
|
return d < 0.05 ? '#edf8e9' : |
|
d < 0.1 ? '#c7e9c0' : |
|
d < 0.5 ? '#a1d99b' : |
|
d < 1.0 ? '#74c476' : |
|
d < 1.5 ? '#41ab5d' : |
|
d < 2.0 ? '#238b45' : |
|
'#005a32'; |
|
} |
|
|
|
function style(feature){ |
|
var value; |
|
for (i = 0; i < kinderen.length; i++) { |
|
if (feature.properties.postcode == kinderen[i].postcode) { |
|
value = kinderen[i].dichtheid |
|
} |
|
} |
|
return { |
|
weight: 1, |
|
opacity: 1, |
|
color: 'white', |
|
fillOpacity: 0.7, |
|
fillColor: getColor(value) |
|
}; |
|
} |
|
|
|
function highlightFeature(e) { |
|
info.update(e.target.feature.properties); |
|
var layer = e.target; |
|
|
|
layer.setStyle({ |
|
weight: 3, |
|
color: '#37ABC8', |
|
fillOpacity: 0.7 |
|
}); |
|
|
|
if (!L.Browser.ie && !L.Browser.opera) { |
|
layer.bringToFront(); |
|
} |
|
} |
|
|
|
var geojson = L.geoJson(null, {style: style,onEachFeature: onEachFeature}).addTo(map); |
|
|
|
function resetHighlight(e) { |
|
geojson.resetStyle(e.target); |
|
info.update(); |
|
} |
|
|
|
function zoomToFeature(e) { |
|
map.fitBounds(e.target.getBounds()); |
|
} |
|
|
|
function onEachFeature(feature, layer) { |
|
layer.on({ |
|
mouseover: highlightFeature, |
|
mouseout: resetHighlight, |
|
click: zoomToFeature |
|
}); |
|
} |
|
|
|
$.getJSON('http://places.geocoders.nl/demo/pc5/3812', function(data) { |
|
geojson.addData(data); |
|
map.fitBounds(geojson.getBounds()); |
|
}); |
|
|
|
geojson.getAttribution = function() { |
|
return 'brongegevens © <a href="http://www.cbs.nl/"><abbr title="Centraal Bureau voor de Statistiek">CBS</abbr></a>, postcodegebieden o.b.v. <abbr title="Basisregistratie Adressen en Gebouwen">BAG</abbr>, <a href="http://www.kadaster.nl/">Kadaster</a>.'; |
|
} |
|
|
|
var legend = L.control({position: 'bottomright'}); |
|
|
|
legend.onAdd = function (map) { |
|
var div = L.DomUtil.create('div', 'info legend'), |
|
grades = [0, 0.05, 0.1, 0.5, 1.0, 1.5, 2.0, ], |
|
labels = ['<strong>Kinderdichtheid</strong>']; |
|
for (var i = 0; i < grades.length; i++) { |
|
labels.push( |
|
'<i style="background:' + getColor(grades[i]) + '"></i> ' + |
|
grades[i] + (grades[i+1] ? '–' + grades[i+1] + ' / km²<br>' : '+ / km²')); |
|
} |
|
div.innerHTML = labels.join('<br>'); |
|
return div; |
|
}; |
|
|
|
legend.addTo(map); |