<?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: Migrate an application that uses the D3.js library, from API JS for ArcGIS 3 to API JS  for ArcGIS 4 in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/migrate-an-application-that-uses-the-d3-js-library/m-p/1300340#M81425</link>
    <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Thanks Rene&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;&lt;SPAN class=""&gt;for your answer, it is important for me to work with D3.js,&amp;nbsp;because I am using solutions based on D3.js version 3. is there a way?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jun 2023 18:14:38 GMT</pubDate>
    <dc:creator>Med-Karim-Rouissi</dc:creator>
    <dc:date>2023-06-16T18:14:38Z</dc:date>
    <item>
      <title>Migrate an application that uses the D3.js library, from API JS for ArcGIS 3 to API JS  for ArcGIS 4</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/migrate-an-application-that-uses-the-d3-js-library/m-p/1300322#M81423</link>
      <description>&lt;P&gt;I am trying to migrate this application which uses the API&amp;nbsp;JS for ArcGIS 3 and the D3.js library, to the API JS for ArcGIS 4 version, the code is retrieved from Github (&lt;A href="https://github.com/chelm/esri-d3" target="_blank"&gt;https://github.com/chelm/esri-d3&lt;/A&gt;),&lt;BR /&gt;I run into this error:&lt;BR /&gt;"Uncaught TypeError: Cannot read properties of undefined (reading 'properties')", apparently it can't read "new d3Layer" on the main code.&lt;BR /&gt;If anyone has an idea on a solution or a suggestion, I thank him in advance.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Here is the code for the main file:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;&amp;lt;!doctype html&amp;gt;
&amp;lt;html lang="en"&amp;gt;
&amp;lt;head&amp;gt;
&amp;lt;meta charset="utf-8"&amp;gt;
&amp;lt;meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" /&amp;gt;
&amp;lt;meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/&amp;gt;
&amp;lt;title&amp;gt;Esri &lt;span class="lia-unicode-emoji" title=":red_heart:"&gt;❤️&lt;/span&gt; d3js&amp;lt;/title&amp;gt;
&amp;lt;link rel="stylesheet" href="https://js.arcgis.com/4.11/esri/themes/light/main.css"&amp;gt;
&amp;lt;style type="text/css"&amp;gt;
html, body {
height: 100%; width: 100%;
margin: 0; padding: 0;
}
body{
background-color: #fff; overflow:hidden;
font-family: sans-serif;
}
path {
fill: #08c;
stroke: #fff;
stroke-width:1.5px;
opacity: 0.5;
}
path#Arizona {
fill: #FF0;
}
path#Colorado {
fill: #F49;
}
#map {
position:absolute;
width: 100%;
height: 100%;
}
&amp;lt;/style&amp;gt;
&amp;lt;script&amp;gt;
var dojoConfig = {
parseOnLoad: true,
packages: [{
"name": "modules",
"location": location.origin + location.pathname.replace(/\/[^/]+$/, '')
}]
};
&amp;lt;/script&amp;gt;
&amp;lt;script src="https://js.arcgis.com/4.11/"&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script&amp;gt;

