Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

Here 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 and the concrete code for the control at

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()) {

            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) {


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

Your Answer


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.