How to create a vector tiles map with ngx-leaflet (Angular way)?

人走茶凉 提交于 2019-12-21 05:09:09

问题


Any good recommended angular 6+ supported libraries which can be used to accomplish the following task?

I'm using ngx-leaflet as the Map. I wish to create the map with Vectors rather than Rasters. I know that Leaflet doesn’t support vector tiles by default, however, you can accomplish via mapbox-gl-leaflet plugin.

Can anyone recommend me an approach or an appropriate library to accomplish this task using angular 6+?


回答1:


You may use Leaflet.VectorGrid plugin. See ngx-leaflet-starter and the associated demo.

  1. Install it via yarn add leaflet.vectorgrid
  2. Create binding file src/typings/leaflet.vectorgrid.d.ts defining API you want to use, eg:

    import * as L from "leaflet";
    
    declare module "leaflet" {
      namespace vectorGrid {
        export function slicer(data: any, options?: any): any;
      }
    }
    
  3. Load your vector tiles, for instance:

    // add import statement
    import * as L from "leaflet";
    // then call...
    loadGeojson() {
        this.http.get("assets/airports.min.geojson").subscribe(result => {
                this.vtLayer = L.vectorGrid.slicer(result, {
                  zIndex: 1000
                });
                this.vtLayer.addTo(this.map);
        });
    }
    


来源:https://stackoverflow.com/questions/53397240/how-to-create-a-vector-tiles-map-with-ngx-leaflet-angular-way

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!