Leafletjs:动态更改地图特征颜色 [英] Leafletjs: Dynamically changing map feature colors

查看:2071
本文介绍了Leafletjs:动态更改地图特征颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

几天以来,我一直在寻找一种方法,可以使用leaflet.js动态更改不同地图要素(例如,道路,水,建筑物,背景等)的颜色.我知道我们使用Mapbox GL在Mapbox中拥有此选项.但是我想知道是否可以使用leaflet.js库来实现.

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

推荐答案

默认情况下,Leaflet只能渲染栅格图块(即无法轻松修改的纯图像)和矢量形状(通常来自GeoJSON数据).

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

如果要修改图块渲染,则主要有3个选项:

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

  • 下载OSM数据,然后使用自己的样式重新渲染图块(即创建自己的图块服务器). OSM Wiki应该有一些页面来解释如何做到这一点.
  • 使用提供自定义样式(例如Mapbox)的图块渲染的在线服务.
  • Leaflet.VectorGrid 插件与从OSM下载的矢量数据一起使用,并提供自己的样式.
  • 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.

如果您希望能够在运行时修改渲染,则只有第3个选项才合适.

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

这篇关于Leafletjs:动态更改地图特征颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