Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
310
WindowCenter and WindowScale doesn't work when we call from Imported event.
posted

We are using the following method to zoom a specific region. It works most of the time.. But we found that it doesn't work if we call it from Imported event. 

private void Zoom() {
            var mapLocation = MainMap.MapProjection.ProjectToMap(new Point(8.516667, 23.5)); //FocalPoint="8.516667, 23.5"
            MainMap.WindowCenter = mapLocation;
            MainMap.WindowScale = 3.5;
}

Here is the sample code to reproduce the issue. 
XAML
 <ig:XamMap  x:Name="MainMap" IsAutoWorldRect="true">
            <ig:MapNavigationPane Visibility="Collapsed"/>
            <ig:XamMap.Layers>
                <ig:MapLayer LayerName="WorldLayer"  FillMode="Choropleth" HorizontalContentAlignment="Center" Resolution="0.5"
                             HorizontalAlignment="Center" VerticalAlignment="Center" VerticalContentAlignment="Center">
                    <ig:MapLayer.Reader>
                        <ig:SqlShapeReader 
                            DataMapping="Data=SpatialData; Name=CountryName" >
                            <ig:SqlShapeReader.CoordinateSystem>
                                <ig:CoordinateSystem UnitType="M" FalseEasting="0.0" FalseNorthing="0.0" >
                                    <ig:CoordinateSystem.Projection>
                                        <ig:MillerCylindrical EllipsoidType="WGS84" CentralMeridian="10.0" />
                                    </ig:CoordinateSystem.Projection>
                                </ig:CoordinateSystem>
                            </ig:SqlShapeReader.CoordinateSystem>
                        </ig:SqlShapeReader>
                    </ig:MapLayer.Reader>
                    <ig:MapLayer.ValueScale>
                        <ig:LinearScale  IsAutoRange="True"/>
                    </ig:MapLayer.ValueScale>
                </ig:MapLayer>                
            </ig:XamMap.Layers>
        </ig:XamMap>
C#
public partial class MainPage : UserControl {
        MapLayer worldLayer;
 
        public MainPage() {
            InitializeComponent();
            worldLayer = MainMap.Layers["WorldLayer"as MapLayer;
            worldLayer.Imported += new MapLayerImportEventHandler(worldLayer_Imported);
            Loaded += new RoutedEventHandler(MainPage_Loaded);
        }
 
        void worldLayer_Imported(object sender, MapLayerImportEventArgs e) {            
            Zoom();
        }
 
        static MemoGeoServiceClient geoService = new MemoGeoServiceClient();
 
        void MainPage_Loaded(object sender, RoutedEventArgs e) {
            geoService.GetWorldCompleted += GetWorldCompleted;
            geoService.GetWorldAsync();
        }
 
        private void GetWorldCompleted(object sender, GetWorldCompletedEventArgs e)
        {
            if (e.Error == null)
            {
                var sqlReader = worldLayer.Reader as SqlShapeReader;
                sqlReader.DataSource = e.Result;
                worldLayer.ImportAsync();
                MainMap.WindowFit();
 
                
            }            
        }
 
        private void Zoom() {
            var mapLocation = MainMap.MapProjection.ProjectToMap(new Point(8.516667, 23.5)); //FocalPoint="8.516667, 23.5"
            MainMap.WindowCenter = mapLocation;
            MainMap.WindowScale = 3.5;
        }       
    }
If you move this Zoom(); method from worldLayer_Imported to somewhere (e.g. GetWorldCompleted event) then it will work. 
Let me know if you need more information.. 
Thanks.
P.S: We reported about one issue related to non-English culture in my account. Please help to take a look at this issue as well. Thanks. 



 

Parents
No Data
Reply
  • 3255
    posted

    Hi Michael,

    In its current version SqlShapeReader's ImportAsync is executed synchronously which means the Zoom method is called first and then MainMap.WindowFit() whicj changes the WindowScale value.

    Sorry for any inconvenience.

    I am looking into the second issue you mentiond and I will post back here my findings.

    Regards,

    Ivan Kotev

Children