1
import Map from "esri/Map";
import MapView from "esri/views/MapView";
import Graphic from "esri/Graphic";
import GraphicsLayer from "esri/layers/GraphicsLayer";
import webMercatorUtils from "esri/geometry/support/webMercatorUtils";


async function kewlClickHandler(event) {

    function initDrawLine();

        function initDrawLine(Map, MapView, Graphic, GraphicsLayer, webMercatorUtils) {

          const map = view.map;

          var graphicsLayer = new GraphicsLayer(); // here
          map.add(graphicsLayer);

          ...... etc

No matter how I arrange my function params and header module includes; I repeatedly get the following error with my initDrawLine function:

Uncaught (in promise) TypeError: GraphicsLayer is not a constructor

New to arcgis-js-api, any ideas?


Update: This is the context, no errors or issues within stand alone CodePen: in arcgis-js 4.13

But errors in actual environment in arcgis 4.11 - confusing.

0

var graphicsLayer = new GraphicsLayer(); <--- The error us being thrown from this line of code, because as the error is saying "GraphicsLayer is not a constructor." And in that line of code, you are trying to declare GraphicsLayer as a constructor once you put () after.

Below is how you need to declare a new GraphicsLayer:

new GraphicsLayer()

Creates a new GraphicsLayer object. (Added at v1.4)

Sample:

require([ "esri/layers/GraphicsLayer", ... ], function(GraphicsLayer, ... ) { var countyLayer = new GraphicsLayer(); ... });

  • Thanks for taking a look but confused with your answer: I am declaring 'new GraphicsLayer()' the same way you are in your sample – emilio estevez Jan 8 at 18:34
  • But is also has a require. I would try is exactly as it is above. Yes, there is a function, but it is all included inside the parens of the require. – enolan Jan 8 at 19:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.