Can I call and set the XY location of center of the map with a button to variables? Any example?
Maybe each time the map moves it resets the variables?
If I set my spatial reference to:
Map<SPAN class="punctuation token">{</SPAN> id<SPAN class="punctuation token">:</SPAN> map spatialReference<SPAN class="punctuation token">:</SPAN> SpatialReference <SPAN class="punctuation token">{</SPAN> wkid<SPAN class="punctuation token">:</SPAN><SPAN class="number token">2150</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
All I want to do is click a button and have it display the center of map coordinates in UTM Zone 17N Nad83
Cant figure out how to do that
There is a MapView function that allows you to convert screen coordinates to Map coordinates called screenToLocation https://developers.arcgis.com/qt/latest/qml/api-reference/qml-esri-arcgisruntime-mapview.html#screenToLocation-method. You can get the screen coordinate of the center of your MapView object that contains your map by usig the QML function mapToGlobal and pass it the local center (width / 2, height / 2) of the MapView. You can do something like this in a button onClicked event handler:
<SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN><SPAN class="punctuation token">.</SPAN> <SPAN class="keyword token">let</SPAN> center <SPAN class="operator token">=</SPAN> myMapView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">mapToGlobal</SPAN><SPAN class="punctuation token">(</SPAN>Qt<SPAN class="punctuation token">.</SPAN><SPAN class="token function">point</SPAN><SPAN class="punctuation token">(</SPAN>myMapView<SPAN class="punctuation token">.</SPAN>width <SPAN class="operator token">/</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> myMapView<SPAN class="punctuation token">.</SPAN>height <SPAN class="operator token">/</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">let</SPAN> mapCenter <SPAN class="operator token">=</SPAN> myMapView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">screenToLocation</SPAN><SPAN class="punctuation token">(</SPAN>center<SPAN class="punctuation token">.</SPAN>x<SPAN class="punctuation token">,</SPAN> center<SPAN class="punctuation token">.</SPAN>y<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>
I hope this helps!
Keith
I put the below in OnClick of a button:
<SPAN class="keyword token">let</SPAN> center <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">mapToGlobal</SPAN><SPAN class="punctuation token">(</SPAN>Qt<SPAN class="punctuation token">.</SPAN><SPAN class="token function">point</SPAN><SPAN class="punctuation token">(</SPAN>MapView<SPAN class="punctuation token">.</SPAN>width <SPAN class="operator token">/</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">,</SPAN> MapView<SPAN class="punctuation token">.</SPAN>height <SPAN class="operator token">/</SPAN> <SPAN class="number token">2</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">let</SPAN> mapCenter <SPAN class="operator token">=</SPAN> MapView<SPAN class="punctuation token">.</SPAN><SPAN class="token function">screenToLocation</SPAN><SPAN class="punctuation token">(</SPAN>center<SPAN class="punctuation token">.</SPAN>x<SPAN class="punctuation token">,</SPAN> center<SPAN class="punctuation token">.</SPAN>y<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"mapCenter: "</SPAN> <SPAN class="operator token">+</SPAN> mapCenter<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
I get this error:
.qml:3420: TypeError: Property 'mapToGlobal' of object [object Object] is not a function
Do I need to import something at the top of the QML
Oh, I assumed that mapToGlobal would work for MapView because Qt Creator's intellisense said it was available even though it throws the error. The easiest way to get around it probably is to wrap the MapView in an Item object and set the size of the Item to the size that you want the MapView to be. Then, just fill the MapView in the Item and use the Item's mapToGlobal funciton and center to get the screen coordinates.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.