alexandrainst / alexandra-trackmap-panel

Grafana map plugin to visualise coordinates as markers, hexbin, ant path, or heatmap.
MIT License
78 stars 26 forks source link

Map not updating correctly when starting with null/0 (lat/lon) values in time range #67

Closed Bart-1992 closed 1 year ago

Bart-1992 commented 3 years ago

When starting/opening grafana with a timerange that does not contain latitude/longitude data ( eg null or 0 --> setting : Discard positions that contains null (avoid plugin crash) or exactly 0 (inconsistent) coordinates to ON ) the map/panel gives an error --> "Invalid LatLng object: (NaN, NaN)"

When correcting the timerange to a point that does contain lat/lon data the map is not updated/refreshed. This can only be solved by completely refreshing the webpage --> Pressing F5.

Is there a way to solve this?

It would also be nice that if there is no lat/lon data in the specific range the map is still visible instead of disapearing and only showing the "Invalid LatLng object: (NaN, NaN)" error. I would prefer if it shows an error like "NO GPS DATA".

Thanks,

CharlesEdouardCady commented 2 years ago

I had the same problem. First I tried to patch the code (from commit a7217bc):

diff --git a/src/TrackMapPanel.tsx b/src/TrackMapPanel.tsx
index 3c410d7..375a591 100644
--- a/src/TrackMapPanel.tsx
+++ b/src/TrackMapPanel.tsx
@@ -37,10 +37,9 @@ export const TrackMapPanel = ({ options, data, width, height }: PanelProps<Track

   useEffect(() => {
     if (mapRef.current !== null) {
-      if (options.map.zoomToDataBounds) {
+      if (positions && positions.length !== undefined && options.map.zoomToDataBounds && positions.length > 1) {
         const bounds = getBoundsFromPositions(positions);
         mapRef.current.leafletElement.fitBounds(bounds, { animate: false });
-      }
       const bounds = mapRef.current.leafletElement.getBounds();
       updateMap(bounds);
     }

But then I realized that the auto-update would no longer work. So in fact, my fix is equivalent to disabling the Zoom map to fit data bounds option in the plugin's settings ("zoomToDataBounds": false in the JSON).