我正在尝试在leaflet中在标记之间插入线条(这些标记是从JSON数据生成的)。 我看到了一个例子,但它不能与JSON数据一起使用。 我可以看到标记,但没有线条出现。
var style = {
color: 'red',
fillColor: "#ff7800",
opacity: 1.0,
fillOpacity: 0.8,
weight: 2
};
$.getJSON('./server?id_dispositivo=' + id_device + '', function(data) {
window.geojson = L.geoJson(data, {
onEachFeature: function (feature, layer) {
var Icon = L.icon({
iconUrl: './images/mymarker.png',
iconSize: [18, 28], // size of the icon
style: style,
});
layer.setIcon(Icon);
layer.bindPopup(feature.properties.date + '<br />' + feature.properties.id);
}
});
});
map.addLayer(geojson);
我的JSON数据:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-70.219841,
8.6310997
]
},
"properties": {
"id": 336,
"id_user": 1,
"id_device": 1,
"timestamp": 1446571154,
"date": "12:49PM 03-11-2015",
"Latitude": 8.6310997,
"Longitude": -70.219841,
"speedKPH": 0,
"heading": "",
"Name": "N\/D",
"City": "N\/D",
"estatus": "Stop"
}
}
]
}
]}
。省略闭合括号是常见的粘贴错误,所以我添加了它们。如果JSON数据仍然不完整,OP将不得不编辑问题。按照现在的写法,它是有效的。 - Dan Lowe