0

I'm trying to check features inside a polygon:

function howinpol(evt) {
    var polygon_extent = evt.feature.getGeometry().getExtent(); // get polygone extent
    var starr_uli = "", arr_fdgdg = [];

    mySource8.forEachFeatureIntersectingExtent(polygon_extent, function(feature) {
        xl = parseFloat(feature.get('lon')); // get lon
        yl = parseFloat(feature.get('lat')); // get lat
        feature.setProperties({ visible: 'visible' });  // add prop
        feature.setProperties({ inpol: 'in' }); // add prop
        arr_fdgdg.push(feature); // add features
        // list
        starr_uli += '<li><span id="'+ feature.getId() +'">' + feature.get('name_kontr') + '&nbsp;&nbsp; id:' + feature.getId() + '</span><small>'+ feature.get('billing_address_city') +', '+ feature.get('billing_address_street') +'</small></li>';
    });

    $('#objects ul').replaceWith('<ul>' + starr_uli + '</ul>'); //name list

    $('#cntobj').text(arr_fdgdg.length); //count in list

    mySource8.clear(); //clear 
    mySource8.addFeatures(arr_fdgdg); //add select features
}

but it is beyond the scope if draw a circle or freehand polygon: enter image description here

I tried to wrap if(evt.feature.getGeometry().intersectsCoordinate([xl, yl])):

function howinpol(evt) {
    var polygon_extent = evt.feature.getGeometry().getExtent(); // get polygone extent
    var starr_uli = "", arr_fdgdg = [];

    mySource8.forEachFeatureIntersectingExtent(polygon_extent, function(feature) {
        xl = parseFloat(feature.get('lon')); // get lon
        yl = parseFloat(feature.get('lat')); // get lat

        if(evt.feature.getGeometry().intersectsCoordinate([xl, yl])){
            feature.setProperties({ visible: 'visible' });  // add prop
            feature.setProperties({ inpol: 'in' }); // add prop
            arr_fdgdg.push(feature); // add features
            // list
            starr_uli += '<li><span id="'+ feature.getId() +'">' + feature.get('name_kontr') + '&nbsp;&nbsp; id:' + feature.getId() + '</span><small>'+ feature.get('billing_address_city') +', '+ feature.get('billing_address_street') +'</small></li>';
        }
    });

    $('#objects ul').replaceWith('<ul>' + starr_uli + '</ul>'); //name list

    $('#cntobj').text(arr_fdgdg.length); //count in list

    mySource8.clear(); //clear 
    mySource8.addFeatures(arr_fdgdg); //add select features
}

It worked, but it loops through a very long time.

have any thoughts?

1

I solved the problem myself:

    function howinpol(evt) {
       var polygon_extent = evt.feature.getGeometry().getExtent(); // get polygone extent
       var starr_uli = "", arr_fdgdg = [], mass = [];

       mySource8.forEachFeatureIntersectingExtent(polygon_extent, function(feature) {
          xl = parseFloat(feature.get('lon')); // get lon
          yl = parseFloat(feature.get('lat')); // get lat

          uli_p = '<li><span id="'+ feature.getId() +'">' + feature.get('name_kontr') + '&nbsp;&nbsp; id:' + feature.getId() + '</span><small>'+ feature.get('billing_address_city') +', '+ feature.get('billing_address_street') +'</small></li>'; 
          mass.push({id: feature.getId(), feature: feature, uli_p: uli_p, xl: xl, yl: yl});

       });

       for(var i = 0; i < mass.length; i++){
          if(evt.feature.getGeometry().intersectsCoordinate([mass[i].xl, mass[i].yl])){
             var selfeatu = mass[i].feature;
             arr_fdgdg.push(selfeatu);
             starr_uli += uli_p;
          }
       }

       $('#objects ul').replaceWith('<ul>' + starr_uli + '</ul>'); //name list

       $('#cntobj').text(arr_fdgdg.length); //count in list

       mySource8.clear(); //clear 
       mySource8.addFeatures(arr_fdgdg); //add select features
   }

I have added an array when forEchFeatureIntersektingEstent and then sort out, not all the features, but only those that received.

It works much faster.

p/s: I'm sorry for Google translator

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.