簡體   English   中英

使用Leaflet UTFGrid的Javascript事件處理程序

[英]Javascript event handlers using Leaflet UTFGrid

我覺得這是一個顯而易見的問題,但這讓我很困惑,我不確定如何調試它。 可能只是我的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/leaflet@1.0.3/dist/leaflet.css" />
    <script src="https://unpkg.com/leaflet@1.0.3/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之間的版本問題。 當我使用舊版傳單時,它可以工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM