<?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: ArcGIS JS 4 Rotate Graphic in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283148#M80985</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/564347"&gt;@BobCowling2&lt;/a&gt;&amp;nbsp; if the enhancements make it in, 4.27 is scheduled for early summer (2023).&lt;/P&gt;</description>
    <pubDate>Wed, 26 Apr 2023 23:54:52 GMT</pubDate>
    <dc:creator>AndyGup</dc:creator>
    <dc:date>2023-04-26T23:54:52Z</dc:date>
    <item>
      <title>ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283024#M80975</link>
      <description>&lt;P&gt;I am attempting to rotate an arrow based on a mobile phones device orientation. However simply changing the symbol angle does not seem to work. What is the proper way to rotate a graphic?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const arrowSymbol = {
  type: "simple-marker",
  path: "M10,0 L20,30 L10,20 L0,30 Z",
  color: [0, 0, 255, 1],
  outline: {
    color: [0, 0, 0, 1],
    width: 1
  },
  size: 25
};


const arrowGraphic = new Graphic({
  symbol: arrowSymbol
});

const track = new Track({
  view: view,
  graphic: arrowGraphic,
  useHeadingEnabled: false
});


  // Add the Track widget to the view
  view.ui.add(track, "top-right");
   
  window.addEventListener("deviceorientation", (event) =&amp;gt; {
  console.log(`${event.alpha} : ${event.beta} : ${event.gamma} : ${event.absolute} : ${event.webkitCompassHeading}`); 
  // get the heading value from the device
  const heading = event.alpha ? event.alpha * -1 : 0;

  // Rotate the arrow symbol based on the device's heading.
  arrowGraphic.symbol.angle = heading;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 23:17:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283024#M80975</guid>
      <dc:creator>BobCowling2</dc:creator>
      <dc:date>2023-04-26T23:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283120#M80977</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/564347"&gt;@BobCowling2&lt;/a&gt; we are working on similar functionality for the Track widget that is tentatively scheduled for the 4.27 release. I can post an update when that is available for testing on the 'next' build, or do you need something sooner than that?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 22:25:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283120#M80977</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2023-04-26T22:25:48Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283121#M80978</link>
      <description>&lt;P&gt;It's likely you'll have to replace the symbol object itself:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Rotate the arrow symbol based on the device's heading.
var newSymbol = arrowGraphic.symbol.clone();
newSymbol.angle = heading;

arrowGraphic.symbol = newSymbol;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If that doesn't work, you might try replacing the graphic entirely:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var newGraphic = arrowGraphic.clone();
newGraphic.symbol.angle = heading;

track.graphic = newGraphic;&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 26 Apr 2023 22:26:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283121#M80978</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2023-04-26T22:26:00Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283136#M80982</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/180"&gt;@AndyGup&lt;/a&gt;&amp;nbsp;I was hoping to get something up for summer use on our field app. Do you have an estimated date when this could be available? Even testing is fine. Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 23:18:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283136#M80982</guid>
      <dc:creator>BobCowling2</dc:creator>
      <dc:date>2023-04-26T23:18:32Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283137#M80983</link>
      <description>&lt;P&gt;Thank you, Joel. I did try cloning the arrow but it was making a new arrow every time there was a new position. If this is the only way I will have to test more!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 23:20:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283137#M80983</guid>
      <dc:creator>BobCowling2</dc:creator>
      <dc:date>2023-04-26T23:20:14Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283147#M80984</link>
      <description>&lt;P&gt;You'll need to manually remove the existing arrow graphic from the graphic layer first before adding the new one and that should prevent the visual stacking of arrows.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 23:36:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283147#M80984</guid>
      <dc:creator>JamesIng</dc:creator>
      <dc:date>2023-04-26T23:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283148#M80985</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/564347"&gt;@BobCowling2&lt;/a&gt;&amp;nbsp; if the enhancements make it in, 4.27 is scheduled for early summer (2023).&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 23:54:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1283148#M80985</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2023-04-26T23:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288326#M81129</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/564347"&gt;@BobCowling2&lt;/a&gt;&amp;nbsp; you can try out the new 2D heading graphic for the Track widget using the 4.27 'next' build: &lt;A href="https://github.com/Esri/feedback-js-api-next/" target="_blank"&gt;https://github.com/Esri/feedback-js-api-next/&lt;/A&gt;. The heading symbol will automatically display when the speed is greater than 0 and heading values are provided by the browser's Geolocation API.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 19:00:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288326#M81129</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2023-05-11T19:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288435#M81132</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/180"&gt;@AndyGup&lt;/a&gt;&amp;nbsp;Thanks! I did play around with it a little bit today, seems to bounce around in the wrong direction quite a bit but I will test it in more depth tomorrow. Does this use the GPS compass heading or the device orientation?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 02:00:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288435#M81132</guid>
      <dc:creator>BobCowling2</dc:creator>
      <dc:date>2023-05-12T02:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288602#M81140</link>
      <description>&lt;P&gt;The widget simply passes through &lt;U&gt;all&lt;/U&gt; Geolocation API results provided by the browser. Be sure to set the high-accuracy property in the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Track.html#geolocationOptions" target="_self"&gt;geolocation options&lt;/A&gt;. Browser Geolocation API implementations haven't been improved in years, so they can be very flaky. You can monitor what's being returned using something like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// https://developers.arcgis.com/javascript/latest/api-reference/esri-widgets-Track.html#event-track
track.on("track", (data) =&amp;gt; {
  const { longitude, latitude, altitude, heading, speed, accuracy } = data.position.coords;
  
  geolocationResultsDiv.innerText = `
  Latitude: ${latitude?.toFixed(4)}
  Longitude: ${longitude?.toFixed(4)}
  Altitude: ${altitude?.toFixed(1)}
  Heading: ${heading?.toFixed(0)}
  Speed: ${speed?.toFixed(2)}
  Accuracy: ${accuracy?.toFixed(0)}m`;
})&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 14:59:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288602#M81140</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2023-05-12T14:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288603#M81141</link>
      <description>&lt;P&gt;&amp;gt; Does this use the GPS compass heading or the device orientation?&amp;nbsp;&lt;/P&gt;&lt;P&gt;The widget just uses the heading value.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 15:01:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288603#M81141</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2023-05-12T15:01:57Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288694#M81144</link>
      <description>&lt;P&gt;Thanks. I did try this out today and it worked much better walking around in the field. I think for our particular use case, which is having users walk around viewing historical buildings, I would prefer to use the device heading as the person is not always going to be moving. I did get the arrow to rotate with the device heading by cloning the graphic as suggested below but could not figure out to remove and replace it correctly. The arrow always draws multiple times when there is a new GPS position. So I am not sure if I was calling the arrowGraphic.removeAll() in the wrong spot or adding it the wrong way.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
  &amp;lt;meta charset="utf-8"&amp;gt;
  &amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no"&amp;gt;
  &amp;lt;title&amp;gt;ArcGIS JS API - Track Widget Example&amp;lt;/title&amp;gt;
  &amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.26/esri/themes/light/main.css"&amp;gt;
  &amp;lt;script src="https://js.arcgis.com/4.26/"&amp;gt;&amp;lt;/script&amp;gt;

  &amp;lt;style&amp;gt;
    html, body, #viewDiv {
      margin: 0;
      padding: 0;
      height: 100%;
      width: 100%;
    }
  &amp;lt;/style&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
  &amp;lt;script&amp;gt;
    require([
      "esri/Map",
      "esri/views/MapView",
      "esri/widgets/Track",
      "esri/Graphic",
      "esri/symbols/SimpleLineSymbol",
      "esri/symbols/SimpleMarkerSymbol",
      "esri/symbols/SimpleFillSymbol",
      "esri/geometry/Point"
    ], function(Map, MapView, Track, Graphic, SimpleLineSymbol, SimpleMarkerSymbol, SimpleFillSymbol, Point) {

      // Create a new Map instance
      const map = new Map({
        basemap: "satellite"
      });

      // Create a new MapView instance
      const view = new MapView({
        container: "viewDiv",
        map: map,
        center: [-118.2437, 34.0522],
        zoom: 13
      });

  

const arrowSymbol = {
  type: "simple-marker",
  path: "M10,0 L20,30 L10,20 L0,30 Z",
  color: [0, 0, 255, 1],
  outline: {
    color: [0, 0, 0, 1],
    width: 1
  },
  size: 25
};


const arrowGraphic = new Graphic({
  symbol: arrowSymbol
});

const track = new Track({
  view: view,
  graphic: arrowGraphic,
  useHeadingEnabled: false
});


       // Add the Track widget to the view
  view.ui.add(track, "top-right");

  function onGeolocationSuccess(position) {
    console.log(position);

 let previousGraphic;

window.addEventListener("deviceorientation", (event) =&amp;gt; {
  // Get the updated heading from the device orientation event
  let heading = `${event.alpha}` * -1;

  // Remove the previous graphic from the view, if there is one
  if (previousGraphic) {
    view.graphics.remove(previousGraphic);
    //view.graphics.remove(arrowGraphic);
  }
  
  // Clone the original graphic and update its symbol angle with the heading
  const newGraphic = arrowGraphic.clone();
  view.graphics.removeAll();

  newGraphic.symbol.angle = heading;

  // Add the new graphic to the view and store it as the previous graphic
  view.graphics.add(newGraphic);
  previousGraphic = newGraphic;
});
}

function onGeolocationError(error) {
  console.error("Geolocation error: ", error);
}

const geolocationOptions = {
  enableHighAccuracy: true,
  maximumAge: 0,
  timeout: 50
};

if (navigator.geolocation) {
  navigator.geolocation.watchPosition(
    onGeolocationSuccess,
    onGeolocationError,
    geolocationOptions
  );
} else {
  console.error("Geolocation is not supported by this browser.");
}

    });   

    &amp;lt;/script&amp;gt;
  &amp;lt;/body&amp;gt;
  &amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 12 May 2023 18:17:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288694#M81144</guid>
      <dc:creator>BobCowling2</dc:creator>
      <dc:date>2023-05-12T18:17:12Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288773#M81150</link>
      <description>&lt;P&gt;&amp;gt; The arrow always draws multiple times when there is a new GPS position.&lt;/P&gt;&lt;P&gt;Two graphics makes sense. There is the Track widget's graphic being drawn, and you are also adding a graphic to the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#graphics" target="_self"&gt;View's graphic collection&lt;/A&gt;. Also, I'm fairly certain you can only set the Track widget's graphic property once, when the widget is first initialized.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 20:45:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288773#M81150</guid>
      <dc:creator>AndyGup</dc:creator>
      <dc:date>2023-05-12T20:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS JS 4 Rotate Graphic</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288776#M81151</link>
      <description>&lt;P&gt;Right, that makes sense. I am guessing I simply cannot rotate the track widget graphic, so the arrow should work as a separate graphic from the track widget one. Got it. Thanks for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2023 20:53:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/arcgis-js-4-rotate-graphic/m-p/1288776#M81151</guid>
      <dc:creator>BobCowling2</dc:creator>
      <dc:date>2023-05-12T20:53:51Z</dc:date>
    </item>
  </channel>
</rss>

