-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Initialize map with spotlight enabled | ||
var map = L.map( | ||
'map', { | ||
spotlight: true, // This one enables spotlight on the map | ||
scrollWheelZoom:false, | ||
zoomControl: false, | ||
boxZoom: false, | ||
doubleClickZoom: false, | ||
dragging: false | ||
}).setView([50.11703222529853, 8.679703474044802], 18); | ||
|
||
// Alternate method of enabling spotlight | ||
//map.spotlight.enable(); | ||
|
||
// Define default style for points (small black dot) | ||
var pointStyle = { | ||
radius: 2, | ||
opacity: 0, | ||
fillColor: "#000000", | ||
fillOpacity: 1 | ||
} | ||
|
||
// Add layer to map | ||
var pointLayer = L.geoJSON(pointData, { | ||
pointToLayer: function (feature, latlng) { | ||
return L.circleMarker(latlng, pointStyle); | ||
} | ||
}).addTo(map); | ||
|
||
// Define a function which takes a leaflet latlng as input and returns a turf polygon geometry (in this case, a circle) | ||
var dynamicCenterCircle = function (center) { | ||
return turf.circle( | ||
center, | ||
25, | ||
{"steps": 128, "units": "meters"} | ||
); | ||
} | ||
|
||
// Define a style for the spotlight polygon itself (in this case, a black ring) | ||
var mySpotlightStyle = { | ||
color: "#000000", | ||
fillOpacity: 0 | ||
}; | ||
|
||
// Define a style for a leaflet point | ||
var myPopupContent = function(feature) { | ||
// console.log(feature) | ||
return '<p>' + feature.properties.id + '</p>'; | ||
}; | ||
|
||
// Define a spotlight object and add it to the map using the ".addTo()" method | ||
var mySpotlight = L.spotlight({ | ||
spotlightType: "popup", | ||
spotlightShape: dynamicCenterCircle, // Function which takes leaflet point and returns a turf polygon | ||
popupContent: myPopupContent, // Style with which the spotlight itself shall be drawn | ||
spotlightStyle: mySpotlightStyle, // Style with which the spotlight itself shall be drawn | ||
targetLayer: pointLayer // Layer onto which to apply the spotlight | ||
}); | ||
|
||
// Make buttons control spotlight | ||
var toggleButton = document.getElementById("toggle-spotlight-button"); | ||
toggleButton.addEventListener("click", function(e) { | ||
if (!map.hasSpotlight(mySpotlight)) { | ||
mySpotlight.addTo(map); | ||
// Alternate method of adding a spotlight to a map | ||
// map.addSpotlight(mySpotlight); | ||
} else { | ||
map.removeSpotlight(mySpotlight) | ||
} | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#map { | ||
height: 95vh; | ||
} | ||
|
||
#toggle-spotlight-button { | ||
width: 100%; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Title</title> | ||
|
||
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" | ||
integrity="sha512-wcw6ts8Anuw10Mzh9Ytw4pylW8+NAD4ch3lqm9lzAsTxg0GFeJgoAtxuCLREZSC5lUXdVyo/7yfsqFjQ4S+aKw==" | ||
crossorigin=""/> | ||
<link rel="stylesheet" href="style.css"> | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.4.0/leaflet.js"></script> | ||
|
||
<script src="../../src/leaflet-spotlight-extension.js"></script> | ||
|
||
<script src='https://npmcdn.com/@turf/turf/turf.min.js'></script> | ||
<script src="../data/points_5000.js"></script> | ||
|
||
</head> | ||
<body> | ||
<button id="toggle-spotlight-button">Toggle Spotlight</button> | ||
<div id="map"></div> | ||
<br> | ||
<br> | ||
<script src="init.js"></script> | ||
</body> | ||
</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