Select to view content in your preferred language

esri:Map and databinding + MVVM

2306
3
08-24-2012 02:44 AM
PetteriLehtonen
New Contributor
Hi,

I'm really struggling with the Silverlight map control and data binding with MVVM.

Is there actually a good way to do this?

So far I have tried:

PointDatasource with a custom MarkerSymbol, could not get properties to custom symbol (i want to forexample show a customername textblock on the symbol, checkboxes with TwoWay binding etc.)

ElemenLayer where i create elements manually (on code-behind), but this way i cant get the items to be on correct position. (My next plan was to set the binding manually on code-behind)

(Somethin like this):
Button pinni = new Button();
Envelope el = new Envelope(Latitude, Longitude, Latitude, Longitude);
pinni.SetValue(ElementLayer.EnvelopeProperty, el);
elementlayer.Children.Add(pinni);


Tried looking at all the samples i could find, but so far haven't found nothing like this. That really supprises me since this should be the "defacto" way to do these things....

Cheers,

Petteri
0 Kudos
3 Replies
DominiqueBroux
Esri Frequent Contributor
PointDatasource with a custom MarkerSymbol, could not get properties to custom symbol (i want to forexample show a customername textblock on the symbol, checkboxes with TwoWay binding etc.)

How to you create tour pointdatasource? You can add attributes to your graphics and these attributes shold then be able to be displayed on the symbol.

ElemenLayer where i create elements manually (on code-behind), but this way i cant get the items to be on correct position. (My next plan was to set the binding manually on code-behind)


Probably that the correct position is the top left position of your symbol. If that's the case, it's a 'center' issue.
You can either apply a negative margin to your element (half it's size), or surround it with your own container that would center it's content.
0 Kudos
PetteriLehtonen
New Contributor
How to you create tour pointdatasource? You can add attributes to your graphics and these attributes shold then be able to be displayed on the symbol.



Like this:
<esri:GraphicsLayer.GraphicsSource>               
<esri:PointDataSource ItemsSource="{Binding DataSource.ServiceOrderLocations, Source={StaticResource DataContextProxy}}" XCoordinateBinding="{Binding ServiceOrderLocation.Longitude}" YCoordinateBinding="{Binding ServiceOrderLocation.Latitude}">
</esri:PointDataSource>
</esri:GraphicsLayer.GraphicsSource>

How to add attributes on PointDataSource, do you have a sample of that?


Probably that the correct position is the top left position of your symbol. If that's the case, it's a 'center' issue.
You can either apply a negative margin to your element (half it's size), or surround it with your own container that would center it's content


The elements all just came to sea near Africa. I think, thats the 0,0,0,0 position.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
The elements all just came to sea near Africa. I think, thats the 0,0,0,0 position.


Might be a spatial reference issue,e.g  the map in Web Mercator coordinates and data in geographical coordinates.

Like this:
<esri:GraphicsLayer.GraphicsSource>
<esri:PointDataSource ItemsSource="{Binding DataSource.ServiceOrderLocations, Source={StaticResource DataContextProxy}}" XCoordinateBinding="{Binding ServiceOrderLocation.Longitude}" YCoordinateBinding="{Binding ServiceOrderLocation.Latitude}">
</esri:PointDataSource>
</esri:GraphicsLayer.GraphicsSource>

How to add attributes on PointDataSource, do you have a sample of that?


AS you are using a PoitDataSource there is a sample here : http://resources.arcgis.com/en/help/silverlight-api/samples/start.htm#UsingPointDataSource

Note that the maptip displays an attribute coming from the view model.
Code:
                <esri:GraphicsLayer.MapTip>
                    <Border Padding="4,2" Background="#99333333" CornerRadius="8" 
                            DataContext="{Binding [DataContext]}">
                        <TextBlock Text="{Binding Name}" Foreground="White" />
                    </Border>
                </esri:GraphicsLayer.MapTip>

The view model is stored in the attribute "DataContext" and from it you can access the 'Name' property.

For a symbol the datacontext is one level up (you need to give the Attributes dictionary in the path), so a symbol displaying the Name property would contain:
<TextBlock Text="{Binding Attributes[DataContext].Name}" Foreground="White" />
0 Kudos