我觉得这是一个显而易见的问题,但这让我很困惑,我不确定如何调试它。可能只是我的javascript无知。
我正在从这里使用传单utfgrid脚本:https://github.com/danzel/Leaflet.utfgrid
我主要只是在跟踪示例脚本,因此无法使事件处理程序正常工作。至此,我已经掌握了非常基本的脚本。这是代码-我希望获得utfGrid.on('click')函数登录到控制台,但不会。感谢您的反馈意见。
<head>
<meta charset="UTF-8">
<title>Leaflet Test</title>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="http://danzel.github.io/Leaflet.utfgrid/src/leaflet.utfgrid.js"></script>
<style>
#map{ width: auto; height: 800px; }
</style>
</head>
<body>
Map Data Test
<div id ="hover"></div>
<div id="map"></div>
<script>
// load a tile layer
var basemap = L.tileLayer('http://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}.png', {attribution: 'CartoDB.', maxZoom: 18, minZoom: 2});
var cmamap = L.tileLayer('http://localhost:8080/tiles/{z}/{x}/{y}.png');
var utfGrid = new L.UtfGrid('http://localhost:8080/grid/{z}/{x}/{y}.json');
//event data
utfGrid.on('click', function (e) {
console.log('clicked');
});
//Create our map with just the base TileLayer
var map = L.map('map')
.setView([38, -94], 5)
.addLayer(basemap);
//Set up the base map and interactive stuff
var cmaLayers = L.layerGroup([
cmamap,
utfGrid
]).addTo(map);
</script>
</body>
最佳答案
因此,这看起来像是Leaflet插件和leaflet.utfgrid之间的版本问题。当我使用旧版传单时,它可以工作。