<\/A>https:\/\/community.esri.com\/people\/EPolle_TensingInternational\/blog\/2020\/06\/14\/tutorial-arcgis-api-for-javascript-4x-table-of-contents<\/A><\/P>
clic derecho + arrastrar<\/CODE> con el ratón<\/LI><LI>presionando las teclas <CODE>A<\/CODE> y <CODE>D<\/CODE><\/LI><\/OL><P><\/P><P>Tú, como desarrollador, también puedes usar la navegación programática ajustando <A href="https:\/\/developers.arcgis.com\/javascript\/latest\/api-reference\/esri-views-MapView.html#rotation" rel="nofollow noopener noreferrer" target="_blank">MapView.rotation<\/A><\/P><P><\/P><P>Para permitir que el usuario restablezca la orientación de la brújula a 0 (es decir, con el norte en la parte superior de la vista) debes agregar un widget <A href="https:\/\/developers.arcgis.com\/javascript\/latest\/api-reference\/esri-widgets-Compass.html" rel="nofollow noopener noreferrer" target="_blank">Compass<\/A> a la vista. Este widget indica dónde está el norte en relación con la rotación actual de la vista. Al hacer clic en el widget, la vista rota para volver a mirar hacia el norte (heading = 0).<\/P><P><\/P><P>Entonces, en cierto sentido, podrías decir que solo necesitas este widget Compass cuando el mapa no está orientado al norte. O, al revés: la mayoría del tiempo no se necesita el widget Compass, porque el mapa está "correctamente" orientado.<\/P><P><\/P><P>En el ejemplo a continuación solo agregamos el Compass cuando el usuario rota el mapa (ya sea por accidente o a propósito). Y en el momento en que la orientación de la brújula se restablece a 0, lo eliminamos nuevamente.<\/P><P><\/P><P>Para verificar la orientación de la vista usamos <A class="link-titled" href="https:\/\/developers.arcgis.com\/javascript\/latest\/api-reference\/esri-core-watchUtils.html" title="https:\/\/developers.arcgis.com\/javascript\/latest\/api-reference/esri-core-watchUtils.html" rel="nofollow noopener noreferrer" target="_blank">watchUtils <\/> </A>de esta manera:<\/P><PRE class="lia-code-sample line-numbers language-none"><CODE>watchUtils<SPAN class="punctuation token">.<\/> <SPAN class="token function">whenTrue<\/> <SPAN class="punctuation token">(<\/> view<SPAN class="punctuation token">, <SPAN class="string token">"stationary"<\/> <SPAN class="punctuation token">, <SPAN class="keyword token">function<\/> <SPAN class="punctuation token">(<\/> <SPAN class="punctuation token">)<\/> {\n <SPAN class="keyword token">if<\/> <SPAN class="punctuation token">(<\/> view<SPAN class="punctuation token">.<\/> rotation <SPAN class="operator token">==<\/> 0<SPAN class="punctuation token">)<\/> {\n view<SPAN class="punctuation token">.<\/> ui<SPAN class="punctuation token">.<\/> remove<SPAN class="punctuation token">(<\/> compassWidget<SPAN class="punctuation token">)<\/> ;\n } else {\n view.ui.add(compassWidget, "top-left");\n }\n})<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
<html>\n <head>\n <meta charset=\"utf-8\" \/>\n <meta name=\"viewport\" content=\"initial-scale=1,maximum-scale=1,user-scalable=no\" \/>\n <title>Tutorial ArcGIS JavaScript - Agregar Widget Compass solo cuando sea necesario<\\title>\n <link rel=\"stylesheet\" href=\"https:\/\/js.arcgis.com/4.15/esri/themes/light/main.css\" \/>\n <script src=\"https:\/\/js.arcgis.com/4.15/\"><\\script>\n <style>\n html, body, #viewDiv {\n padding: 0;\n margin: 0;\n height: 100%;\n width: 100%;\n }\n <\\style>\n <script>\n require([\n \"esri/Map\",\n \"esri/views/MapView\",\n \"esri/widgets/Compass\",\n \"esri/core/watchUtils\"\n ], function(Map class="punctuation token">, MapView, Compass, watchUtils) {var mapa = new Map({ basemap: "national-geographic"});var vista = new MapView({ container: "viewDiv", scale: 500000, center: [26.26, 39.17], rotation: 45, map: mapa});var compassWidget = new Compass({ view: vista});// Observar la propiedad stationary de la vista para que sea true y verificar la rotación// Si la rotación es igual a 0 (es decir, el mapa está orientado al Norte) eliminar el widget compass,// de lo contrario agregar este widget watchUtils.whenTrue(vista, "stationary", function() {if (vista.rotation == 0) { vista.ui.remove(compassWidget ) ; } else } { vista<( compassWidget, "top-left")</); } }) }) </script>
Los miembros registrados pueden publicar, seguir actualizaciones y más. ¿Nuevo aquí? Regístrate gratis.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.