Page 1 of 1

Looking for solution to display active region in Map center

Posted: Fri Jul 28, 2017 6:58 am
by webdirekt
- We have the list of Points (i.e. X and Y coordinates) and Geometry data with respect to list of zip codes.
- Based on result of Geometry data; we have added BaseLayer in the map using the tile renderer which is implemented from ITiledProvider interface (Ptv.XServer.Controls.Map.Layers.Tiled).
- We have set the map control envelope using the list of Points (i.e. X and Y coordinates).

Code: Select all

wpfMap.SetEnvelope(new MapRectangle(pointList), "OG_GEODECIMAL");
-- wpfMap: ptv wpf map control.
-- pointList: list of Points (i.e. X and Y coordinates).
-- "OG_GEODECIMAL": Point format
Issue:
Active region is displayed in the center of the map as expected but some part of the region is still out side the map.
Find "ActiveRegionActualResult.png" which shows the current display of Map
Find "ActiveRegionExcpectedResult.png" which we want to display the Map in our App

Solutions tried:
We tried to decrease the zoom level of map programmatically as mentioned below, but its not working.
Option 1:

Code: Select all

ptvMap.Zoom = ptvMap.Zoom - 1;
Option 2:

Code: Select all

ptvMap.ZoomLevel = ptvMap.ZoomLevel - 1;

Re: Looking for solution to display active region in Map cen

Posted: Fri Jul 28, 2017 10:37 am
by Oliver Heilig
Hi,

are you sure you're getting you points right? It works for me as excpected.
envelope.png
How i verified this:
[*] Downloaded the project https://github.com/ptv-logistics/SharpMap.Widgets
[*] Set SharpMap.Win as startup project
[*] at Form1::SelectedRegions_CollectionChanged change like below

Note: The SetEnvelope method set the map section to fit the envelope exactly longitudal or latitulal, depending on the ration of the window/envelope. You can use the MapRect.Inflate() method to increase the size to get a buffer.

Oli

Code: Select all

        private void SelectedRegions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            if(this.selectedRegions.Count == 0)
            {
                propertyGrid1.SelectedObject = null;
                return;
            }

            var selectedItem = selectedRegions[0];

            // test: set the map envelope to fit the selected item;
            // ... using Ptv.XServer.Controls.Map;
            // ... using GeoAPI.Geometries;

            // set the maprectangle from sharpmap geomatry
            var envelope = selectedItem.Geometry.EnvelopeInternal;
            var rect = new MapRectangle(
                new System.Windows.Point(envelope.Right(), envelope.Top()),
                new System.Windows.Point(envelope.Left(), envelope.Bottom()));
            // inflate by 20%
            rect.Inflate(1.2);

            this.formsMap1.SetEnvelope(rect);

            // ....

            // dump all attributes

Re: Looking for solution to display active region in Map cen

Posted: Fri Jul 28, 2017 11:05 am
by webdirekt
Thank you very much. It works perfectly for us and solved the issue. :)