Skip to content

Commit a9b7b26

Browse files
committed
Added popups for spots on map. Added corridor, however had to disble it as same sat lines cross. Some geo crossing needs be established to eliminate intersections.
1 parent 9af84d3 commit a9b7b26

File tree

10 files changed

+162
-82
lines changed

10 files changed

+162
-82
lines changed

ComponentsLibrary/Map/Map.razor

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
catch { }
4646
}
4747

48-
public async Task ClearMarkers(Marker location)
48+
public async Task ClearMarkers()
4949
{
5050
if (!renderAllowed)
5151
{
@@ -56,8 +56,7 @@
5656
{
5757
await JSRuntime.InvokeVoidAsync(
5858
"deliveryMap.clearMarkers",
59-
elementId,
60-
location);
59+
elementId);
6160
}
6261
catch { }
6362
}

ComponentsLibrary/Map/Marker.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@ public class Marker
1111
public string Color { get; set; }
1212

1313
public bool ShowPopup { get; set; }
14+
public int SatNo { get; set; }
15+
public double Alt { get; set; }
16+
public double Quality { get; set; }
1417
}
1518
}

ComponentsLibrary/wwwroot/deliveryMap.js

Lines changed: 58 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,44 +15,44 @@
1515
elem.map = L.map(elementId).setView([location.lat, location.lon], zoom);
1616
elem.map.addedMarkers = [];
1717
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);
1826
}
1927

2028
var map = elem.map;
2129

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+
//}
5656

5757
elem.style.height = window.innerHeight / 2 + "px";
5858
map.invalidateSize();
@@ -67,17 +67,38 @@
6767
var map = elem.map;
6868
var layerGroup = L.layerGroup().addTo(map);
6969

70-
markers.forEach(setMarker);
70+
var corridors = [];
71+
var options = {
72+
corridor: 1000, // meters
73+
className: 'route-corridor'
74+
};
7175

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) {
7381
marker = L.circle([m.lat, m.lon], {
7482
color: m.color,
75-
fillOpacity: 0.5,
83+
fillOpacity: 0.05,
7684
radius: 50,
7785
id: 'marker'
7886
});
87+
marker.bindPopup('Sat: ' + String(m.satNo) + ', Quality: ' + String(m.quality));
7988
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+
//}
8097
}
98+
99+
//function setCorridors(c, index, array, options) {
100+
// map.addLayer(L.corridor(c, options));
101+
//}
81102
},
82103

83104
clearMarkers: function (elementId, location) {
@@ -94,34 +115,4 @@
94115
});
95116
}
96117
};
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-
}
127118
})();
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* https://github.com/adoroszlai/leaflet-distance-markers
3+
*
4+
* The MIT License (MIT)
5+
*
6+
* Copyright (c) 2014- Doroszlai Attila, 2016- Phil Whitehurst
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
9+
* this software and associated documentation files (the "Software"), to deal in
10+
* the Software without restriction, including without limitation the rights to
11+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
12+
* the Software, and to permit persons to whom the Software is furnished to do so,
13+
* subject to the following conditions:
14+
*
15+
* The above copyright notice and this permission notice shall be included in all
16+
* copies or substantial portions of the Software.
17+
*
18+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
20+
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
21+
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22+
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24+
*/
25+
26+
L.Corridor = L.Polyline.extend({
27+
initialize: function (latlngs, options) {
28+
var self = this;
29+
30+
L.Polyline.prototype.initialize.call(this, latlngs, options);
31+
32+
this.corridor = options.corridor;
33+
this.updateCallback = (function (e) {
34+
self._updateWeight(this);
35+
});
36+
},
37+
38+
onAdd: function(map) {
39+
L.Polyline.prototype.onAdd.call(this, map);
40+
map.on('zoomend', this.updateCallback);
41+
this._updateWeight(map);
42+
},
43+
44+
onRemove: function(map) {
45+
map.off('zoomend', this.updateCallback);
46+
L.Polyline.prototype.onRemove.call(this, map);
47+
},
48+
49+
_updateWeight: function(map) {
50+
this.setStyle({ 'weight': this._getWeight(map, this.corridor) });
51+
},
52+
53+
_getWeight: function (map, corridor) {
54+
return corridor * 2 / this._getMetersPerPixel(map);
55+
},
56+
57+
_getMetersPerPixel: function(map) {
58+
var centerLatLng = map.getCenter(); // get map center
59+
var pointC = map.latLngToContainerPoint(centerLatLng); // convert to containerpoint (pixels)
60+
var pointX = L.point(pointC.x + 10, pointC.y); // add 10 pixels to x
61+
62+
// convert containerpoints to latlng's
63+
var latLngX = map.containerPointToLatLng(pointX);
64+
return centerLatLng.distanceTo(latLngX) / 10; // calculate distance between c and x (latitude)
65+
}
66+
});
67+
68+
L.corridor = function (latlngs, options) {
69+
return new L.Corridor(latlngs, options || { corridor: 100 });
70+
}

IridiumLive/Data/ILColors.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ public static string ILColor(double altitude, double quality)
5858
switch ((int)quality)
5959
{
6060
case 100:
61-
return "#FF0000";
62-
case 99:
6361
return "#B22222";
62+
case 99:
63+
return "#FF0000";
6464
case 98:
6565
return "#DC143C";
6666
case 97:

IridiumLive/Pages/Live.razor

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
</div>
1414
<p>Red dots indicate the physical satellite position, blue dots indicate signal activity in ground vecinity.</p>
1515

16-
@if (viewIras == null || liveMap == null)
16+
@if (viewIras == null || liveMap == null || oldViewIras == null)
1717
{
1818
<p>Awaiting for data...</p>
1919
}
@@ -42,7 +42,7 @@ else
4242
<td>@context.Quality %</td>
4343
<td>@context.Beam</td>
4444
<td>@context.Lat N @context.Lon E</td>
45-
<td>@string.Format("{0} km", context.Alt);</td>
45+
<td>@string.Format("{0} km", context.Alt)</td>
4646
</MatTableRow>
4747
</MatTable>
4848
}
@@ -60,7 +60,7 @@ else
6060
{
6161
if (firstRender)
6262
{
63-
lastUtcTicks = DateTimeOffset.Now.AddSeconds(-10).UtcTicks;
63+
lastUtcTicks = DateTimeOffset.Now.AddSeconds(-15).UtcTicks;
6464
SetLocation(location);
6565
}
6666
StartTimer(interval);
@@ -89,7 +89,13 @@ else
8989
viewIras = await liveService.GetLiveIraAsync(lastUtcTicks);
9090
if (oldViewIras == null)
9191
{
92-
oldViewIras = viewIras;
92+
if (viewIras != null)
93+
{
94+
if (viewIras.Count > 0)
95+
{
96+
oldViewIras = viewIras;
97+
}
98+
}
9399
}
94100
var liveira = viewIras.LastOrDefault();
95101
if (liveira != null)
@@ -102,6 +108,9 @@ else
102108
m.Lat = record.Lat;
103109
m.Lon = record.Lon;
104110
m.Color = ILColors.ILColor(record.Alt, record.Quality);
111+
m.SatNo = record.SatNo;
112+
m.Alt = record.Alt;
113+
m.Quality = record.Quality;
105114
coloredMarkers.Add(m);
106115
}
107116

IridiumLive/Pages/Playback.razor

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ else
6161
//to gain the reference to liveMap we need to render the page at least once
6262
if (liveMap != null)
6363
{
64-
await liveMap.ClearMarkers(location);
64+
await liveMap.ClearMarkers();
6565
}
6666

6767
//Debug.WriteLine("ReloadOnTimer thread {0}", Thread.CurrentThread.ManagedThreadId);
@@ -79,6 +79,9 @@ else
7979
m.Lat = record.Lat;
8080
m.Lon = record.Lon;
8181
m.Color = ILColors.ILColor(record.Alt, record.Quality);
82+
m.SatNo = record.SatNo;
83+
m.Alt = record.Alt;
84+
m.Quality = record.Quality;
8285
coloredMarkers.Add(m);
8386
}
8487

IridiumLive/Pages/_Host.cshtml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
</head>
1919
<body>
2020
<app>
21-
@*Cannot do ServerPrerendered because of the current implementation of the polling mechanism.*@
22-
<component type="typeof(App)" render-mode="ServerPrerendered" />
21+
<component type="typeof(App)" render-mode="Server" />
2322
</app>
2423

2524
<div id="blazor-error-ui">
@@ -34,8 +33,9 @@
3433
</div>
3534

3635
<script src="_framework/blazor.server.js"></script>
37-
<script src="_content/ComponentsLibrary/deliveryMap.js"></script>
3836
<script src="_content/ComponentsLibrary/leaflet/leaflet.js"></script>
3937
<script src="_content/MatBlazor/dist/matBlazor.js"></script>
38+
<script src="_content/ComponentsLibrary/leaflet-corridor.js"></script>
39+
<script src="_content/ComponentsLibrary/deliveryMap.js"></script>
4040
</body>
4141
</html>

IridiumLive/Services/SatsService.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ public async Task<bool> AddRxLineAsync(string rxLine)
134134
long utcTicks = satTime.ToUniversalTime().UtcTicks;
135135
int quality = Convert.ToInt32(words[4].TrimEnd('%'), CultureInfo.InvariantCulture);
136136
int satNo;
137-
Debug.WriteLine("{0} {1}", words[0], satTime);
137+
//Debug.WriteLine("{0} {1}", words[0], satTime);
138138

139139
if (words[0] == "IRA:")
140140
{
141-
//Debug.WriteLine("{0} {1} {2}", words[0], satTime, utcTicks);
141+
Debug.WriteLine("{0} {1} {2}", words[0], satTime, utcTicks);
142142

143143
Ira ira = new Ira
144144
{

IridiumLive/wwwroot/css/site.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ app {
141141
color: fuchsia;
142142
}
143143

144+
.route-corridor {
145+
stroke: #000000;
146+
stroke-opacity: 0.1;
147+
}
148+
144149
@media (max-width: 767.98px) {
145150
.main .top-row:not(.auth) {
146151
display: none;

0 commit comments

Comments
 (0)