【发布时间】:2021-10-29 10:57:04
【问题描述】:
我有具有 LineString 特征类型的 GeoJSON 数据。我将使用L.geoJson() 函数显示这些数据。数据具有每个坐标的旋转属性。我想为每个坐标创建一个具有该旋转属性的标记。这是我的 geojson 数据。
{
"type": "Feature",
"properties": {
"name": "Track of bus 699",
"times": [
"2019-11-23 10:51:06",
"2019-11-23 10:52:05",
"2019-11-23 10:53:05",
"2019-11-23 10:54:04",
"2019-11-23 10:55:05",
"2019-11-23 10:56:05",
"2019-11-23 10:57:05",
"2019-11-23 10:58:05",
"2019-11-23 10:59:05",
"2019-11-23 11:00:06"
],
"rotation": [
0,
0,
15,
15,
20,
25,
35,
45,
55,
60
]
},
"geometry": {
"type": "LineString",
"coordinates": [
[
-4.4214296,
36.73835
],
[
-4.422104,
36.737865
],
[
-4.4229302,
36.73773
],
[
-4.4235334,
36.735817
],
[
-4.4222927,
36.73413
],
[
-4.4218254,
36.732475
],
[
-4.4213734,
36.72983
],
[
-4.420156,
36.73
],
[
-4.419239,
36.730686
],
[
-4.417272,
36.732136
]
]
}
}
我很困惑如何获取每个坐标的索引,以便我可以根据该索引获取旋转数据。
这是我的代码。我使用Leaflet.RotatedMarker 插件来旋转标记
var layer = L.geoJson(data, {
pointToLayer: function (feature, latLng) {
return new L.marker(latLng, {
icon: icon,
rotationAngle: feature.properties.rotation[index]
});
}
});
我尝试过使用Array.findIndex(),如果它具有相同的经纬度坐标,则返回索引,但有可能数据具有相同的坐标但旋转不同。
我也尝试过使用循环,但它并没有解决我的问题。
【问题讨论】: