- We have xmap which shows points based on the coordinates provided to it.
- I want after showing the coordinates the map should zoom in by default.
- Please see the screen attached.
- By default (Xmap_default screen)
- Manually after zoom in(Xmap_After_Zoom_in)
Wpf Xmap to zoom in by default
- Bernd Welter
- Site Admin
- Posts: 2695
- Joined: Mon Apr 14, 2014 10:28 am
- Contact:
Re: Wpf Xmap to zoom in by default
How about using the following approach?
I assume you know the coordinates of the bounding rect:
At least works fine with MERCATOR:
I just manipulated the initial coordinates (factor 0.1 is a value to play with):
Best regards Bernd
I assume you know the coordinates of the bounding rect:
Code: Select all
double north = dictTransportDepot.Values.Max(y => y.transportPoint.location.point.y);
double south = dictTransportDepot.Values.Min(y => y.transportPoint.location.point.y);
double west = dictTransportDepot.Values.Min(x => x.transportPoint.location.point.x);
double east = dictTransportDepot.Values.Max(x => x.transportPoint.location.point.x);
I just manipulated the initial coordinates (factor 0.1 is a value to play with):
Code: Select all
double bufferH = (east - west) * 0.1;
double bufferV = (north - south) * 0.1;
north += bufferV;
south -= bufferV;
east += bufferH;
west -= bufferH;
formsMap1.SetEnvelope(new Ptv.XServer.Controls.Map.MapRectangle(west,east,south,north), "PTV_MERCATOR");
Bernd Welter
Technical Partner Manager Developer Components
PTV Logistics - Germany
Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning...
Technical Partner Manager Developer Components
PTV Logistics - Germany
Bernd at... The Forum,LinkedIn, Youtube, StackOverflow
I like the smell of PTV Developer in the morning...
Re: Wpf Xmap to zoom in by default
I'm using a similar approach to Bernd, but I'm basing myself on the layers of the map control itself for input.
Code: Select all
public static void ZoomMapToAll(this FormsMap mapControl)
{
double north = double.MinValue, south = double.MaxValue, west = double.MaxValue, east = double.MinValue;
string srid = "";
foreach (var layer in mapControl.Layers)
{
if (layer.GetType() == typeof(ShapeLayer))
{
var shapeLayer = (ShapeLayer)layer;
if (shapeLayer.Shapes.Count > 0)
{
north = Math.Max(shapeLayer.Shapes.Select(s => ShapeCanvas.GetLocation(s).Y).Max(), north);
south = Math.Min(shapeLayer.Shapes.Select(s => ShapeCanvas.GetLocation(s).Y).Min(), south);
east = Math.Max(shapeLayer.Shapes.Select(s => ShapeCanvas.GetLocation(s).X).Max(), east);
west = Math.Min(shapeLayer.Shapes.Select(s => ShapeCanvas.GetLocation(s).X).Min(), west);
}
srid = shapeLayer.SpatialReferenceId;
}
}
if (north == double.MinValue) return; // there is nothing drawn yet, so abort zoom function
double shiftX = (east - west) * 0.1, shiftY = (north - south) * 0.1;
var boundingBox = new MapRectangle()
{
North = north + shiftY,
South = south - shiftY,
East = east + shiftX,
West = west - shiftX,
};
try
{
mapControl.SetEnvelope(boundingBox, srid);
}
catch (Exception) { }
}
Joost Claessen
Senior Technical Consultant
PTV Benelux
Senior Technical Consultant
PTV Benelux
Re: Wpf Xmap to zoom in by default
Thanks for the feedback,it works fine for me.