E
E
edmoiseenkoff2013-12-26 17:50:09
JavaScript
edmoiseenkoff, 2013-12-26 17:50:09

How to solve the problem with checking whether the marker hits the polygon?

Good day.
There is such code:
jsbin.com/isESifA/4/edit
There is a polygon, when you click on it, editing of this polygon is enabled. You can change its vertices, add and remove. And there are two more markers that are outside this polygon.
If, when editing this polygon, one of the markers falls within the boundaries of the polygon, then the marker should change color from red to green.
If the marker does not lie within the polygon, and add a new point so that the marker falls into the polygon, then everything works fine, and the marker changes color.
If you do not add a new point, but drag the existing one so that the marker is in the polygon, then the marker does not change color, but changes color after the next movement (as if it is one step behind).
How can I solve this problem so that there is no such lag in one step, and the marker changes color.
Thanks a lot!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dima_horror, 2013-12-27
@edmoiseenkoff

Another half an hour and I found the answer. JSBIN

polygon.editor.geometry.events.add('pixelgeometrychange', function(e1){
    var objectsInsidePolygon = geoQuery.searchInside(e1.originalEvent.target);
    objectsInsidePolygon.setOptions('preset', 'islands#greenDotIcon');
    // Оставшиеся объекты - красными.
    geoQuery.remove(objectsInsidePolygon).setOptions('preset', 'islands#redDotIcon');
  });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question