2016-11-28 109 views
1

我希望單張離線工作,無標題,只顯示網格作爲標題。要具備Leaflet的所有功能,請添加插件以繪製線條,固定標記,繪製多邊形,放大/縮小形狀等。單張離線網格圖層

是否有簡單的方法可以顯示簡單的網格?

回答

2

這是一個自定義GridLayer(這已由Leaflet作者實施)。您所要做的就是複製L.GridLayer.DebugCoords,您通常會在其中加載圖塊圖層。

var map = L.map('map', { 
    center: [0, 0], 
    zoom: 0 
}); 

L.GridLayer.DebugCoords = L.GridLayer.extend({ 
    createTile: function (coords, done) { 
     var tile = document.createElement('div'); 
     //this adds tile coordinates; you may or may not want this 
     tile.innerHTML = [coords.x, coords.y, coords.z].join(', '); 
     tile.style.outline = '1px solid red'; 

     /* // you don't need this artificial timeout for your application 
     setTimeout(function() { 
       done(null, tile); // Syntax is 'done(error, tile)' 
     }, 500 + Math.random() * 1500); 
     */ 

     return tile; 
    } 
}); 

L.gridLayer.debugCoords = function(opts) { 
    return new L.GridLayer.DebugCoords(opts); 
}; 

map.addLayer(L.gridLayer.debugCoords()); 

單機,工作示例:http://leafletjs.com/examples/extending/extending-2-layers.html

:取自 http://leafletjs.com/examples/extending/gridcoords.html

代碼