过去(传单版本0.7)我使用了代码
var multipolyline = L.multiPolyline([[[35.10418, -106.62987],[35.19738, -106.875],[35.07946, -106.80634]],[[35.11654, -106.58318],[35.13142, -106.48876],[35.07384, -106.52412]]],{color: 'red',weight:8}).addTo(map);
用于创建具有多段折线的图层。
<html>
<head>
<title>Eine OSM Karte mit Leaflet</title>
<link rel="stylesheet" href="https://unpkg.com/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea868f8b8c868f9eaadbc4dbc4da" rel="noreferrer noopener nofollow">[email protected]</a>/dist/leaflet.css" />
</head>
<body>
<script src="http://cdn.leafletjs.com/leaflet-0.7.2/leaflet.js"></script>
<div id="map" style="width: 600px; height: 400px"></div>
<script>
var map = L.map('map',
{
center: [35.10418, -106.62987],
zoom: 10
});
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png').addTo(map);
var multipolyline = L.multiPolyline([[[35.10418, -106.62987],[35.19738, -106.875],[35.07946, -106.80634]],[[35.11654, -106.58318],[35.13142, -106.48876],[35.07384, -106.52412]]],{color: 'red',weight:8}).addTo(map);
</script>
</body>
</html>
此代码不适用于当前的传单版本 1.0.0,并且我在传单文档 ( http://leafletjs.com/reference-1.1.0.html ) 中没有找到 multiPolyline 类。所以我认为它已被删除。
如何创建一个包含许多折线的图层?我是否必须创建每条折线并将其添加到图层中,或者是否有其他函数可以完成此操作?
最佳答案
根据变更日志,您可以只使用 L.Polyline:
Removed MultiPolyline and MultiPolygon classes since multiple rings are now handled by Polyline and Polygon classes respectively. Layers with multiple rings now perform much better (since each is now physically a single path object instead of being a FeatureGroup of layers).
关于javascript - 使用 leaflet Js 创建 MultiPolyline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45371611/