This project has moved. For the latest updates, please go here.

Complex Feature/Layer and Zoom to Extent

Jul 18, 2013 at 8:21 AM
Hi,

First - very impressive control - great work! (and thanks for posting it)

I have a 2 questions:
  1. I need to add features to the map. The feature appearance is a triangle with some text in it. I was not able to do it (I am not that versed in WPF and this control usage) directly so I implemented it as 2 MapItemsControls - one the draw the triangle using a DataTemplate (copied the polyline resources from example) and the second that draws the text according to the PointItemStyle in the example). This does not do exactly as I want. My question is - how should I go about something like this - can I do it with one template? I tried to use MapPanel to place several controls but this didn't work.
  2. Is there a way I can zoom the map to the extent of some items? How should I go about it in a MVVM manner?
Thanks

Tomer
Coordinator
Jul 18, 2013 at 9:45 AM
Edited Jul 18, 2013 at 10:13 AM
Does the triangle actually have to be a map polygon? In other words, are the three corners of the triangle at geographic locations? And when you say "this does not do exactly as I want", then what exactly do you want, or where exactly is the problem?

Anyway, you may create a MapItem Style that contains a Polyline and perhaps a Label or TextBlock for the text, To illustrate this I changed the SamplePolyline class in the sample application to be derived from SamplePoint, so that it also has a Location and a Name property, in addition to its Locations property. Then I modified the PolylineItemStyle like this:
    <Style x:Key="PolylineItemStyle" TargetType="map:MapItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="map:MapItem">
                    <map:MapPanel>
                        <map:MapPolyline Locations="{Binding Locations}"
                                         Stroke="Red" StrokeThickness="3"/>
                        <Label map:MapPanel.Location="{Binding Location}"
                               Content="{Binding Name}" Background="#7FFFFFFF"
                               HorizontalAlignment="Center"
                               VerticalAlignment="Center"/>
                    </map:MapPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
For zooming to the extent of an item, there is no built-in feature in the Map Control that supports zooming to a certain extent (rectangle). Such kind of zooming can not easily be done in a general way that supports all possible use cases, including rotated maps. But it shouldn't be to complicated to calculate the required changes for the Center and ZoomLevel properties from the item's Locations and associated vieport points. MapBase has the methods to transform coordinates, like LocationToViewportPoint or ViewportPointToLocation.