Select to view content in your preferred language

Address locator problem

687
7
04-26-2010 12:53 PM
DonFreeman
New Contributor
The ESRI sample at
http://resources.esri.com/help/9.3/arcgisserver/apis/silverlight/samples/start.htm#AddressToLocation
requires 2 clicks to get the map to zoom AND center on the found address. I have experimented several ways to get it to do both on a single click but haven't been able to find a solution. Is this a bug in the zoom function? Has anyone found a workaround?

Thanks
0 Kudos
7 Replies
dotMorten_esri
Esri Notable Contributor
I'm not seeing this. Could you tell us a little about what OS, SL version and browser you are using?
0 Kudos
DominiqueBroux
Esri Frequent Contributor
Looks like there is a small issue in the sample because the first time the user selects an address, it's calling ZoomToResolution but this method is not supposed to center on the given point.
If we try calling successively ZoomToResolution + PanTo, we run into trouble because these methods are asynchronous.

There is already a thread about this issue (without definitive solution) http://forums.arcgis.com/threads/2269-Zoom-and-Pan-with-Address-locator

Dominique
0 Kudos
DominiqueBroux
Esri Frequent Contributor
After removing the dust from my student geometry books, I eventually got a method which centers AND pans to a point.

private void centerAndZoom(ESRI.ArcGIS.Client.Map map, ESRI.ArcGIS.Client.Geometry.MapPoint mapPoint, double resolution)
{
 double ratio = 1.0;
 if (map.Resolution != 0.0)
  ratio = resolution / map.Resolution;

 if (ratio == 1.0)
  map.PanTo(mapPoint);
 else
 {
  ESRI.ArcGIS.Client.Geometry.MapPoint mapCenter = map.Extent.GetCenter();
  double X = (mapPoint.X - ratio * mapCenter.X) / (1 - ratio);
  double Y = (mapPoint.Y - ratio * mapCenter.Y) / (1 - ratio);
  map.ZoomToResolution(resolution, new ESRI.ArcGIS.Client.Geometry.MapPoint(X, Y));
 }
}


/Dominique
0 Kudos
DonFreeman
New Contributor
Thanks dbroux -

Can you tell me how to assign a value to the variable resolution?

Thanks
0 Kudos
DonFreeman
New Contributor
After more thought I deduced that any arbitrary number that produces a good result would probably be OK, so I settled on a value of 150.

Thanks again.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
With the 'address to location' sample, you can use 'centerAndZoom' instead of ZoomToResolution this way:

//if (_firstZoom)
//{
//    MyMap.ZoomToResolution(MyMap.Resolution / 6, pt);
//    _firstZoom = false;
//}
//else
//    MyMap.PanTo(pt);
centerAndZoom(MyMap, pt, MyMap.MinimumResolution * 4);


This will give good results.

/Dominique
0 Kudos
BrandonIves
New Contributor
I am attempting to get an App up and running using an Address locator. I want to pass the address through a url (http://gisadev/cismap?Address=301 E Central). My app grabs the correct parameters and is supposed to zoom to the appropriate address after finding a match.

This works great in Visual Studio when testing and when running directly on the server. But when I attempt to run the application from my client machine and copy/paste the exact same url to IE I can find the correct address but the zoom to function isn't working. I know that I am finding a match because the canidates list is populated. The map will only load at the full extent instead of zooming to the correct address.

Any thoughts on what could be different between VS, the server that the app is published to, and any clients. The map loads fine without errors on all three (VS, server, and client) but only the client machine won't zoom to the address. In VS the URL, if entered in as http://gisadev/cismap?Address=301 E Central, will automatically add a %20 for the spaces. On the server the spaces stay spaces when running the app. Both find the correct address and complete the zoomto. When I run the app on the client machine by typing in the URL with spaces it fills in %20 again, finds the address and doesn't zoom to.

Sorry for the long post. It is hard to explain even when someone is sitting here looking at the problem as I explain.
0 Kudos