Page 1 of 1

Looking for solution to display active region in Map center

PostPosted: 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

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

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

are you sure you're getting you points right? It works for me as excpected.


How i verified this:
[*] Downloaded the project
[*] 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.

Code: Select all
        private void SelectedRegions_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
            if(this.selectedRegions.Count == 0)
                propertyGrid1.SelectedObject = null;

            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%


            // ....

            // dump all attributes

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

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