require([
"esri/Map",
"esri/views/MapView",
"modules/d3Layer",
"dojo/parser",
"dojo/domReady!"
], function(
Map,
MapView,
d3Layer,
parser) {

parser.parse();

var map = new Map({
basemap: "gray"
});

var view = new MapView({
container: "map",
map: map,
center: [-98, 39],
zoom: 4
});
console.log("d3Layer", d3Layer);
layer = new d3Layer('us-states.json', {
styles: [
//{ key: 'fill', value: '#555'}
],
attrs: [{
key: 'id',
value: function(d) {
return d.properties.name;
}
}]
});
console.log("layer", layer);
map.addLayer(layer);
});
&amp;lt;/script&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;div id="map"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;Here is the code for d3Layer.js:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;define([
    "dojo/_base/declare",
    "dojo/_base/lang",
    "dojo/_base/array",
    "dojo/on",
    "esri/geometry/Point",
    "esri/geometry/support/webMercatorUtils",
    "esri/layers/GraphicsLayer",
    "https://d3js.org/d3.v3.min.js"
  ],
  function(
    declare,
    lang,
    array,
    on,
    Point,
    webMercatorUtils,
    GraphicsLayer,
    d3) {

    var d3Layer = declare("d3Layer", [GraphicsLayer], {

      constructor: function(url, options) {
        var self = this;
        this.url = url;
        this.type = options.type || 'path';
        this.selector = this.type;

        if (options.projection) this._project = options.projection;

        this._styles = options.styles || [];
        this._attrs = options.attrs || [];
        this._events = options.events || [];

        this._path = options.path || d3.geo.path();
        this.path = this._path.projection(lang.hitch(this, self._project));
      },

      _load: function() {
        var self = this;
        d3.json(self.url, function(geojson) {
          self.geojson = geojson;
          self.bounds = d3.geo.bounds(self.geojson);
          self.loaded = true;
          self._render();
          self.onLoad(self);
        });
      },

      //called once the layer's been added to the map
      _setMap: function(map, surface) {
        this._load();

        this._zoomEnd = map.on("zoom-end", lang.hitch(this, function() {
          this._reset();
        }));
        return this.inherited(arguments);
      },

      _unsetMap: function() {
        this.inherited(arguments);
        this._zoomEnd.remove();
      },

      _project: function(x) {
        var p = new Point(x[0], x[1]);
        var point = this._map.toScreen(webMercatorUtils.geographicToWebMercator(p))
        return [point.x, point.y];
      },

      _render: function() {
        var self = this;
        var p = this._paths();
        if (this.type == 'circle') {

          p.data(this.geojson.features)
            .enter().append(this.type)
            .attr("cx", function(d, i) {
              return self._project(d.geometry.coordinates)[0];
            })
            .attr("cy", function(d, i) {
              return self._project(d.geometry.coordinates)[1];
            })
            .attr('r', 10)
            .on('click', function(d) {
              self.select(d, this)
            })
            .on('mouseover', function(d) {
              self.hover(d, this);
            })
            .on('mouseout', function(d) {
              self.exit(d, this);
            });
        } else {

          p.data(this.geojson.features)
            .enter().append(this.type)
            .attr('d', this.path);
        }

        this._styles.forEach(function(s, i) {
          self.style(s);
        });

        this._attrs.forEach(function(s, i) {
          self.attr(s);
        });

        this._events.forEach(function(s, i) {
          self.event(s);
        });

        // assign a class to each feature element that is the ID of the layer
        // this makes it possible to select all primary features, and have secondary ones
        this._paths().attr('class', function(d, el) {
          return d3.select(this).attr('class') + " " + self.id;
        });

        // selector needs to respect the layer id classname we just gave each element
        this.selector += "." + this.id;
      },

      style: function(s) {
        this._paths().style(s.key, s.value);
      },

      attr: function(a) {
        /* at, 3.9+, this method fires with 'data-suspended' as the sole argument before the graphics have drawn for the first time

        it seems like it would be sufficient to check layer.suspended, but it is returning false

        https://developers.arcgis.com/javascript/jsapi/layer-amd.html#suspended
        */
        if (a != "data-suspended" || this.suspended) {
          this._paths().attr(a.key, a.value);
        }

        return this.inherited(arguments);
      },

      event: function(e) {
        this._paths().on(e.type, e.fn);
      },

      _reset: function() {
        var self = this;
        if (this.type == 'circle') {
          this._paths()
            .attr("cx", function(d, i) {
              return self._project(d.geometry.coordinates)[0];
            })
            .attr("cy", function(d, i) {
              return self._project(d.geometry.coordinates)[1];
            })
        } else {
          this._paths().attr('d', this.path)
        }
      },

      _element: function() {
        return d3.select("g#" + this.id + "_layer");
      },

      _paths: function(selector) {
        return this._element().selectAll(selector || this.selector);
      },

      hover: function() {},
      exit: function() {},
      select: function() {}
    });
    return d3Layer;
  });&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 17:41:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/migrate-an-application-that-uses-the-d3-js-library/m-p/1300322#M81423</guid>
      <dc:creator>Med-Karim-Rouissi</dc:creator>
      <dc:date>2023-06-16T17:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate an application that uses the D3.js library, from API JS for ArcGIS 3 to API JS  for ArcGIS 4</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/migrate-an-application-that-uses-the-d3-js-library/m-p/1300333#M81424</link>
      <description>&lt;P&gt;That d3Layer is written for a very old version of the 3x JavaScript library. It would need to be rewritten for 4x without all the dojo modules. As far as I know, no one has undertaken this task. If you are interested, you can look at this Custom WebGL LayerView sample that shows how to extend a GraphicsLayer to create the custom LayerView.&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/javascript/latest/sample-code/custom-gl-visuals/" target="_blank"&gt;https://developers.arcgis.com/javascript/latest/sample-code/custom-gl-visuals/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 18:02:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/migrate-an-application-that-uses-the-d3-js-library/m-p/1300333#M81424</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2023-06-16T18:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: Migrate an application that uses the D3.js library, from API JS for ArcGIS 3 to API JS  for ArcGIS 4</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/migrate-an-application-that-uses-the-d3-js-library/m-p/1300340#M81425</link>
      <description>&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;Thanks Rene&lt;/SPAN&gt;&lt;/SPAN&gt; &lt;SPAN class=""&gt;&lt;SPAN class=""&gt;for your answer, it is important for me to work with D3.js,&amp;nbsp;because I am using solutions based on D3.js version 3. is there a way?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 18:14:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/migrate-an-application-that-uses-the-d3-js-library/m-p/1300340#M81425</guid>
      <dc:creator>Med-Karim-Rouissi</dc:creator>
      <dc:date>2023-06-16T18:14:38Z</dc:date>
    </item>
  </channel>
</rss>

