GeoJSON: Are FeatureCollection properties allowed?

I could not find any relevant information in the specification: http://geojson.org/geojson-spec.html

Is it allowed to have a properties key in FeatureCollection ? Or is this only possible for functions?

If possible, how can I access properties inside openlayers ? Thanks in advance.

+4
source share
2 answers

The specification does not explicitly forbid this, but function collections have no properties. The GeoJSON specification only mentions the following keys for FeatureCollection:

  • type - must be `FeatureCollection
  • features - feaures array
  • bbox - the bounding box of the entire collection of functions

As I can see from the OpenLayers code, properties processed only for instances of objects, and not for a collection of functions.

+6
source

Switching to Leaflet is easier, and it accepts GeoJSON with FeatureCollection. You can also get attributes from a popup when you click objects.

However, Openlayers also have access to FeatureCollection. The mobile (jQuery Mobile) example for Openlayers demonstrated access to properties.

http://openlayers.org/dev/examples/mobile-jq.html#mappage

Click on the black icons and you will see a pop-up window with these attributes.

This is part of GeoJSON in the mobile example.

 { "type": "FeatureCollection", "features": [ { "type": "Feature", "geometry": {"type": "Point","coordinates": [1332700, 7906300]}, "properties": {"Name": "Igor Tihonov","Country":"Sweden", "City":"Gothenburg"} }, { "type": "Feature", "geometry": {"type": "Point","coordinates": [790300, 6573900]}, "properties": {"Name": "Marc Jansen","Country":"Germany", "City":"Bonn"} }, { "type": "Feature", "geometry": {"type": "Point","coordinates": [568600, 6817300]}, "properties": {"Name": "Bart van den Eijnden","Country":"Netherlands", "City":"Utrecht"} }, { "type": "Feature", "geometry": {"type": "Point","coordinates": [-7909900, 5215100]} } ] } 
+2
source

Source: https://habr.com/ru/post/1390434/


All Articles