diff options
author | Siri Reiter <siri@jones.dk> | 2018-05-20 21:17:12 +0200 |
---|---|---|
committer | Siri Reiter <siri@jones.dk> | 2018-05-20 21:17:12 +0200 |
commit | 22f268b88b91945df80935a142849e90e0a3ddb0 (patch) | |
tree | 41e2fb8964073e12d08f5ee0438653f9a04e10a5 | |
parent | ab27c721fa35beb6093272c420101e142ce7c36a (diff) |
Highlight on hover (for a single polygon).
-rw-r--r-- | src/js/tours.js | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/src/js/tours.js b/src/js/tours.js index 1819b5f..0224d29 100644 --- a/src/js/tours.js +++ b/src/js/tours.js @@ -19,6 +19,40 @@ requirejs(['./slippymap'], function(_foo) { map.layers.addOverlay(boundary(data), 'Regionsgrænse'); }); */ + +function style(feature) { + return { + weight: '2', + color: '#336699', + fillOpacity: '0.4' + }; +} + +var geojson; +function highlightFeature(e) { + var layer = e.target; + + layer.setStyle({ + weight: 5, + color: '#666', + dashArray: '', + fillOpacity: 0.7 + }); + + if (!L.Browser.ie && !L.Browser.opera && !L.Browser.edge) { + layer.bringToFront(); + } +} +function resetHighlight(e) { + geojson.resetStyle(e.target); +} +function onEachFeature(feature, layer) { + layer.on({ + mouseover: highlightFeature, + mouseout: resetHighlight + }); +} + var polygon = L.polygon([ [55.73275, 12.56572], [55.73247, 12.56692], @@ -52,8 +86,13 @@ var polygon = L.polygon([ [55.73127, 12.56357], [55.73131, 12.56424], [55.73124, 12.566] -]).addTo(map); -polygon.bindPopup("<a href=../../osterbro/>Ture på Østerbro</a>"); + ]); + +geojson = L.geoJson(polygon.toGeoJSON(), { + style: style, + onEachFeature: onEachFeature +}).addTo(map); +geojson.bindPopup("<a href=../../osterbro/>Ture på Østerbro</a>"); var polygon = L.polygon([ [55.69916, 12.59171], [55.69505, 12.59359], |