From 5281dbe99d11769058df165344cb768a325844e8 Mon Sep 17 00:00:00 2001 From: Vladimir Agafonkin Date: Fri, 3 Aug 2012 15:57:59 +0300 Subject: [PATCH] improve geojson example more --- debug/vector/geojson.html | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/debug/vector/geojson.html b/debug/vector/geojson.html index fb7d7af9..3c615f4e 100644 --- a/debug/vector/geojson.html +++ b/debug/vector/geojson.html @@ -10,12 +10,11 @@ @@ -38,9 +37,6 @@ }).addTo(map); - L.control.scale().addTo(map); - - var info = L.Util.extend(L.control(), { onAdd: function (map) { @@ -50,10 +46,10 @@ }, setFeature: function (feature) { - this._div.innerHTML = feature ? + this._div.innerHTML = (feature ? '' + feature.properties.name + '' + - '
' + feature.properties.density + ' /mi2' - : 'Hover over a state'; + ': ' + feature.properties.density + ' /mi2' + : 'Hover over a state'); } }); @@ -77,24 +73,32 @@ } function highlightFeature(e) { - var style = L.Util.extend({}, defaultStyle, { - weight: 3, - color: '#555', + var layer = e.target; + + layer.bringToFront().setStyle({ + weight: 5, + color: '#666', dashArray: '' }); - e.target.setStyle(style).bringToFront(); + info.setFeature(e.target.feature); } function resetHighlight(e) { e.target.setStyle(defaultStyle); + info.setFeature(null); } + function zoomToFeature(e) { + map.fitBounds(e.target.getBounds()); + } + function onEachFeature(feature, layer) { layer.feature = feature; layer.on('mouseover', highlightFeature); layer.on('mouseout', resetHighlight); + layer.on('click', zoomToFeature); } var geojson = L.geoJson(statesData, {