0

I am using

ol.extent.intersects(extent1, extent2) 

to check for intersection between layers and polygon I drew, but it doesn't get me any intersection which is weird because I draw the polygon creating intersection with the layer

can you think of any reason of this please ?

  • Could you post more of your code ? That'd help finding the issue. – Alexis_A Jun 3 '16 at 19:55
1

The reason was that the projection of the vector and the projection of the polygons drawn are different. To check for intersection, the projection for the vector and the polygons should be the same.

0

ol.extent.intersects accepts 2 arguments, both of them should be of type ol.extent api doc here So to make it clear ol.extent.intersects is determining whether the supplied extents (not polygons, not layers) are having any kind of spatial intersection.

  • Yes I'm using both arguments are extents : Extent of the layer and Extent of the polygon , but Still no intersection found – R-OLayers Jun 4 '16 at 20:09
  • Would you like to provide some piece of your code and the extents you use? – pavlos Jun 4 '16 at 21:00
0

yes, here is my code I have a list of extents listExtent that stores the extents of polygons drawn and I query the list of layers extent from the database to check intersection between the two :

 listExtent.forEach(function(item, index, array){                          
                     //loo[ to get layers extent below
                      <apex:repeat value="{! allListLayers}" var="layer">
                             var layerExtent = [];
                             var extentListstatic = [];
                            if('{!layer.Layer_Extent__c}' !== ''){                                     

                                    layerExtent = '{!layer.Layer_Extent__c}'.split(',');
                                    for(var i=0; i<layerExtent.length;i++){
                                        extentListstatic.push(parseFloat(layerExtent[i]));
                                    }
                                    //check for intersection below                                   
                                    var intersection = ol.extent.intersects(extentListstatic, item);

          }

If the polygons drawn are wide and large then the intersects method returns true (so there is intersection), else it returns always false, and I don't know why, this is the code for the map :

//Draw the map       
        var raster = new ol.layer.Tile({
          source: new ol.source.MapQuest({layer: 'osm'})
        });

        var source = new ol.source.Vector({wrapX: false});

        var vector_layer = new ol.layer.Vector({
          name: 'my_vectorlayer',
          source: new ol.source.Vector(),
          style: new ol.style.Style({
            fill: new ol.style.Fill({
              color: 'rgba(255, 255, 255, 0.2)'
            }),
            stroke: new ol.style.Stroke({
              color: 'blue',
              width: 2
            }),
            image: new ol.style.Circle({
              radius: 7,
              fill: new ol.style.Fill({
              color: '#ffcc33'
              })
            })
          })
        });
var map = new ol.Map({
            target: 'map',
            layers: [raster, vector_layer],            
            view: new ol.View({
                center: ol.proj.transform([51.56775, -0.1336], 'EPSG:900913', 'EPSG:4326'),
                zoom: 2
            })            
        });

and the code below shows how to store the list of extents of the polygons drawn :

 function addInteraction() {
              var value = polyValue.value;
              if (value !== 'None') {
                    draw = new ol.interaction.Draw({
                      source: vector_layer.getSource(),                     
                      type: /** @type {ol.geom.GeometryType} */ (value)
                    });
                    map.addInteraction(draw);

                    draw.on('drawend', function(e2) {
                        //var poly1 = geojsonFormat.writeFeatureObject(e2.feature);
                      listExtent.push(e2.feature.getGeometry().getExtent());                                                    
                    });   
              }          
          }        

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.