I need to read a layer-wide attribute, from a GeoJSON file, set by a custom member to the object:

{"type": "FeatureCollection", "features": [...], "search_polygon": "POLYGON (...)"}

Since it seems neither the Vector Layer nor the Layer classes have any attribute or method to expose this data, I tried to use the callback from HTTP Protocol with no success. (I put an alert to the callback function, but no response.)

My question is: Is there any way to access that search_polygon custom member using OpenLayers 2?

1 Answer 1


If you use custom objects and properties in your GeoJSON, they are ignored when the object is read using GeoJSON format.

You can clearly see this on line 115 of the GeoJSON.js source code.

Since the properties are never read in the first place, it is not possible to get them in OpenLayers.

There are multiple workarounds to get what you want. You could use one of the following, depending on your needs.

  1. Have the GeoJSON directly in your JavaScript code, and then access it for both your Vector layer, as well as to access the custom code.

  2. Call the GeoJSON with an Ajax request; once you get it, proceed as in option 1.

  3. Call the GeoJSON for the vector layer, and when you need to access the custom object, make an AJAX request for it. Since it will be cached in your browser's cache, it should load quickly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.