Danijel
Danijel

Reputation: 1185

HereMaps GeoJSON Polygon click read properties

my question is as follows.

What I have

What I want

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.

Upvotes: 1

Views: 981

Answers (1)

user3505695
user3505695

Reputation:

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

Upvotes: 2

Related Questions