Select to view content in your preferred language

Zooming/Navigating to point

881
5
12-22-2010 12:56 PM
SteveDobrioglo
Deactivated User
Hello experts. I hope someone can help me. A contractor developed an app for us, is gone and I need to make an enhancement such as grabbing Lat/Long from a browser QueryString and zoom/locate to that location.

I've done ASP.NET but didn't work with ArcGIS, ESRI Silverlight framework or ASP.NET MVC.
I can retrieve URL params but zooming doesn't work. I tried some examples from ESRI forums but no luck so far.

Below is where I place my (bolded) code. Any suggestions/ideas to get it working? Thanks in advance.

- Steve
  void MainPage_Loaded(object sender, System.Windows.RoutedEventArgs e)
  {
   RoleAccess roleAccess = IoC.Resolve<RoleAccess>();

   roleAccess.Initialize(() => Dispatcher.BeginInvoke(() =>
    {
     Map map = AddMap();

     _nav.Map = map;
     _scaleBar.Map = map;

     var baseMapTabsViewModel = IoC.Resolve<BaseMapTabsViewModel>();
     baseMapTabsViewModel.Map = map;
     baseMapTabsViewModel.LayerID = "BaseLayer";
     _baseMapTabs.DataContext = baseMapTabsViewModel;

     var mapLayersMenuViewModel = IoC.Resolve<LayersMenuViewModel>();
     mapLayersMenuViewModel.Map = map;
     _mapLayersMenu.DataContext = mapLayersMenuViewModel;
     _mapLayersMenu.Visibility = roleAccess.IsControlAvailable("layerList").ToVisibility();

     _legend.DataContext = IoC.Resolve<LegendViewModel>();
     _legend.Visibility = roleAccess.IsControlAvailable("legend").ToVisibility();

     if (roleAccess.IsControlAvailable("identify"))
     {
      var identifyViewModel = IoC.Resolve<IdentifyViewModel>();
      identifyViewModel.Map = map;
      identifyViewModel.Symbol = DefaultPictureSymbol;
      _identify.DataContext = identifyViewModel;
     }
     _identify.Visibility = roleAccess.IsControlAvailable("identify").ToVisibility();
    
     _greeting.DataContext = IoC.Resolve<GreetingViewModel>();

     var spacialBookmarksViewModel = IoC.Resolve<SpacialBookmarksViewModel>();
     spacialBookmarksViewModel.Map = map;
     _spacialBookmarks.DataContext = spacialBookmarksViewModel;
     _spacialBookmarks.Visibility = roleAccess.IsControlAvailable("linkBookmarks").ToVisibility();

     var searchResultsViewModel = IoC.Resolve<SearchResultsViewModel>();
     searchResultsViewModel.Map = map;
     searchResultsViewModel.Symbol = DefaultFillSymbol;
     _searchResults.DataContext = searchResultsViewModel;

     if (!roleAccess.IsControlAvailable("printing"))
      _printButton.Visibility = Visibility.Collapsed;

     _printButton.Click += (s, a) =>
                            {
            var printDialogViewModel = IoC.Resolve<PrintDialogViewModel>();
            printDialogViewModel.Map = map;
            
            var printing = new PrintDialog();
                             printing.DataContext = printDialogViewModel;
                             printing.Show();
                            };

     var locationDisplayViewModel = IoC.Resolve<LocationDisplayViewModel>();
     locationDisplayViewModel.Map = map;
     _locationDisplay.DataContext = locationDisplayViewModel;
     _locationDisplay.Visibility = roleAccess.IsControlAvailable("locationDisplay").ToVisibility();

     ZoomToViewModel zoomToViewModel = IoC.Resolve<ZoomToViewModel>();
     zoomToViewModel.Map = map;
     zoomToViewModel.Symbol = PoiMarkerSymbol;
     zoomToViewModel.FillSymbol = DefaultFillSymbol;
     _zoomTo.DataContext = zoomToViewModel;
     _zoomTo.Visibility = roleAccess.IsControlAvailable("zoomTo").ToVisibility();

     OverviewMapViewModel overviewMapViewModel = IoC.Resolve<OverviewMapViewModel>();
     overviewMapViewModel.Map = map;
     _overviewMap.DataContext = overviewMapViewModel;

                    double dblLat = Convert.ToDouble(HtmlPage.Document.QueryString["lat"]);
                    double dblLong = Convert.ToDouble(HtmlPage.Document.QueryString["long"]);
                    MapPoint myPoint = new MapPoint(dblLat, dblLong);
                    map.ZoomTo(myPoint);

    }));

  } 
0 Kudos
5 Replies
DanielWalton
Frequent Contributor
ZoomTo() doesn't work for a MapPoint, I believe. Instead you should call ZoomToResolution() and supply the mappoint and a resolution value.
0 Kudos
SteveDobrioglo
Deactivated User
ZoomTo() doesn't work for a MapPoint, I believe. Instead you should call ZoomToResolution() and supply the mappoint and a resolution value.


Dan - thanks for the idea. I tried ZoomToResolution with two overloads but it didn't work either.
I wonder if I need to call ZoomTo or ZoomToResolution from other place than MainPage_Loaded.


I tried zooming from Main_Page(), after MainPage_Loaded() was called but then I don't have a reference to the map object.

public MainPage()
  {
   InitializeComponent();

   Loaded += MainPage_Loaded; // I placed ZoomTo/ZoomToResolution into the MainPage_Loaded before


[INDENT]                  [INDENT]// I tried to initiate zooming here but no reference to the map object[/INDENT][/INDENT]
}
0 Kudos
DanielWalton
Frequent Contributor
I would place that code in the BaseLayer_Initialized event handler (first layer in your map, usually a tiled map service). There you will definitely have a reference to the map control with the spatial reference set.

[HTML]<esri:Map x:Name="Map" >
       <esri:ArcGISTiledMapServiceLayer
                Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"           
                Initialized="baseLayer_Initialized" />
</esri:Map>[/HTML]
0 Kudos
SteveDobrioglo
Deactivated User
I would place that code in the BaseLayer_Initialized event handler (first layer in your map, usually a tiled map service). There you will definitely have a reference to the map control with the spatial reference set.

[HTML]<esri:Map x:Name="Map" >
       <esri:ArcGISTiledMapServiceLayer
                Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer"           
                Initialized="baseLayer_Initialized" />
</esri:Map>[/HTML]


Thanks Dan. I searched for <esri:Map tag and I don't have it in my solution so I'll ask you a silly question: where this HTML code would go, into which page?

Base layer might get initialized in a ViewModel.

ASP.NET MVC is making it hard for me. Thanks.

- Steve
0 Kudos
DanielWalton
Frequent Contributor
Your map is being declared in AddMap(). Wherever the first layer is added with Map.Layers.Add(...) , attach the event handler for the Initialized event to that layer before you add it to the map. Since I can't see all your code I'm not sure where that's happening.
0 Kudos