Leafletjs: Dynamically changing map feature colors

房东的猫 提交于 2019-12-02 05:15:14

问题


It's been a few days now that I have been looking for a way to be able to dynamically change the colors of different map features such as Roads, Water, Buildings, Background etc using leaflet.js. I know we had this option in Mapbox using the Mapbox GL. But I am wondering if this can be achieved using the leaflet.js library.

Any help/workaround would be highly appreciated. Thanks


回答1:


By default Leaflet can render only raster tiles (i.e. plain images, which you cannot easily modify) and vector shapes (typically from GeoJSON data).

If you want to modify the tiles rendering, you have mainly 3 options:

  • Download OSM data and re-render the tiles (i.e. create your own tile server) using your own styling. OSM wiki should have some pages that explain how to do so.
  • Use an online service that offers tiles rendering with custom style (e.g. Mapbox).
  • Use Leaflet.VectorGrid plugin with downloaded vector data from OSM and providing your own styling.

If you want to be able to modify the rendering at runtime, then only the 3rd option would be appropriate.



来源:https://stackoverflow.com/questions/48167068/leafletjs-dynamically-changing-map-feature-colors

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