1

my question is as follows.

What I have

  • I have a GeoJSON feature collection with Polygons and custom properties
  • GeoJSON is loaded into the Here maps

What I want

  • I want to detect a polygon click and read the custom property value

Example GeoJSON

{
    "type": "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": {
            "customProp": "heyImACustomProperty"
        },
        "geometry": {
            "type": "Polygon",
            "coordinates": [
                [
                    [
                        16.45477294921875,
                        43.51619059561274
                    ],
                    [
                        16.450481414794922,
                        43.50772499687011
                    ],
                    [
                        16.470909118652344,
                        43.5019975949657
                    ],
                    [
                        16.481552124023438,
                        43.51021500212034
                    ],
                    [
                        16.475543975830078,
                        43.518306809754804
                    ],
                    [
                        16.45477294921875,
                        43.51619059561274
                    ]
                ]
            ]
        }
    }]
}

Docs on GeoJSON manipulation are not the greatest.

Thanks in advance.

Danijel
  • 1,145
  • 8
  • 15

1 Answers1

2

Here is the example code to get the property value of the GeoJSON Polygon on click.

reader = new H.data.geojson.Reader('/path/to/geojson/file.json');
  reader.parse();
  map.addLayer(reader.getLayer());

  reader.getLayer().getProvider().addEventListener("tap", function(e) {
    if(e.target instanceof H.map.Polygon) {
      console.log('Custom property value: ', e.target.getData().properties.customProp);
    }
  }); 

GeoJSON documentation can be found here: https://developer.here.com/documentation/maps/topics_api/h-data-geojson-reader.html

  • Thank you! I have solved it by making a custom parser that transforms geojson to HERE maps "normal" polygon format. Will take a look if this is a "better" solution than mine. – Danijel Mar 22 '19 at 18:47