Ich versuche, Popup-Fenster zu einer Leaflet-Map hinzuzufügen, die Pufferzonen um verschiedene Mining-Sites zeigt. Wenn ich auf ein Pufferzonenpolygon klicke, möchte ich die Minennamensinformationen erhalten. Hier ist mein Code,Hilfe zum Hinzufügen von Popup-Infofenstern zu Polygonen auf Leaflet-Map
<html>
<head>
<title>Buffer Zones around Mine</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css"/>
<script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
<style>
#map{ height: 100% }
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map').setView([45, -95], 4); //center map view
var CartoDB_Positron = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> © <a href="http://cartodb.com/attributions">CartoDB</a>',
subdomains: 'abcd',
maxZoom: 19
}).addTo(map);
// load JSON data
$.getJSON("BufferPolygons.json",function(data){
// add GeoJSON layer to the map once the file is loaded
L.geoJson(data).addTo(map);
});
//get popup info
var myLayer = L.geoJson(polygon, {
onEachFeature: yourOnEachFeatureFunction
}).addTo(map);
function yourOnEachFeatureFunction(feature, layer){
if (feature.properties.mine_name) {
layer.bindPopup(feature.properties.mine_name);
}
}
</script>
</body>
</html>
Ich bin neu zu Leaflet und Javascript, jede Hilfe würde sehr geschätzt werden!
Bearbeiten: Mein Cursor ändert sich beim Scrollen über Polygone im Vergleich zu Nicht-Polygonen, so dass ich glaube, dass Informationen mit einem Mausklick abgerufen werden. Da nichts angezeigt wird, gehe ich davon aus, dass es sich um ein HTML/CSS-Problem handelt. Vielleicht habe ich kein Fenster für diese Informationen erstellt.