javascript - 使用 leaflet Js 创建 MultiPolyline

标签 javascript maps leaflet

过去(传单版本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).

https://github.com/Leaflet/Leaflet/blob/master/CHANGELOG.md

关于javascript - 使用 leaflet Js 创建 MultiPolyline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45371611/

相关文章:

Swift MapKit 不显示固定方向

javascript - 如何将分类图例添加到 Python Folium map ?

javascript - 如何传递从服务器返回的数据,然后将返回的数据转移到另一个路由?

javascript - Ember.js - 多个复选框绑定(bind)到单个数组

javascript - jscript if 用于全局变量

javascript - 按字符串属性值对对象数组进行排序

java - 将纬度/经度点转换为墨卡托投影上的像素 (x,y)

android - 在没有 Google API 的情况下使用 Google Map

R 传单 map : Include multiple rows of data in label popup

javascript - 传单图例未按预期工作