Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a couple of things that you could do to resolve this.</p> <p>Firstly, you could add your required dependency to the <code>define</code> array so you don't need to do an asynchronous require within the constructor of the class.</p> <p>That would look like:</p> <pre><code>define(["dojo/_base/declare", "esri/map", "esri/config", "esri/SpatialReference", "esri/geometry/Extent"], function (declare, Map, config, SpatialReference, Extent) { return declare(null, { action: "pan", activeMeasureTool: "", aerialLayer: "", legendLayers: "", loadedServices: "", popup: "", resizeId: 0, constructor: function () { this.init(); }, init: function () { //custom map requires a proxy to function properly. esri.config.defaults.io.proxyUrl = "../sdc_devdata/proxy.php"; var spatRef = new SpatialReference(2276); var startExtent = new Extent(2481416.32087491, 6963246.42495962, 2501196.36936991, 6980267.92469462, spatRef); var appFullExtent = new Extent(2396699.46935379, 6872369.60195443, 2607745.94404633, 7107335.22319087, spatRef); map = new Map("map", { extent: startExtent, isZoomSlider: true, logo: false, sliderStyle: "large" }); this.attachMapEventHandlers(); this.createLayers(); this.handleLayerVisibilityChange(); } }); }); </code></pre> <p>OR you could save the current scope of <code>this</code> to something in the closure when doing the require</p> <pre><code>init: function () { var that = this; require(["esri/map", "esri/config", "esri/SpatialReference", "esri/geometry/Extent"], function (Map, config, SpatialReference, Extent) { //custom map requires a proxy to function properly. esri.config.defaults.io.proxyUrl = "../sdc_devdata/proxy.php"; var spatRef = new SpatialReference(2276); var startExtent = new Extent(2481416.32087491, 6963246.42495962, 2501196.36936991, 6980267.92469462, spatRef); var appFullExtent = new Extent(2396699.46935379, 6872369.60195443, 2607745.94404633, 7107335.22319087, spatRef); map = new Map("map", { extent: startExtent, isZoomSlider: true, logo: false, sliderStyle: "large" }); that.attachMapEventHandlers(); that.createLayers(); that.handleLayerVisibilityChange(); }); }, </code></pre> <p>EDIT: your third option would be using lang.hitch, which lets you specify the scope of <code>this</code> in the the callback function. To use it, you would add <code>dojo/_base/lang</code> to you define() dependency list, and wrap the require callback in <code>lang.hitch(this, function(){});</code></p> <pre><code>define(["dojo/_base/declare", "dojo/_base/lang"], function (declare, lang) { return declare(null, { //... init: function () { require(["esri/map", "esri/config", "esri/SpatialReference", "esri/geometry/Extent"], lang.hitch(this, function (Map, config, SpatialReference, Extent) { //this now refers to the instance of the class })); } }); }); </code></pre> <p>I would strongly suggest going with the first option, since it is consistent with the entire use of AMD (declaring what dependencies a module needs before it executes, rather than loading it on the fly).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload