Esri / arcgis-maps-sdk-dotnet-toolkit

Toolkit for ArcGIS Maps SDK for .NET
https://esri.github.io/arcgis-maps-sdk-dotnet-toolkit/
Apache License 2.0
213 stars 121 forks source link

Add ViewPointController API for easy binding of viewpoints in XAML #138

Open dotMorten opened 7 years ago

dotMorten commented 7 years ago

Something along the lines of this to support MVVM and setting extents, while keeping your view model and view decoupled:

https://github.com/Esri/arcgis-runtime-demos-dotnet/blob/master/src/TurnByTurn/RoutingSample.Shared/CommandBinder.cs#L26

zwaap commented 6 years ago

We also have something very similar here:

https://github.com/Esri/maps-app-dotnet/blob/b3470775c9bc14a96c3c254da750a9e6966da9de/src/MapsApp.Shared/Binding%20Support/ViewpointController.cs#L35

and:

https://github.com/Esri/maps-app-dotnet/blob/272cac8923d1f743ac0fbeb084f74c725fe9cb6a/src/MapsApp.Shared/Binding%20Support/GeoViewExtensions.cs#L39

Which together allow hooking into multiple view-models to update the viewpoint on a given GeoView:

<esri:MapView Map="{Binding Map, Source={StaticResource MapViewModel}}" >
  <utils:GeoViewExtensions.ViewpointControllers>
    <utils:ViewpointControllerCollection>
      <utils:ViewpointController Viewpoint="{Binding AreaOfInterest, Source={StaticResource MapViewModel}}"/>
      <utils:ViewpointController Viewpoint="{Binding AreaOfInterest, Source={StaticResource GeocodeViewModel}}"/>
      <utils:ViewpointController Viewpoint="{Binding AreaOfInterest, Source={StaticResource RouteViewModel}}"/>
    </utils:ViewpointControllerCollection>
  </utils:GeoViewExtensions.ViewpointControllers>
</esri:MapView>

The nice thing here is that it allows for the area of interest updates to come from multiple sources.

Not to get too off-topic, but there seem to be lots of other cases where these sort of binding helpers are desirable as well. From the same app, here's a HoldingLocationController that allows listening to the GeoView's holding location from a view-model. Or we recently had a user ask about handling identify operations on GeoNet (here), and I was able to adapt and share IdentifyController class from an Example App that's currently under development. Seems like there's potential for a whole little area of Toolkit development here.