0

Using OpenLayers, I am loading a large geojason file of about 4000 polygons.

Once the polygons are loaded I want to draw a "LineString" on the map (already done and working).

My challenge is that I want to change the color of the polygons that intersects with the drawn line.

My research did not return any information that would guide me for this feature.

Any suggestion is appreciated.

  • What if the lines are drawn and the only need is to select line, and automatically polygons are selected? – Stefan Mihajlovic Jan 12 '15 at 9:52
1

Here http://acanimal.github.io/Openlayers-Cookbook at Chapter08-Selecting features intersecting with a line you can find a sample of control that selects the features that intersects with a line.

The code is at https://github.com/acanimal/Openlayers-Cookbook and the concrete code for the control at https://github.com/acanimal/Openlayers-Cookbook/blob/master/recipes/ch08/selectFeaturePath.js#L49

The main task is to check, with the linestring method intersect, if the linestring intersects with any of features of the desired layer.

    for(var l=0; l<layers.length; ++l) {
        layer = layers[l];
        for(var i=0, len = layer.features.length; i<len; ++i) {
            var feature = layer.features[i];
            // Check if the feature is displayed
            if (!feature.getVisibility()) {
                continue;
            }

            if (this.geometryTypes == null || OpenLayers.Util.indexOf(
                this.geometryTypes, feature.geometry.CLASS_NAME) > -1) {
                if (**path.intersects(feature.geometry)**) {
                    if (OpenLayers.Util.indexOf(layer.selectedFeatures, feature) == -1) {
                        this.select(feature);
                    }
                }
            }
        }
    }

Cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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