Search code examples
angular5ngx-leaflet

How to use leaflet-extra/leaflet-providers with ngx-leaflet?


How can I use leaflet-extra/leaflet-providers with ngx-leaflet. A simple example would be nice. I installed leaflet, @types/leaflet, ngx-leaflet, leaflet-providers, @types/leaflet-providers, but I cannot figure out how exactly to link ngx-leaflet with tileLayer.providers('ProviderId'). there should be an .addTo(???map???) call. Thanks.


Solution

  • If you need access to the map reference, you can follow the instructions here: https://github.com/Asymmetrik/ngx-leaflet#getting-a-reference-to-the-map

    There's also a guide with a bunch of examples of how to integrate Leaflet plugins located here: https://github.com/Asymmetrik/ngx-leaflet-tutorial-plugins

    It sounds like with this example, you would use the providers plugin to create layers that you'd add to the layers array you are providing to the leafletLayers input binding or the leafletLayersControl input binding.

    You'd just need to create the layers and add them to the appropriate array or object.

    If you can provide some more specific example code I can give you more detail.