GraphicsOverlay - Graphic not always appearing

3674
10
Jump to solution
01-18-2016 06:49 AM
JimFiddes
Occasional Contributor

Good morning Everyone

I'm in the process of writing a mapping application for an in fire truck solution. The jobs of the map is to show their current incident, gps location, route and other active incidents as they click on the list. What I currently have working is the gps location (manually placed at the moment) and current incident showing up and even a route being displayed within my GraphicsOverlay. What I can't seem to get working properly is the active incident location showing up (all the time). I have tried many ways to make 3 different icons appear within the graphics overlay however I can't seem to figure out what is going wrong. Attached is sample code depicting the creation and rendering of the graphics overlay and the addition and removal of graphics. I'm stumped as to why symbols don't appear and remove all the time.

Thanks,

Jim

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JimFiddes
Occasional Contributor

Hey Antti

I resolved the issue! 10.2.5 seems to have an issue with displaying graphics (add, removing...). I tested my code from Friday on another development machine running just 10.2.5 .Net Runtime and the code didn't work as expected. My main development machine has 10.2.6 installed but my project was referencing a copy of the 10.2.5 and it didn't work. When I changed both machines to 10.2.6 and ran code as it was on Friday, it worked without issue.

Thanks for the different ideas on how to handle things but the culprit appears to be 10.2.5.

Cheers,

Jim

View solution in original post

0 Kudos
10 Replies
JimFiddes
Occasional Contributor

Further testing also makes me feel like the overlay layer needs a refreshing or something? I can see the correct amount of graphics in the count; however they aren't always visible.

0 Kudos
AnttiKajanus1
Occasional Contributor III

Hi Jim,

I had a fast overview on the attached file. Couple tips in general. Try to avoid un-necessary projecting but if you need to do that, try to use SpatialReferences.WGS/WebMer factories or SpatialReference.Create() method. You can just update the existing graphics location (geometry) instead of removing previous and creating a new one.  I think you can simplify updating the location quite a bit. Also consider using PictureMarkerSymbol.SetSourceAsync method for setting the source picture for the PMS's.

What comes to get the graphics visible, make sure that you have the values set correctly to the UniqueValueRenderer and the graphic. If the _activeIncLocationID is always the same, it should use the correct image. Do you see the new graphic but using wrong symbol?

0 Kudos
JimFiddes
Occasional Contributor

Further testing I've been doing this morning:

1. I stopped the removal of graphics to see if there is an issue with the collection. Graphics still don't appear but are in the count.

2. If I add an active incident, it will not appear but if I click on my current incident, this snippet gets called:

- MdsMapView.SetView(_incidentLocation as Esri.ArcGISRuntime.Geometry.MapPoint,10000);

..and after the map focus' to that location, the next time I click on a different active incident, the icon will appear and if I had tried to display other active incidents (prior to focusing on current incident), the others will now appear on the map. It almost seems like a refresh is not happening.

Current Incident  - This is the location we are dispatched to

Active Incident - Other 911 calls that are going on and the user can quickly see where they are (really an on and off setup) and will be removed once they close the list.

0 Kudos
JimFiddes
Occasional Contributor

Below is a picture showing the renderer is working; however it is with a combination of setviews and graphic adding will things magically appear. No removing of graphics is being called at this moment.

RedPin - Current Incident

BluePin - GPS location

GreenPin - Active Incidents

WorkingandNotWorking.JPG

0 Kudos
AnttiKajanus1
Occasional Contributor III

Here is a simple app that shows one way how to play around with the moving graphic while using UniqueValueRenderer. Let me know if this helps.

I have a timer that is moving one of the 3 graphics every second. Similar fashion you should be able to add/remove items from the collection if needed. If this doesn't help, I'll try to make a bit more comprehensive sample.

0 Kudos
AnttiKajanus1
Occasional Contributor III

Just a continuation to the moving / adding / removing graphics, you can do it something like this

   var removepoints = _overlay.Graphics.Where(x => Convert.ToInt32(x.Attributes["SymbolID"]) == 3).ToList();

   foreach (var removepoint in removepoints)

   {

             _overlay.Graphics.Remove(removepoint);

   }

  

   Random rnd = new Random(DateTime.Now.Millisecond);

   for (int i = 0; i < 10; i++)

   {

      var randomX = rnd.Next(Convert.ToInt32(MyMapView.Extent.XMin), Convert.ToInt32(MyMapView.Extent.XMax));

      var randomY = rnd.Next(Convert.ToInt32(MyMapView.Extent.YMin), Convert.ToInt32(MyMapView.Extent.YMax));

      var randomMapPoint = new MapPoint(randomX, randomY, SpatialReferences.WebMercator);

      var graphic = new Graphic(randomMapPoint);

      graphic.Attributes.Add("SymbolID", _activeIncLocationID);

          _overlay.Graphics.Add(graphic);

   }

Ofc remember to protect against timing issues etc but the principle is the same.

EDIT: edited to contain the code

0 Kudos
JimFiddes
Occasional Contributor

Thanks Antti for all the quick replies! I'm still uncertain on why the map isn't getting word that the collection of graphics is changing; however, I'm going to make some code alteration so I can move forward. I will keep 3 private Graphic objects around and just manipulate them and not worrying about removing or adding them. I'll zero out their geometries when I don't need them or make the graphic invisible. It would be nice to just add or remove graphics as needed but in the short term I will try a more simplified approach.

0 Kudos
AnttiKajanus1
Occasional Contributor III

If you have a reproducer that I can run and see how it really works, I can give a look for it if I can figure it out. It can be related to timing things, your workflow, maybe the collection is not modified in the correct thread or just a simple mistake that both of us are missing here.

Let me know if you need any more help with this one.

0 Kudos
JimFiddes
Occasional Contributor

Hey Antti

I resolved the issue! 10.2.5 seems to have an issue with displaying graphics (add, removing...). I tested my code from Friday on another development machine running just 10.2.5 .Net Runtime and the code didn't work as expected. My main development machine has 10.2.6 installed but my project was referencing a copy of the 10.2.5 and it didn't work. When I changed both machines to 10.2.6 and ran code as it was on Friday, it worked without issue.

Thanks for the different ideas on how to handle things but the culprit appears to be 10.2.5.

Cheers,

Jim

0 Kudos