Page 1 of 1
Wpf Xmap to zoom in by default
Posted: Sat Dec 17, 2016 10:02 am
by webdirekt
- 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)
Re: Wpf Xmap to zoom in by default
Posted: Tue Dec 20, 2016 2:56 pm
by Bernd Welter
How about using the following approach?
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);
At least works fine with MERCATOR:
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");
- Initial image section applied by my sample source
Best regards Bernd
Re: Wpf Xmap to zoom in by default
Posted: Wed Dec 21, 2016 8:10 am
by Joost
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) { }
}
Re: Wpf Xmap to zoom in by default
Posted: Mon Dec 26, 2016 6:30 am
by webdirekt
Thanks for the feedback,it works fine for me.