Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

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.

share|improve this answer
    
Neil - Thank you :) –  user2449078 Jul 3 '13 at 23:20
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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