我有一个LatLng
列表,其中包含一些其他数据(例如海拔/海拔高度),我希望将leaflet显示为Polyline
。而不是单一的彩色线条,我希望根据其他数据对线条进行着色。
这可能与传单有关吗?插件是否存在类似的东西?
答案 0 :(得分:1)
有几个插件可以做到这一点。例如这一个: https://github.com/hgoebl/Leaflet.MultiOptionsPolyline
答案 1 :(得分:0)
您可以这样做:
var states = [{
"type": "Feature",
"properties": {"altitude": "high"},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-104.05, 48.99],
[-97.22, 48.98],
[-96.58, 45.94],
[-104.03, 45.94],
[-104.05, 48.99]
]]
}
}, {
"type": "Feature",
"properties": {"altitude": "low"},
"geometry": {
"type": "Polygon",
"coordinates": [[
[-109.05, 41.00],
[-102.06, 40.99],
[-102.03, 36.99],
[-109.04, 36.99],
[-109.05, 41.00]
]]
}
}];
L.geoJson(states, {
style: function(feature) {
switch (feature.properties.altitude) {
case 'high': return {color: "#ff0000"};
case 'low': return {color: "#0000ff"};
}
}
}).addTo(map);
有关详细信息,请参阅this。