Is there any way to create two color border in leaflet multipolygon, polygon?

老子叫甜甜 提交于 2019-12-11 12:56:09

问题


How can I create a custom border to multipolygon with leaflet? I would like to have inner border black and outer red or vice versa.

Example picture to show what I mean:

Is there any way to do this?


回答1:


You can use Leaflet Polyline Offset plugin to draw a duplicate polyline offset by a specified number of pixels and achieve somewhat the desired effect.

L.polyline([
  [48.3, 0.1],
  [48.3, 0.7],
  [48.7, 0.7],
  [48.7, 0.1],
  [48.3, 0.1]
], {
  fillColor: "none",
  weight: 4,
  lineJoin: "miter",
  color: "red"
}).addTo(map);

L.polyline([
  [48.3, 0.1],
  [48.3, 0.7],
  [48.7, 0.7],
  [48.7, 0.1],
  [48.3, 0.1]
], {
  fillColor: "none",
  weight: 4,
  lineJoin: "miter",
  color: "black",
  offset: -4 // Thanks to Leaflet Polyline Offset plugin
}).addTo(map);

There is however a "bug" at the polyline start and end, due to the fact that it is offset but not shorten / extended to close the gap with the beginning of the polyline.

Using an L.rectangle or an L.polygon shows a different bug, where the last segment is not offset. That could be a room for improvement for the plugin, if someone has the dedication to have a look, correct the bug and submit a Pull Request! :-)

Demo: http://jsfiddle.net/3v7hd2vx/42/



来源:https://stackoverflow.com/questions/38430112/is-there-any-way-to-create-two-color-border-in-leaflet-multipolygon-polygon

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