SetView/SetViewAsync not respecting MaximumExtent

876
4
Jump to solution
11-29-2017 02:06 AM
BjørnarSundsbø1
Occasional Contributor II

In 10.2.7, I'm having a problem when setting the view to a point outside the maximum extent of the map. My map covers {Envelope[XMin=-2500000, YMin=3500000.00000629, XMax=3045983.99999371, YMax=9045984, Wkid=25833]}. SetViewAsync where I set center to TargetGeometry = {MapPoint[X=63, Y=10, Wkid=4326]} (which is outside the maximum extent of the map), my map goes to a blank area. I can still zoom and pan, but I am never able to SetView to a point within my map later or zoom/pan to a location within the map without restarting the application. 

I have tried calculating the MaximumExtent for the map on LayerLoaded event, but this only restrict where the user can zoom or pan, but does not affect the SetView methods. WrapAround is False.

Is there a better way to prevent this issue than checking against Maximum extent in all locations where I do a SetView call?

Adding a world map layer to my map, this issue no longer occurs, but we can't rely on the user having a world map available as a workaround for this issue.

0 Kudos
1 Solution

Accepted Solutions
BjørnarSundsbø1
Occasional Contributor II

Not sure when this was fixed, but the error doesn't occur in 100.4. Probably resolved earlier.

View solution in original post

0 Kudos
4 Replies
BjørnarSundsbø1
Occasional Contributor II

Any suggestions?

0 Kudos
JenniferNery
Esri Regular Contributor

You can use NavigationCompleted event and GeometryEngine to check if the current extent is still within MaximumExtent.

Something like this? Any of the SetView calls will raise NavigationCompleted and you can do checks then.

Envelope lastExtent = null;
MyMapView.NavigationCompleted += (s, e) =>
  {
      if (MyMapView.MaximumExtent == null || GeometryEngine.Within(MyMapView.Extent, MyMapView.MaximumExtent) || (lastExtent?.IsEqual(MyMapView.Extent) ?? false))
          return;
      lastExtent = MyMapView.Extent;
      MyMapView.SetViewAsync(new Viewpoint(GeometryEngine.Intersection(MyMapView.Extent, MyMapView.MaximumExtent)));
  };
0 Kudos
BjørnarSundsbø1
Occasional Contributor II

I ended up doing a GeometryEngine.Project(viewpoint..TargetGeometry, MapView.SpatialReference). If the result s an empty geometry, I abort the operation.

I Never really understood the difference between NavigationCompleted vs ExtentChanged event. Documentation is not very precise.

0 Kudos
BjørnarSundsbø1
Occasional Contributor II

Not sure when this was fixed, but the error doesn't occur in 100.4. Probably resolved earlier.

0 Kudos