<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Map.ZoomTo() not working in Initialized event handler for OpenStreetMapLayer in ArcGIS API for Silverlight Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434481#M11219</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It was not so easy to tell from the documentation exactly when the Extent of the Map is guaranteed to be properly initialized. I actually got the idea with the Initialized event from the SDK documentation of Map.ZoomTo().&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I should have mentioned that the code I presented here was just a test for this problem. What I really try to achieve in my app is to keep the extent while changing the map's spatial reference (which can only be done by creating a new Map control and manually projecting the old extent with a Geometry Service, right?), so setting an initial extent does not solve my real problem. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I will try the ExtentChanged event instead, although it feels a bit scary to change the extent in that handler (risk of recursion), but I guess ZoomTo() is an asynchronous operation. Can I also thrust that the SpatialReference property of the Map is initialized in that event? I'll post by my results here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Dec 2010 05:58:23 GMT</pubDate>
    <dc:creator>MarkusHjärne</dc:creator>
    <dc:date>2010-12-15T05:58:23Z</dc:date>
    <item>
      <title>Map.ZoomTo() not working in Initialized event handler for OpenStreetMapLayer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434479#M11217</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;when I try to zoom to a given extent in the event handler for the Initailized event of an OpenStreetMapLayer, the XMax of the map's extent becomes Infinity and YMin becomes -Infinity.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In XAML I have a Map control with a single OpenStreetMapLayer:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;esri:Map Background="White" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; HorizontalAlignment="Left" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Margin="12,12,0,0" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Name="map1" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; VerticalAlignment="Top" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Height="308" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Width="471" &amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;esri:OpenStreetMapLayer ID="OSM" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Style="Mapnik" &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Initialized="OpenStreetMapLayer_Initialized"/&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;/esri:Map&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and in the code behind I have this event handler:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;private void OpenStreetMapLayer_Initialized(object sender, EventArgs e)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; Envelope extent = new Envelope(1400000, 7420000, 1470000, 7450000)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; {&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SpatialReference = map1.SpatialReference&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; };&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; map1.ZoomTo(extent);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This works for ArcGISDynamicMapServiceLayer and Bing TileLayer. I'm using the Silverlight/WPF API version 2.0.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does anybody know if this is a correct way of using ZoomTo() or why it doesn't work for OpenStreetMapLayer?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Dec 2010 22:24:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434479#M11217</guid>
      <dc:creator>MarkusHjärne</dc:creator>
      <dc:date>2010-12-14T22:24:18Z</dc:date>
    </item>
    <item>
      <title>Re: Map.ZoomTo() not working in Initialized event handler for OpenStreetMapLayer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434480#M11218</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You should not be calling ZoomTo or PanTo until the map has its extent property set. There is no guarantee this is set when a layer initializes. Either wait for the first ExtentChanged event to fire, or set the extent instead of zooming to it (since this is at startup you are really better of just setting the extent). You can set the extent whenever you want, and don't have to wait for any other properties to be set, or layers to be ready.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Dec 2010 23:44:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434480#M11218</guid>
      <dc:creator>dotMorten_esri</dc:creator>
      <dc:date>2010-12-14T23:44:37Z</dc:date>
    </item>
    <item>
      <title>Re: Map.ZoomTo() not working in Initialized event handler for OpenStreetMapLayer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434481#M11219</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It was not so easy to tell from the documentation exactly when the Extent of the Map is guaranteed to be properly initialized. I actually got the idea with the Initialized event from the SDK documentation of Map.ZoomTo().&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I should have mentioned that the code I presented here was just a test for this problem. What I really try to achieve in my app is to keep the extent while changing the map's spatial reference (which can only be done by creating a new Map control and manually projecting the old extent with a Geometry Service, right?), so setting an initial extent does not solve my real problem. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But I will try the ExtentChanged event instead, although it feels a bit scary to change the extent in that handler (risk of recursion), but I guess ZoomTo() is an asynchronous operation. Can I also thrust that the SpatialReference property of the Map is initialized in that event? I'll post by my results here.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for the help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Dec 2010 05:58:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434481#M11219</guid>
      <dc:creator>MarkusHjärne</dc:creator>
      <dc:date>2010-12-15T05:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Map.ZoomTo() not working in Initialized event handler for OpenStreetMapLayer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434482#M11220</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You can also listen to Map.Layers.LayersInitialized event &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.LayerCollection~LayersInitialized_EV.html" rel="nofollow noopener noreferrer" target="_blank"&gt;http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.LayerCollection~LayersInitialized_EV.html&lt;/A&gt;&lt;SPAN&gt;. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Note however, that this event will fire every time a new layer is added to your map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;public MainPage()
{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeComponent();
 MyMap.Layers.LayersInitialized += Layers_LayersInitialized;
}
bool performedInitialZoom = false;
private void Layers_LayersInitialized(object sender, EventArgs args)
{
 if (!performedInitialZoom)
 {
&amp;nbsp; MyMap.ZoomTo(someExtent);
&amp;nbsp; performedInitialZoom = true;
 }&amp;nbsp;&amp;nbsp; 
}&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:28:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434482#M11220</guid>
      <dc:creator>JenniferNery</dc:creator>
      <dc:date>2021-12-11T19:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Map.ZoomTo() not working in Initialized event handler for OpenStreetMapLayer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434483#M11221</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the tip with the LayersInitialized event, I didn't know about it before.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;My app worked when I used the ExtentChanged event instead...kind of. The problem now is that first the map draws in full extent and then my code changes to the previous extent, this causes a lot of flickering in the map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm thinking of a new approach that will be to first initialize the new base map layer the user wants to change to, project the map's current extent using the spatial reference of the base map layer with a geometry service, create a new map and set its extent before adding the base map layer and the rest of the (projectable) layers to it, and finally replace the old map in the object tree with the new map.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But before I try that it would be good to know if a layer's SpatialReference property is guaranteed to be set when its Initialized event is raised.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Dec 2010 21:12:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434483#M11221</guid>
      <dc:creator>MarkusHjärne</dc:creator>
      <dc:date>2010-12-15T21:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: Map.ZoomTo() not working in Initialized event handler for OpenStreetMapLayer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434484#M11222</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes, the layer's SpatialReference is set on Initialize() and will be available when Initialized event is raised. Check for layer.IsInitialized property and layer.SpatialReference != null.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For Map's SpatialReference, kindly look at this help document: &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Map~SpatialReference.html"&gt;http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Map~SpatialReference.html&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Dec 2010 21:28:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434484#M11222</guid>
      <dc:creator>JenniferNery</dc:creator>
      <dc:date>2010-12-15T21:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Map.ZoomTo() not working in Initialized event handler for OpenStreetMapLayer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434485#M11223</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;My new approach works really fine, although it was a bit tricky chaining all the asynchronous calls needed to make it work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for all your help!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 19 Dec 2010 10:30:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434485#M11223</guid>
      <dc:creator>MarkusHjärne</dc:creator>
      <dc:date>2010-12-19T10:30:51Z</dc:date>
    </item>
    <item>
      <title>Re: Map.ZoomTo() not working in Initialized event handler for OpenStreetMapLayer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434486#M11224</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;MyMap.ExtentChanged += OnMapExtentChanged;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;void OnMapExtentChanged(object sender, ExtentEventArgs e)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyMap.ExtentChanged -= OnMapExtentChanged; //unhook so we only listen the first time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; //TODO...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;But again I don't see why you want to do a ZoomTo at startup, since there won't really be anything loaded yet to zoom from. Just simply set the extent on the map, which you can do at any time:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;myMap.Extent = new Extent(x1,y1,x2,y2);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to set the extent of a specific layer, just do this when that layer initializes:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;myMap.Extent = myLayerThatJustInitialized.FullExtent;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Dec 2010 16:18:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434486#M11224</guid>
      <dc:creator>dotMorten_esri</dc:creator>
      <dc:date>2010-12-21T16:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: Map.ZoomTo() not working in Initialized event handler for OpenStreetMapLayer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434487#M11225</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In this new approach I don't do a ZoomTo() at startup, I just initialize the empty map with an extent and then add the layers just as you suggested. But in my original approach I had layers in the map in XAML, so then I hadn't much choice but to do a ZoomTo() if I wanted to change the extent.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Although it would have been much easier if it had been possible to just remove all the layers from the map, change the map's extent to an extent with another spatial reference (causing the map spatial reference to change too) and then add the layers back.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Dec 2010 18:19:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-silverlight-questions/map-zoomto-not-working-in-initialized-event/m-p/434487#M11225</guid>
      <dc:creator>MarkusHjärne</dc:creator>
      <dc:date>2010-12-21T18:19:34Z</dc:date>
    </item>
  </channel>
</rss>

