【发布时间】:2016-04-12 02:19:37
【问题描述】:
我正在尝试将弹出窗口添加到传单地图中,该地图显示不同采矿地点周围的缓冲区。当我单击缓冲区多边形时,我想获取矿井名称信息。这是我的代码,
<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>
我是 Leaflet 和 Javascript 的新手,非常感谢任何帮助!
编辑:当滚动多边形与非多边形时,我的光标会发生变化,所以我相信通过鼠标单击可以检索信息。由于没有显示任何内容,我假设这是一个 HTML/CSS 问题,也许我还没有创建任何窗口让这些信息进入?
【问题讨论】:
标签: javascript leaflet geojson