ThinkGeo.com    |     Documentation    |     Premium Support

Track Overlay Question

Is it possible to add a track overlay to a particular feature layer?


I need to track a point when the mouse moves over a layer such as a road layer.


 



Madduri,


I am still not very clear with your requirement. But I did a similar post and demo before, hope it helps.
 
gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/5913/afv/topic/afpgj/1/Default.aspx#9297
 
If you still have questions or this do not satisfy your requirement, just let me know.
 
Thanks.
 
Yale

Sorry about not being clear on my initial question.  what I want to accomplish is similar to the TrackandEditShapes example.  
  
 winformsMap1.TrackOverlay.TrackMode = TrackMode.Point 
  
 I need to track a point on mouse move but want to restirct the point to a feature layer. Eg. In the sample, the point can be moved all over the map. I would like to not be able to move the point beyond the world map border. i.e The user should not be able to drag the point over the water bodies (oceans). The point should dissappear when the user moves the mouse cursor out of the land area and reappear when the mouse cursor moves back in.

Madduri,


Thanks for your post and explanations!
 
I think you can achieve your attempt by using the event TrackEnding event provided in TrackOverlay.
 
First hook up the event:
 

winformsMap1.TrackOverlay.TrackEnding += new EventHandler<TrackEndingTrackInteractiveOverlayEventArgs>(TrackOverlay_TrackEnding);

 

In the event implementation, use your own logic to set it to false when you DONOT want to see it.

 



void TrackOverlay_TrackEnding(object sender, TrackEndingTrackInteractiveOverlayEventArgs e)
{
    PointShape pointShape = (PointShape)e.Shape;

    //This is your own logic.
    if (usBoudningBox.Contains(pointShape))
    {
        e.Cancel = false;
    }
    else
    {
        e.Cancel = true;
    }
 }

In my given example above, the tracked point only will be shown inside the US bounding box which is the bounding box of USStates.shp. You can try to change the logic here as you want.


 
Any more questions just let me know.
 
Thanks.
 
Yale

 

Thanks Yale,


Using your example I was able to get it working for a Road layer. However it is rather slow. Is there a better way. Please see my code below.

 




 



Sub TrackOverlay_TrackEnding(ByVal sender As System.Object, ByVal e As TrackEndingTrackInteractiveOverlayEventArgs)Dim PointShape As PointShapeDim RoadDOTLayer As FeatureLayer = WinformsMap1.FindFeatureLayer("ROAD_DOT")Dim selectedFeaturesRoadDOTLayer As Collection(Of Feature) = RoadDOTLayer.QueryTools.GetFeaturesWithinDistanceOf(PointShape, GeographyUnit.Meter, GeographyUnit.Meter, 1, New String(0) {"STREET_NAM"})If selectedFeaturesRoadDOTLayer.Count > 0 Then

e.Cancel =


False

 


Else

e.Cancel =


True

 


End If

 


End Sub

 


 



 


PointShape = e.Shape


 


 


 


 



Madduri,


Thanks for your post!
 
I think the main reason for the low performance is the GetFeaturesWithinDistanceOf API executed in the TrackOverlay_TrackEnding event.
 
How many records in your “ROAD_DOT” data? Can you test this API separately to see its performance?
 
Besides, I think you do not need the “STREET_NAM” in this query because it will not be used.
 
Any more questions will be welcome.
 
Thanks.
 
Yale

Thanks Yale, 
  
 I used the GetFeaturesWithinDistanceOf API to allow the point to track only on the road line and not throughout the bounding box of the entire roadway network. Please let me know if there is another API to acheive this. The ROAD_DOT data has 39873 feature rows.  The STREET_NAM column will eventually be displayed below the tracking point. 
  
 I will try to test the API seperately. 
  
 Thank you 
 Madduri

Madduri,


Thanks for your post!
 
How‘s your test separately on GetFeaturesWithinDistanceOf API?
 
I think it would be faster if you using the GetFeaturesInsideBoundingBox API for its usage of Rtree index.

Dim tolerance As Double = 0.0001
Dim searchingBoundingBox As RectangleShape = New RectangleShape(e.WorldX - tolerance, e.WorldY + tolerance, e.WorldX + tolerance, e.WorldY - tolerance)

worldLayer.Open()
Dim selectedFeatures As Collection(Of Feature) = worldLayer.QueryTools.GetFeaturesInsideBoundingBox(searchingBoundingBox, New String(0) {"FENAME"})
worldLayer.Close()

Let me know if more questions.


Thanks.
 
Yale

Thanks Yale, 
  
 I havent yet been able to setup the independant test of the GetFeaturesWithinDistanceOf API. I have been exploring the GetFeaturesInsideBoundingBox API which seems to work better.  
  
 I am running into a problem with setting up the rectangle shape for the bounding box which is sometimes throwing a NullReferenceException. 
  
 Thank you 
 madduri

Madduri,


Thanks for your post!
 
I am very curious why you will have the NullReferenceexception happened when you setup the searchingBoundingBox.
 
Can you have an initial debug to see what is the status of e which is the TrackOverlay_TrackEnding event args?
 
 
Any more questions just let me know.
 
Thanks.
 
Yale