前言 在上一篇博客中,详细讲述了在LeafLet.js中集成VectorGrid插件进行矢量瓦片渲染的案例,原文连接基于VectorGrid加载GeoServer发布的矢量瓦片实例,感兴趣的朋友可以直接点击链接进行查阅之前的博文 一、VectorGrid相关API介绍 要想使用VectorGrid进行矢量瓦片的渲染,样式必不可少。 1、VectorGrid A VectorGrid is a generic, abstract class for displaying tiled vector data. it provides v=1.0.0"></script><script src="https://unpkg.com/leaflet.<em>vectorgrid</em>@latest/dist/Leaflet.<em>VectorGrid</em>.bundled.js "></script> <script src="https://unpkg.com/leaflet.<em>vectorgrid</em>@latest/dist/Leaflet.<em>VectorGrid</em>.js"><
这里简单介绍VectorGrid插件,以及其它可以选择的矢量瓦片展示插件。·在Leaflet的官方网站上可以看到以下的介绍瓦片的介绍,其中有一个是关于Vector Tiles的介绍。 打开效果如下:二、与LeafLet集成1、新建html页面 在文件夹中创建index_vectorgrid.html网页,示例代码如下:<! v=1.0.0"></script><script src="https://unpkg.com/leaflet.<em>vectorgrid</em>@latest/dist/Leaflet.<em>VectorGrid</em>.bundled.js "></script> <script src="https://unpkg.com/leaflet.<em>vectorgrid</em>@latest/dist/Leaflet.<em>VectorGrid</em>.js">< (pbfUrl, vectorTileOptions).addTo(mymap)到此,在Leaflet中将VectorGrid进行集成展示的例子就完成了。
综合分析之后我选用了Leaflet.VectorGrid插件进行矢量瓦片的渲染,Github地址https://github.com/IvanSanchez/Leaflet.VectorGrid。 2.1 添加插件 除了正常的Leftlet所需的js以及css文件外(具体请自行搜索),还需添加一下语句引入vectorgrid的js文件。 <script src="https://unpkg.com/leaflet.<em>vectorgrid</em>@1.2.0"></script> 当然你可以直接将此文件下载到本地引入。 vectorTileLayerStyles: osm_poi_style, subdomains: '0123', interactive: true, // Make sure that this VectorGrid mouse/pointer events key: '5iCgspbpUIw5lEYGLbGj', maxZoom: 16 }; var openmaptilesPbfLayer = L.vectorGrid.protobuf