1

I am having some issues in OpenLayers 5.3.0. The context is that I'm using Sharepoint lists as a backend to save feature data and OpenLayers is running in a Vue.js container. Everything works as expected:

The geoJSON feature strings are pulled in from SharePoint and aggregated into a feature collection. As I load each feature I add custom properties - most importantly the ItemID from the SharePoint list. The features load on the map. I can draw new features and save all of them.

If at any point I get all features with code like

allFeatures = self.drawLayer.getSource().getFeatures();

the features will contain the additional properties I have added.

The problem I am having is that when use a select interaction the selected feature comes back differently if it is a point or if it is a polygon - using for example:

self.drawClickSelect.on('select', function(e) {
            self.selectedFeatures = e.selected;                   
            console.log(self.selectedFeatures);
          });

The feature comes back with the added properties if it is a polygon, but if it's a point the properties itemID and modified do not exist.

Examples Polygon returns:

e {…}
dispatching_: (...)
disposed_: (...)
geometryChangeKey_: (...)
geometryName_: (...)
id_: (...)
listeners_: (...)
ol_lm: (...)
ol_uid: (...)
pendingRemovals_: (...)
revision_: (...)
styleFunction_: (...)
style_: (...)
**values_: Object
geometry: e
itemID: 13
modified: false**

Point returns:

0: e
dispatching_: (...)
disposed_: (...)
geometryChangeKey_: (...)
geometryName_: (...)
id_: (...)
listeners_: (...)
ol_lm: (...)
ol_uid: (...)
pendingRemovals_: (...)
revision_: (...)
styleFunction_: (...)
style_: (...)
**values_: Object
geometry: (...)**

self.drawLayer.getSource().getFeatures() returns: (Note that the properties I'm interested are present for each feature.)

"{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-9148122.009657301,4148932.8076870437],[-9148001.336280514,4149124.4626323017],[-9148174.732892036,4149232.323163778],[-9148225.35521765,4149153.4073993675],[-9148302.20055545,4149200.6003566994],[-9148335.00415841,4149155.742857091],[-9148551.727115743,4149293.291205446],[-9148561.789387284,4149278.5208011325],[-9148673.828665541,4149349.3877884443],[-9148735.371373663,4149252.6485635266],[-9148560.38595463,4149144.0397318634],[-9148567.23964962,4149133.2237431305],[-9148549.761260215,4149122.8749220027],[-9148544.360359373,4149132.5307491873],[-9148449.959080853,4149071.7602422866],[-9148456.755445173,4149061.5738832294],[-9148442.091697177,4149052.313675927],[-9148435.004098615,4149063.0075244764],[-9148340.775473515,4149000.2413342204],[-9148324.546920547,4149028.1325729615],[-9148199.787204698,4148944.980097804],[-9148184.701774493,4148972.1811943417],[-9148122.009657301,4148932.8076870437]]]},"properties":{"itemID":12,"modified":false}},{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-9149230.727863472,4149974.6889362033],[-9148917.825374642,4149776.7721247915],[-9149008.484043097,4149633.442597651],[-9149321.386531925,4149831.359409064],[-9149230.727863472,4149974.6889362033]]]},"properties":{"itemID":13,"modified":false}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-9149507.058888558,4150498.531335066]},"properties":{"itemID":21,"modified":false}},{"type":"Feature","geometry":{"type":"Point","coordinates":[-9149383.916618763,4150420.6414931556]},"properties":{"itemID":22,"modified":false}}]}"

Is there some known issue with points that would make them different than polygons with regard to properties?

4
  • Thank you for the formatting and cleanup TomazicM. I was a little slow on the uptake there.
    – m.t.Dutch
    Oct 1, 2019 at 15:00
  • The properties object of the geojson is included in the value_ field but should be accessed using .getProperties() (methods not documented in the API are usually not available when using minified builds) What do you get when logging self.selectedFeatures[0].getProperties()
    – Mike
    Oct 1, 2019 at 15:16
  • That returns the geometry only. I did find a workaround, but I'm curious as to why this would work. self.selectedFeatures = self.map.forEachFeatureAtPixel(e.mapBrowserEvent.pixel, function(feature) { return feature; }); returns exactly what I'm after.
    – m.t.Dutch
    Oct 1, 2019 at 16:57
  • It seems sometimes like the object OL returns on select is a kind of copy of the original feature. And features seem to have different properties after they're added to a map than they do before. It's a bit confusing at times.
    – m.t.Dutch
    Oct 1, 2019 at 17:02

1 Answer 1

0

For anyone facing this problem in the future I got to the bottom of it. The problem was that I was adding multiple interactions at the same time - i.e. Modify, Translate, and Select. I saw this issue only selecting points and lineStrings while all the interactions were active. If I only use the interactions one at a time (although Translate and Select seem to work ok together) I get back exactly what I expect. If it's documented somewhere that you shouldn't combine interactions I missed it.

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.