1

What type is the argument of a function "buildGeometry" of JavaScript library JSTS? How to use JSTS function "buildGeometry" with OpenLayers 3 selection, which is created is this way:

window.select = new ol.interaction.Select({
    layers: window.layers, //an array of OpenLayers layers
    wrapX: false
});

According to documentation, the class 'ol.interaction.Select' has a method 'getFeatures', which returns 'ol.Collection.<ol.Feature>' object? A code:

var features = window.select.getFeatures();
var geometryFactory = new jsts.geom.GeometryFactory();
var group = geometryFactory.buildGeometry(features);

causes an error:

Uncaught TypeError: t.iterator is not a function
    buildGeometry (...)/js/openlayers3/jsts.js:9

How to use JSTS function "buildGeometry" with 'ol.interaction.Select' and 'ol.Collection.<ol.Feature>' objects? How to create a group with various elements which are selected with OpenLayers 3?

1
  • 1
    I presume you would need to parse the feature geometry into JSTS format with jsts.io.OL3Parser as in openlayers.org/en/v3.20.1/examples/jsts.html e.g. var geometries = select.getFeatures().getArray().map(function(feature) { return parser.read(feature.getGeometry()); }); Note that in more recent versions of JSTS you must inject the OpenLayers format constructors into the parser.
    – Mike
    Commented May 19, 2023 at 18:36

0

Your Answer

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

Browse other questions tagged or ask your own question.