<?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: Alternative of 2d canvas getContext('2d')  and getImageData() in webgl2 canvas? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/alternative-of-2d-canvas-getcontext-2d-and/m-p/1543890#M85787</link>
    <description>&lt;P&gt;Have you looked into the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#takeScreenshot" target="_self"&gt;takeScreenshot&lt;/A&gt; method of the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html" target="_self"&gt;MapView&lt;/A&gt; module?&amp;nbsp; Perhaps that's the missing piece you're looking for.&lt;/P&gt;</description>
    <pubDate>Mon, 30 Sep 2024 17:19:07 GMT</pubDate>
    <dc:creator>JoelBennett</dc:creator>
    <dc:date>2024-09-30T17:19:07Z</dc:date>
    <item>
      <title>Alternative of 2d canvas getContext('2d')  and getImageData() in webgl2 canvas?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/alternative-of-2d-canvas-getcontext-2d-and/m-p/1543785#M85786</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm migrating a web mapping application from ESRI Javascript API v3 to ArcGIS Maps SDK v4. In the v3 code, I used getContext('2d') to get access to the canvas and getImageData() to get the pixel data (color RGB on a particular spot on the map).&lt;/P&gt;&lt;P&gt;With Maps SDK, it seems the map is drawn on a webgl2 canvas and getContext('2d') returns null. I tried getContext('webgl2', {preserveDrawingBuffer: true}) and readPixels() but it returns an empty array. So, I can't get the pixel data. It seems there is a way to preserve the drawing buffer of webgl2 canvas but I don't think it's possible because how to create a canvas is totally up to Maps SDK and I can't modify it.&lt;/P&gt;&lt;P&gt;So, my questions are:&lt;/P&gt;&lt;P&gt;- Is there a way to make readPixels() return useful information so I can get the color RGB of the pixel?&lt;/P&gt;&lt;P&gt;- Is there a way to force Maps SDK to use 2d canvas instead of webgl2 or setup the webgl canvas with drawing buffer on?&lt;/P&gt;&lt;P&gt;- Is there workaround to get the pixel color RGB?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Background: my application visualizes a mosaic dataset as an ImageryLayer and map services as MapImageLayers from our own ArcGIS Server and I want to allow users to get the color information in RGB when they mouse-over the map (layers). So, it's not "Identify". I use pixelFilter to render ImageryLayer. So, I know I can get the pixel data. But what I want to achieve is to get the pixel color upon a user action on both ImageryLayer and MapImageLayers.&lt;/P&gt;&lt;P&gt;And below is a simplified working code for the v3 application.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var x = evt.screenPoint.x;
var y = evt.screenPoint.y;
var canvasDiv = Ext.get(divId);
var canvasDom = canvasDiv.child("canvas", true);
var c2d = canvasDom.getContext('2d');
var pixelData = c2d.getImageData(x, y, 1, 1).data;
var rgb = {r: pixelData[0], g: pixelData[1], b: pixelData[2]};
// And show rgb in a popup.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 13:56:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/alternative-of-2d-canvas-getcontext-2d-and/m-p/1543785#M85786</guid>
      <dc:creator>efujioka</dc:creator>
      <dc:date>2024-09-30T13:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative of 2d canvas getContext('2d')  and getImageData() in webgl2 canvas?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/alternative-of-2d-canvas-getcontext-2d-and/m-p/1543890#M85787</link>
      <description>&lt;P&gt;Have you looked into the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html#takeScreenshot" target="_self"&gt;takeScreenshot&lt;/A&gt; method of the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html" target="_self"&gt;MapView&lt;/A&gt; module?&amp;nbsp; Perhaps that's the missing piece you're looking for.&lt;/P&gt;</description>
      <pubDate>Mon, 30 Sep 2024 17:19:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/alternative-of-2d-canvas-getcontext-2d-and/m-p/1543890#M85787</guid>
      <dc:creator>JoelBennett</dc:creator>
      <dc:date>2024-09-30T17:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative of 2d canvas getContext('2d')  and getImageData() in webgl2 canvas?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/alternative-of-2d-canvas-getcontext-2d-and/m-p/1544397#M85798</link>
      <description>&lt;P&gt;That sounds promising! Thanks for the tip. I will call takeScreenshot whenever the layer view is updated and paste it into a hidden canvas. That way, I can call getImageData.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2024 16:56:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/alternative-of-2d-canvas-getcontext-2d-and/m-p/1544397#M85798</guid>
      <dc:creator>efujioka</dc:creator>
      <dc:date>2024-10-01T16:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Alternative of 2d canvas getContext('2d')  and getImageData() in webgl2 canvas?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/alternative-of-2d-canvas-getcontext-2d-and/m-p/1545350#M85814</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/516105"&gt;@efujioka&lt;/a&gt;! We should be returning the image data already in the takeScreenshot() result, so unless you're doing something extra I don't think you'd need to use a hidden canvas. I put together a codepen here in case it's helpful:&amp;nbsp;&lt;A href="https://codepen.io/sam11948/pen/BaXKwGQ?editors=1000" target="_blank"&gt;https://codepen.io/sam11948/pen/BaXKwGQ?editors=1000&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2024 19:08:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/alternative-of-2d-canvas-getcontext-2d-and/m-p/1545350#M85814</guid>
      <dc:creator>SamEngel</dc:creator>
      <dc:date>2024-10-03T19:08:47Z</dc:date>
    </item>
  </channel>
</rss>

