0

I am trying to show a selected feature information in a popup using ShowCalloutAt API function on mousemove event. using below code:

public class TestMouseMove
{

  public TestMouseMove(MapView mapView)
  {
    mapView.MouseMove+=MouseMove_Event;
  }
  private void MouseMove_Event(object sender, MouseEventArgs e)
  {

    var screenPoint = new MapPoint (e.Location.X, e.Location.Y, 
    EsriMapView.SpatialReference);
    var mapPoint = (MapPoint)GeometryEngine.Project (screenPoint, SpatialReferences.Wgs84);

    Feature selectedFeature=null;
    //I have written logic to Filter and take the single feature of top layer under mouse pointer
    selectedFeature=GetFeatureUnderMousePointer();

    //Now I am calling callout at the selected point using below code           
    CalloutDefinition myCalloutDefinition = new CalloutDefinition("Testing message");
    // Display the callout
    MyMapView.ShowCalloutAt(mapPoint , myCalloutDefinition);
 }
 private GetFeatureUnderMousePointer()
 {
  //Logic to filter and ge feature under mouse pointer
 }
}

But, if I move my mouse pointer within polygon feature, the ShowCAllout popup up is appears many time on mousemove. As a result the popup appears like it blinks. So, is there is any better way to implement with something like on mousemovestop event?.

Or any suggestion on solving this problem is appreciated.

Thanks in advance.

Parashuram
  • 303
  • 2
  • 6
  • 19

1 Answers1

1

First you must be VERY careful with doing this on each mouse-move event. Performing a hittest on every mouse move is going to hit the CPU very hard, and you might not be able to keep up with the very frequent mouse-moves. I'd recommend you don't perform a hittest if one is already in process, and once that is completed, you perform whichever latest mousemove event occured (since the intermediate ones no longer are important). You should also try and avoid performing identify if MapView.IsNavigating is true (no need to perform identify while you're moving the map around). In general we really recommend only performing these on click, rather than mouse move (depending on the service these can be rather slow/long-running operations).

Now to your specific question if you really want to do this on mouse-move, I'd suggest you only show a new callout if the returned feature is a different feature (use the object id to identify if it's the same one or not). So you'd only show it the first time the feature comes back, and you'd close the callout if no feature came back.

dotMorten
  • 1,953
  • 1
  • 14
  • 10