Interaction with GeoJSONView

Hi!

I’m trying to create an interactive map for a GeoJSONView, and according to the docs I have to give an identifier to each geometric object, e.g. point_1 = MapPoint(..., identifier="point1")

However, this doesn’t seem to be working for GeoJSONView. Some context: I create a GeoDataFrame with several columns (including “stroke” and “type” etc., all properties which are used for plotting). Then I convert this to a GeoJSON and return it as GeoJSONResult. I tried adding “identifier” as a column, like I did with other properties, but this doesn’t seem to work. Should I do it differently?

Hi Martijn,

Thank you for your question. As you noticed, it is not documented how to use map select interaction for a GeoJSONResult. We will fix this. The identifier can be added to the raw json with “id” on the same level as “type” within a feature:

{
  "type": "FeatureCollection",
  "features": [{
      "type": "Feature",
      "properties": ...,
      "geometry": ...
      "id": "my identifier",
      ...

I have no experience with geopandas.GeoDataFrame, but I can imagine that it is possible to add such a keyword by adding a column?

Hi Bas,

Adding a column called “id” (instead of “identifier”) to the GeoDataFrame was the solution! Thanks for your help.

Hi Bas, I tried creating the “id” field but while interaction it doesn’t provide the field I copied but some number. Could you please let me know if I am missing something.

 _gdf['id'] = _gdf['NODE'].copy()
 _geojson = json.loads(_gdf.to_json())

Update: Resolved this. I learnt that ‘id’ has to be defined under features (feature[‘id’] = " ") and not in geo-dataframe.

1 Like