Hi
I am using the xammap control for silverlight and use Bing Maps as underlying tilesource layer.
Before using Bing Maps, the initial zoom was to the shape file, which fits perfectly our needs.
We have different shape files which are added dynamically, but we only have one layer at a time.
Our ideal solution would be that if the user accesses the chart the initial zoom would be exactly the shapefile and not the "entire world" like we have now. (we sometimes have shapefiles of smaller regions where it takes a long time to zoom to the region of interest).
How can we achieve this?
Thanks!
Roel
another question I have:
we are able to pan on the regions that are not covered by the shape file, but when we click on a region that is covered by the shape file, we cannot pan anymore. (zooming in/out with scroll still works). Can we solve this? I rather not have the zooming/panning control on the xammap control, but use the mouse.
Hi RoelMartens,
To set a focus on a particular shapefile, you could use the following approach:XAML: <igMap:XamMap x:Name="Map" Loaded="Map_Loaded" IsClickable="False"> <igMap:XamMap.Layers> <igMap:MapLayer x:Name="europe" Brushes="Green"> <igMap:MapLayer.Reader> <igMap:ShapeFileReader Uri="Shapefiles/europe/europe"/> </igMap:MapLayer.Reader> </igMap:MapLayer> </igMap:XamMap.Layers> </igMap:XamMap>CB: private void Map_Loaded(object sender, RoutedEventArgs e) { this.Map.WindowRect = this.Map.Layers[0].WorldRect; } Setting the IsClickable property of XamMap to False allows for panning the map, using mouse click even on the surface of the shapefile.
Edit: If you want to keep the IsClickable set to True, you could press and hold the Ctrl key while clicking/dragging with the mouse somewhere on the shapefile's surface. This would allow for the same functionality.
Hope that helps,Milana Zhileva
Hi Milana,
Thanks for the quick answer. The IsClickable property works for me, but initial zooming does not work for me.
Have you tried this with Bing Maps as underlying datasource?
I have:
public BingMap()
{
InitializeComponent();
InitImageryService();
InitMapCoordinates();
}
private void Map_Loaded(object sender, RoutedEventArgs e)
if (xamMap.Layers.Count > 0)
xamMap.WindowRect = xamMap.Layers[0].WorldRect;
As I debug, I have 1 layer, but the WorldRect seems to be empty. Could this be the problem?
Hi again,
Apologies for the confusion, unfortunately I missed something in my previous post - you need to make a small change in the code of the InitMapCoordinates() function in order to be able to zoom out after you've changed map's WindowRect to reflect that of a layer: private void InitMapCoordinates() { // define world dimensions Point worldTopLeft = new Point(-180, 90); Point worldBottomRight = new Point(180, -90);
// Convert Geodetic to Cartesian coordinates Point winTopLeft = this.Map.MapProjection.ProjectToMap(worldTopLeft); Point winBottomRight = this.Map.MapProjection.ProjectToMap(worldBottomRight);
// Create Rect structure the map control's WindowRect and WorldRect Rect winRect = new Rect() { X = Math.Min(winTopLeft.X, winBottomRight.X), Y = Math.Min(winTopLeft.Y, winBottomRight.Y), Width = Math.Abs(winTopLeft.X - winBottomRight.X), Height = Math.Abs(winTopLeft.Y - winBottomRight.Y) };
this.Map.IsAutoWorldRect = false; this.Map.WindowZoomMaximum = 80;
// Change the map control's WorldRect this.Map.WorldRect = winRect; }
Also, it would be a better practice to make sure that you set map's WindowRect after the layer's been imported like this: private void europe_Imported(object sender, Infragistics.Controls.Maps.MapLayerImportEventArgs e) { this.Map.WindowRect = this.Map.Layers[0].WorldRect; } Feel free to post back should you have any other questions.
Best regards,Milana Zhileva
This works perfectly!
Thanks for the quick response!
Br,