Leaflet JS (react-leaflet) - Bounds Box Filled With Transparent Color

筅森魡賤 提交于 2019-12-25 07:15:05

问题


I'm working with react-leaflet package, however, if you can answer the question in plain leaflet that would be helpful as well.

I am successfully panning to the bounds of a polygon that I supply like so:

<Map center={position}
                 zoom={13}
                 bounds={this.state.bounds}
                 className="campaignimagery-map">
                 <TileLayer
                    url="http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
                    attribution=""
                 />

However, I would like the entire polygon boundary box to be some transparent color so they can see exactly where the boundary box lies on the map. Is this possible?


回答1:


Short answer

Use the bounds to draw a colored rectangle like this L.rectangle(bounds, {color: "#ff7800", weight: 1}).addTo(map);. See related documentation for more information.

Explanation

I don't think it's possible to color bounds as is, but you can use bounds for drawing a polygon. Then the polygon itself can be colored and managed as you wish.



来源:https://stackoverflow.com/questions/38234377/leaflet-js-react-leaflet-bounds-box-filled-with-transparent-color

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