宣传单离线网格图层

时间:2016-11-28 16:05:23

标签: javascript leaflet

我希望传单脱机工作,没有标题,只显示网格作为标题。要获得Leaflet的所有功能,请添加插件以绘制线条,固定标记,绘制多边形,放大/缩小形状等。

有一种简单的方法可以显示一个简单的网格吗?

1 个答案:

答案 0 :(得分:2)

这是一个自定义GridLayer(已经由传单作者实现)。您所要做的就是复制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/gridcoords.html

代码取自:http://leafletjs.com/examples/extending/extending-2-layers.html