leaflet-webpack 入門開發系列六矢量瓦片(附源碼下載)


前言

leaflet-webpack 入門開發系列環境知識點了解:

內容概覽

leaflet 矢量瓦片
源代碼 demo 下載

效果圖如下:

本篇主要利用 leaflet 的插件 leaflet.vectorgrid 實現兩種不同數據源的矢量瓦片渲染加載效果:

  1. 調用 geoserver 發布的 pbf 矢量瓦片服務
  2. 加載 geojson 數據源渲染矢量瓦片
    leaflet.vectorgrid 插件 github 地址:https://github.com/Leaflet/Leaflet.VectorGrid
  • 實現方式1:調用 geoserver 發布的 pbf 矢量瓦片服務
  1. geoserver 安裝矢量瓦片插件,用來拓展支持發布矢量瓦片服務,具體可以參考以下資料:
    https://www.jianshu.com/p/6d0cb4d0e432
    https://blog.csdn.net/qq_36061233/article/details/84751073
    https://blog.csdn.net/qq_28418387/article/details/82823725
  2. geoserver 安裝好矢量瓦片以及發布矢量瓦片服務之后,可以利用 leaflet.vectorgrid 插件來調用矢量瓦片服務渲染加載
//加載Pbf形式矢量瓦片函數
function loadVectorPbfLayer() {
// var localUrl = "http://localhost:8080/geoserver/gwc/service/wmts?" +
// "REQUEST=GetTile&SERVICE=WMTS&VERSION=1.0.0&LAYER=ZKYGIS:bs_spot_t" +
// "&STYLE=&TILEMATRIX=EPSG:900913:{z}&TILEMATRIXSET=EPSG:900913&" +
// "FORMAT=application/x-protobuf;type=mapbox-vector&TILECOL={x}&TILEROW={y}";
var localUrl = "http://localhost:8080/geoserver/gwc/service/tms/1.0.0/ZKYGIS:bs_spot_t@EPSG:900913@pbf/{z}/{x}/{-y}.pbf";
var localVectorTileOptions = {
rendererFactory: L.canvas.tile,//渲染方式 canvas
interactive: true,//設置true,允許鼠標交互事件
getFeatureId: function (f) {
return f.properties.map_num;
},
//rendererFactory: L.svg.tile,
vectorTileLayerStyles: getSpotVectorStyles("bs_spot_t"),//設置矢量渲染的樣式符號
};
……

完整demo源碼見小專欄文章尾部GIS之家leaflet小專欄

文章尾部提供源代碼下載,對本專欄感興趣的話,可以關注一波


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM