Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
336 views
in Technique[技术] by (71.8m points)

javascript - 如何在传单上实时在每个点上用标记制作线串?(How do I make line string in leaflet-realtime with marker on every point?)

I want something like below image:(我想要下图所示的内容:)

在此处输入图片说明 Don't know where to define linestring.(不知道在哪里定义线串。) It would be great if anyone can guide me.(如果有人可以指导我,那就太好了。) Moreover I want to change the color of linestring.(此外,我想更改线串的颜色。) Here is my code:-(这是我的代码:) function createRealtimeLayer(url, container) { return L.realtime(url, { interval: 5 * 1000, getFeatureId: function(f) { return f.properties.id; }, cache: true, container: container, onEachFeature(f, l) { date = f.properties.date; l.bindPopup(date); l.on("mouseover", function () { l.openPopup(); }); l.on("mouseout", function () { l.closePopup(); }); } }); } realtime1 = createRealtimeLayer('getPosition').addTo(map), realtime2 = createRealtimeLayer('getUserPositionHistory').addTo(map); L.control.layers(null, { 'Current': realtime1, 'History': realtime2 }).addTo(map); realtime1.once('update', function() { map.fitBounds(realtime1.getBounds(), {maxZoom: 18}); });   ask by Alia Jain translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

To set the markers on every point add this to your onEachFeature:(要在每个点上设置标记,请将其添加到onEachFeature中:)

if(layer instanceof L.Path){ l.getLatLngs().forEach(function(latlng){ L.marker(latlng).addTo(map); }) } if you want to colorize your line, you have to split up your line like that, but then append not the geojson layer to the map:(如果要给线着色,则必须像这样将线分开,但不要在地图上附加geojson图层:) if(layer instanceof L.Path){ var lastlatlng = null; layer.getLatLngs().forEach(function(latlng, i){ if(lastlatlng !== null){ L.polyline([lastlatlng,latlng],{color: getColor(i)}).addTo(map); } lastlatlng = latlng; }) } https://jsfiddle.net/falkedesign/bw290evz/(https://jsfiddle.net/falkedesign/bw290evz/)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...