|
15 | 15 | elem.map = L.map(elementId).setView([location.lat, location.lon], zoom); |
16 | 16 | elem.map.addedMarkers = []; |
17 | 17 | L.tileLayer(tileUrl, { attribution: tileAttribution }).addTo(elem.map); |
| 18 | + |
| 19 | + location = L.circle([location.lat, location.lon], { |
| 20 | + color: location.color, |
| 21 | + fillOpacity: 0.05, |
| 22 | + radius: 50, |
| 23 | + id: 'location' |
| 24 | + }); |
| 25 | + elem.map.addLayer(location); |
18 | 26 | } |
19 | 27 |
|
20 | 28 | var map = elem.map; |
21 | 29 |
|
22 | | - location = L.circle([location.lat, location.lon], { |
23 | | - color: location.color, |
24 | | - fillOpacity: 0.5, |
25 | | - radius: 50, |
26 | | - id: 'location' |
27 | | - }); |
28 | | - map.addLayer(location); |
29 | | - |
30 | | - if (map.addedMarkers.length !== markers.length) { |
31 | | - // Markers have changed, so reset |
32 | | - map.addedMarkers.forEach(marker => marker.removeFrom(map)); |
33 | | - map.addedMarkers = markers.map(m => { |
34 | | - return L.marker([m.y, m.x]).bindPopup(m.description).addTo(map); |
35 | | - }); |
36 | | - |
37 | | - //// Auto-fit the view |
38 | | - //var markersGroup = new L.featureGroup(map.addedMarkers); |
39 | | - //map.fitBounds(markersGroup.getBounds().pad(0.3)); |
40 | | - |
41 | | - //// Show applicable popups. Can't do this until after the view was auto-fitted. |
42 | | - //markers.forEach((marker, index) => { |
43 | | - // if (marker.showPopup) { |
44 | | - // map.addedMarkers[index].openPopup(); |
45 | | - // } |
46 | | - //}); |
47 | | - } else { |
48 | | - // Same number of markers, so update positions/text without changing view bounds |
49 | | - markers.forEach((marker, index) => { |
50 | | - animateMarkerMove( |
51 | | - map.addedMarkers[index].setPopupContent(marker.description), |
52 | | - marker, |
53 | | - 4000); |
54 | | - }); |
55 | | - } |
| 30 | + //if (map.addedMarkers.length !== markers.length) { |
| 31 | + // // Markers have changed, so reset |
| 32 | + // //map.addedMarkers.forEach(marker => marker.removeFrom(map)); |
| 33 | + // //map.addedMarkers = markers.map(m => { |
| 34 | + // // return L.marker([m.y, m.x]).bindPopup(m.description).addTo(map); |
| 35 | + // //}); |
| 36 | + |
| 37 | + // //// Auto-fit the view |
| 38 | + // //var markersGroup = new L.featureGroup(map.addedMarkers); |
| 39 | + // //map.fitBounds(markersGroup.getBounds().pad(0.3)); |
| 40 | + |
| 41 | + // //// Show applicable popups. Can't do this until after the view was auto-fitted. |
| 42 | + // //markers.forEach((marker, index) => { |
| 43 | + // // if (marker.showPopup) { |
| 44 | + // // map.addedMarkers[index].openPopup(); |
| 45 | + // // } |
| 46 | + // //}); |
| 47 | + //} else { |
| 48 | + // // Same number of markers, so update positions/text without changing view bounds |
| 49 | + // markers.forEach((marker, index) => { |
| 50 | + // animateMarkerMove( |
| 51 | + // map.addedMarkers[index].setPopupContent(marker.description), |
| 52 | + // marker, |
| 53 | + // 4000); |
| 54 | + // }); |
| 55 | + //} |
56 | 56 |
|
57 | 57 | elem.style.height = window.innerHeight / 2 + "px"; |
58 | 58 | map.invalidateSize(); |
|
67 | 67 | var map = elem.map; |
68 | 68 | var layerGroup = L.layerGroup().addTo(map); |
69 | 69 |
|
70 | | - markers.forEach(setMarker); |
| 70 | + var corridors = []; |
| 71 | + var options = { |
| 72 | + corridor: 1000, // meters |
| 73 | + className: 'route-corridor' |
| 74 | + }; |
71 | 75 |
|
72 | | - function setMarker(m, index, array) { |
| 76 | + markers.forEach(element => setMarker(element, null, null, corridors)); |
| 77 | + |
| 78 | + //corridors.forEach(element => setCorridors(element, null, null, options)); |
| 79 | + |
| 80 | + function setMarker(m, index, array, corridors, options) { |
73 | 81 | marker = L.circle([m.lat, m.lon], { |
74 | 82 | color: m.color, |
75 | | - fillOpacity: 0.5, |
| 83 | + fillOpacity: 0.05, |
76 | 84 | radius: 50, |
77 | 85 | id: 'marker' |
78 | 86 | }); |
| 87 | + marker.bindPopup('Sat: ' + String(m.satNo) + ', Quality: ' + String(m.quality)); |
79 | 88 | layerGroup.addLayer(marker); |
| 89 | + |
| 90 | + ////add to corridor |
| 91 | + //if (!corridors[m.satNo]) { |
| 92 | + // corridors[m.satNo] = []; |
| 93 | + //} |
| 94 | + //if (m.alt > 100) { |
| 95 | + // corridors[m.satNo].push(L.latLng(m.lat, m.lon)); |
| 96 | + //} |
80 | 97 | } |
| 98 | + |
| 99 | + //function setCorridors(c, index, array, options) { |
| 100 | + // map.addLayer(L.corridor(c, options)); |
| 101 | + //} |
81 | 102 | }, |
82 | 103 |
|
83 | 104 | clearMarkers: function (elementId, location) { |
|
94 | 115 | }); |
95 | 116 | } |
96 | 117 | }; |
97 | | - |
98 | | - function animateMarkerMove(marker, coords, durationMs) { |
99 | | - if (marker.existingAnimation) { |
100 | | - cancelAnimationFrame(marker.existingAnimation.callbackHandle); |
101 | | - } |
102 | | - |
103 | | - marker.existingAnimation = { |
104 | | - startTime: new Date(), |
105 | | - durationMs: durationMs, |
106 | | - startCoords: { x: marker.getLatLng().lng, y: marker.getLatLng().lat }, |
107 | | - endCoords: coords, |
108 | | - callbackHandle: window.requestAnimationFrame(() => animateMarkerMoveFrame(marker)) |
109 | | - }; |
110 | | - } |
111 | | - |
112 | | - function animateMarkerMoveFrame(marker) { |
113 | | - var anim = marker.existingAnimation; |
114 | | - var proportionCompleted = (new Date().valueOf() - anim.startTime.valueOf()) / anim.durationMs; |
115 | | - var coordsNow = { |
116 | | - x: anim.startCoords.x + (anim.endCoords.x - anim.startCoords.x) * proportionCompleted, |
117 | | - y: anim.startCoords.y + (anim.endCoords.y - anim.startCoords.y) * proportionCompleted |
118 | | - }; |
119 | | - |
120 | | - marker.setLatLng([coordsNow.y, coordsNow.x]); |
121 | | - |
122 | | - if (proportionCompleted < 1) { |
123 | | - marker.existingAnimation.callbackHandle = window.requestAnimationFrame( |
124 | | - () => animateMarkerMoveFrame(marker)); |
125 | | - } |
126 | | - } |
127 | 118 | })(); |
0 commit comments