Domanda

Esri's ArcGIS for WPF does not seem to have any real MVVM support or binding support; unless I'm mistaken.

Anyway, I am creating a tracking application and it needs to track objects via GPS coordinates.

I have implemented a custom IGeoPositionWatcher<GeoCoordinate> which is used with the GpsLayer. This all works perfectly. I can modify the GPS coordinates and my little dot on the map moves smoothly to it's final resting place. My problem is that I can't use the little dot and arrow that comes with the GpsLayer. I need a custom MarkerSymbol to be something similar to the following:

<Grid>
   <Image Source="{Binding Pogostick.HeightImage}" />
   <TextBlock Text="{Binding Pogostick.PogoId}" />
</Grid>

I have a list (amount unknown and changes at any given moment) of these "pogosticks" which are always tracking by GPS and need to have the symbol update according to its status. The problem is that I can't get the Pogostick object to be the DataContext for the custom MarkerSymbol.ControlTemplate and there for my image source and text do not show.

I'm trying to avoid using a Graphic in a GraphicLayer and would like this to work with the GpsLayer. Is there a way to do this at all? Am I even approaching this correctly... should I be using a GraphicLayer or a FeatureLayer?

I want to render these tracked pogosticks on the user's desktop app and not by editing layers or features on the map service. Perhaps I should be using a custom renderer?

È stato utile?

Soluzione

I've figured out a way to do this. I created a class which inherits from MarkerSymbol which has a DependencyProperty which holds the object I want to bind to (the Pogostick class).

public class EntityMarkerSymbol : MarkerSymbol
{
    public static readonly DependencyProperty EntityProperty;

    static EntityMarkerSymbol()
    {
        EntityMarkerSymbol.EntityProperty = DependencyProperty.Register("Entity", typeof(object), typeof(EntityMarkerSymbol), new PropertyMetadata());
        return;
    }

    public EntityMarkerSymbol()
    {
        return;
    }

    public object Entity
    {
        get { return this.GetValue(EntityMarkerSymbol.EntityProperty); }
        set { this.SetValue(EntityMarkerSymbol.EntityProperty, value); }
    }
}

Then I create a ControlTemplate in a resource dictionary like so:

<ControlTemplate x:Key="PogostickMarker">
    <StackPanel>
        <Image Source="{Binding Symbol.Entity.HeightImage}" />
        <TextBlock Text="{Binding Symbol.Entity.PogostickId}" />
    </StackPanel>
</ControlTemplate>

The key to this working is that ArcGIS for WPF will automatically assign the MarkerSymbol's DataContext to it's sealed class DataBinding which contains a reference to the MarkerSymbol assigned to the GpsLayer's LocationMarkerSymbol. So I can access my custom symbols Entity property through this binding.

The code used to create the GpsLayer and assign the MarkerSymbol is below:

GpsLayer layer = new GpsLayer();
EntityMarkerSymbol marker = new EntityMarkerSymbol() { Entity = pogoStick };

marker.ControlTemplate = Application.Current.Resources["ConvoyMarker"] as ControlTemplate;
layer.LocationMarkerSymbol = marker;

NOTE: this approach cannot be used when the UseAcceleratedDisplay property of the map is set to True. If someone can figure out how to use this approach with that property set to true, please let me know.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top