Wpf Xmap to zoom in by default

Within this forum we want to offer discussions all around our .NET based Map control including all .Net-language specific questions concerning calls of the xServer-API. Attention: xServer-relevant concepts can be found in further forums such as xRoute or xTour.
Post Reply
User avatar
webdirekt
Posts: 28
Joined: Wed Jul 15, 2015 10:18 am

Wpf Xmap to zoom in by default

Post 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)
Attachments
Xmap_After_Zoom_in
Xmap_After_Zoom_in
Xmap_default screen
Xmap_default screen
User avatar
Bernd Welter
Site Admin
Posts: 2703
Joined: Mon Apr 14, 2014 10:28 am
Contact:

Re: Wpf Xmap to zoom in by default

Post 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
Initial image section applied by my sample source
Best regards Bernd
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... :twisted:
Joost
Posts: 310
Joined: Fri Apr 25, 2014 1:46 pm

Re: Wpf Xmap to zoom in by default

Post 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) { }
        }
Joost Claessen
Senior Technical Consultant
PTV Benelux
User avatar
webdirekt
Posts: 28
Joined: Wed Jul 15, 2015 10:18 am

Re: Wpf Xmap to zoom in by default

Post by webdirekt »

Thanks for the feedback,it works fine for me. :D
Post Reply