alexandrainst / alexandra-trackmap-panel

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

Do not see location on map #7

Closed sptrakesh closed 4 years ago

sptrakesh commented 4 years ago

This is most likely a question and not necessarily a bug. I followed the documentation for displaying NGSIv2 data, and through the query inspector and datasource logs I think I see the data being returned as it is supposed to be formatted. However I do not see any points on the map.

Related question is is there a way to automatically have the map centre itself based on range of points being displayed?

[{
    "columns": [{
        "text": "location",
        "type": "geo:json"
    }],
    "rows": [{
        "location": {
            "type": "geo:json",
            "value": {
                "type": "Point",
                "coordinates": [39.2866544, -76.5896193]
            }
        }
    }, {
        "location": {
            "type": "geo:json",
            "value": {
                "type": "Point",
                "coordinates": [39.286594, -76.5894559]
            }
        }
    }],
    "type": "table"
}]
Drazair commented 4 years ago

Hey Sptrakesh,

It looks like the rows are wrap with a "location" which it doesn't except. Could you send the query you used, so I can see if it's a problem with the plugin or the query?

And it's currently not possible to have the map center itself based on the points, but should be easy to implement, when I have the time.

sptrakesh commented 4 years ago

Hello,

The data is coming from an Akumuli event stream that is retrieved via a custom JSON datasource, so it will be hard for you to replicate.

When I did not see the data, I inspected the map query control implementation, and it looked like you expect a structure similar to what I have above as well.

https://github.com/alexandrainst/alexandra-trackmap-panel/blob/master/src/map_ctrl.js#L88

If I am reading it right, for each row in the rows array, you retrieve the location object, and within the location object you verify the type is geo:json and that it has a value property with an array of coordinates.

If you can share what a valid response should look like (maybe expand the README), I can validate against that. I will also try changing the output in the JSON datasource to be simple latitude longitude to see if that works better.

sptrakesh commented 4 years ago

Did a debug build by adding some console output, and now I know why the map shows nothing. Looks like the output is invalid (no errors shown) as far as what Grafana expects. See this screen capture where you can see the query inspector shows the data, but in the map control, during iteration it just sees an array of null values.

Any idea why Grafana hands over different results to the map control?

Drazair commented 4 years ago

Here is the structure that i'm getting from a CrateDB:

[{
  columns: [
    { text: "location" },
    { text: "time_index" }
  ],
  rows: [
    [ 
      "{\"type\":\"geo:json\",\"value\":{\"coordinates\":[56.18803,10.16773],\"type\":\"Point\"},\"metadata\":{\"timestamp\":{\"type\":\"DateTime\",\"value\":\"2019-12-19T06:35:59.390Z\"}}}",
      "2019-12-19T06:35:59Z" 
    ],
    [ 
      "{\"type\":\"geo:json\",\"value\":{\"coordinates\":[56.18803,10.16773],\"type\":\"Point\"},\"metadata\":{\"timestamp\":{\"type\":\"DateTime\",\"value\":\"2019-12-19T06:38:44.376Z\"}}}", 
      "2019-12-19T06:38:44Z" 
    ]
  ],
  type: "table"
}]

It doesn't have to be a json string, here is the string as a object:

{
  "type": "geo:json",
  "value": {
    "coordinates": [56.18803, 10.16773],
    "type": "Point"
  },
  "metadata": {
    "timestamp": {
      "type": "DateTime",
      "value": "2019-12-19T06:35:59.390Z"
    }
  }
}
Drazair commented 4 years ago

The metadata above is not needed for the plugin, it's just part of NSGIv2 data format

sptrakesh commented 4 years ago

Thanks for the samples, that is very helpful. Still not clear how the array without a wrapper location object works based on line 88 (on master branch) in the map control code. The bigger issue in my case seems to be a mismatch in the data I see in the query inspector vs the data that gets to the map control.

https://sptci.com/uploads/map-issue.png

Drazair commented 4 years ago

The location variable, that is used in line 88, is the index in the array that was found from the columns list.

Haven't had any problems with a mismatch between the query inspector and the map controls data. This seems more like a problem with the Grafana and your data source.

The response I get in the query inspector looks a lot different compared to yours: query-inspector

sptrakesh commented 4 years ago

Thanks for your help. Definitely looks like a datasource issue.