Zooming in and out programmatically in C# works very well but ZoomInFixed and ZoomOutFixed don't allow you to to zoom to an exact scale as you apparently can't change the zoom factor - is there a property hidden away somewhere to control this?
You can make an add-in with buttons for your own zoom functionality. Here is the sample button code to step down the scale:
<SPAN class="keyword token">protected</SPAN> <SPAN class="keyword token">override</SPAN> <SPAN class="keyword token">void</SPAN> <SPAN class="token function">OnClick</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// get the active mapview</SPAN> MapView activeMapView <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN>Active<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>activeMapView <SPAN class="operator token">==</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">return</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// note that MapView.ZoomIn must be called on the MCT</SPAN> QueuedTask<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Run</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">=</SPAN><SPAN class="operator token">></SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="comment token">// get the original camera position </SPAN> <SPAN class="keyword token">var</SPAN> camera <SPAN class="operator token">=</SPAN> activeMapView<SPAN class="punctuation token">.</SPAN>Camera<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// lower the scale </SPAN> <SPAN class="keyword token">var</SPAN> scale <SPAN class="operator token">=</SPAN> camera<SPAN class="punctuation token">.</SPAN>Scale <SPAN class="operator token">-</SPAN> <SPAN class="number token">1.0</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> sScale <SPAN class="operator token">=</SPAN> $<SPAN class="string token">@"{scale:0}"</SPAN><SPAN class="punctuation token">;</SPAN> sScale <SPAN class="operator token">=</SPAN> sScale<SPAN class="punctuation token">.</SPAN><SPAN class="token function">Substring</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">PadRight</SPAN><SPAN class="punctuation token">(</SPAN>sScale<SPAN class="punctuation token">.</SPAN>Length<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">Replace</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">' '</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'0'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> nextLowerScale <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">double</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="token function">Parse</SPAN><SPAN class="punctuation token">(</SPAN>sScale<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> camera<SPAN class="punctuation token">.</SPAN>Scale <SPAN class="operator token">=</SPAN> nextLowerScale<SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">// zoom in</SPAN> activeMapView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">ZoomTo</SPAN><SPAN class="punctuation token">(</SPAN>camera<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Please note that working with scale(s) in only relevant in 2D maps.
Have you succeeded in making this work? It was one of the first alternatives I tried and didn't work for me. My code looked pretty much like yours.
I guess the answer to my original question is that there is no way of setting the zoom factor for ZoomInFixed and ZoomOutFixed?
i copied the code snippet above from a working sample, so yes it does work on 2D maps (scale is not relevant in 3D). i don't know any way to change the behavior of the built-in ZoomInFixed/ZoomOutFixed buttons.
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.