Component and Service Interactions
Components and services have multiple ways of interacting with other components and services.
- When possible, interaction through commands and operations should be preferred, as this introduces the loosest coupling.
- When you need stronger coupling and direct access to a service, then dependency injection can be used to reference services.
If a component or service needs access to the ArcGIS MapView object powering the applications map, it can reference it through an ILayoutModel
.
MapView
Interacting with the Components or services can interact with the MapView
by injecting an ILayoutModel
that takes a MapView
. The actual MapView
needs to be resolved once the map component has loaded, so it's best practice to resolve the ILayoutModel
in the initialization method of the component or service.
note
A layout model is resolved according to the layout hierarchy.
class CustomComponent : ComponentBase
{
private readonly ILayoutModel<MapView> _mapViewResolver;
private MapView _mapView;
public CustomComponent(ILayoutModel<MapView> mapViewResolver)
{
_mapViewResolver = mapViewResolver;
}
protected async override Task DoInitializeAsync()
{
_mapView = await _mapViewResolver.ResolveAsync();
var wkid = _mapView.SpatialReference.Wkid;
...
}
...
}
Relevant SDK Samples
Check out the relevant Geocortex Mobile SDK Samples: