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

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

问题描述

几天以来,我一直在寻找一种能够使用 Leaflet.js 动态更改不同地图特征(例如道路、水、建筑物、背景等)颜色的方法.我知道我们在 Mapbox 中使用 Mapbox GL 有这个选项.但我想知道这是否可以使用 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天全站免登陆