Select to view content in your preferred language

Getting “isWebMercator” Error When Trying To Draw a Circle On Graphics Layer

1731
9
Jump to solution
10-24-2017 12:05 PM
BehrouzHosseini
Regular Contributor

can you please take a look at this snippet and let me know why I am getting this Error message

Uncaught TypeError: Cannot read property 'isWebMercator' of undefined

from the Circle.js module?

var graphicsLayerPoint = new esri.layers.GraphicsLayer();   
map.addLayer(graphicsLayerPoint);

var graphicsLayerCircle = new esri.layers.GraphicsLayer();   
map.addLayer(graphicsLayerCircle);


$("#btnAddJunctionFlag").on("click", function () {
        toolbar = new Draw(map);
        toolbar.activate(Draw.POINT);
        map.hideZoomSlider();
        toolbar.on("draw-end", addToMap);

        function addToMap(evt) {
        circle = new Circle({
            center: evt.mapPoint,
            geodesic: true,
            radius: .6,
            radiusUnit: "esriMiles"
        });
    }
    var cgraphic = new Graphic(circle, circleSymb);
    graphicsLayerCircle.add(cgraphic);

    var pgraphic = new Graphic(evt.geometry, config.symbolPointJFlag);
    graphicsLayerPoint.add(pgraphic);
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Bengi,

   Simple, it would look like this:

$("#btnAddJunctionFlag").on("click", function () {‍
  if(clickEvtHandler){
    clickEvtHandler.remove();
  }
  clickEvtHandler = map.on("click", function(evt){
    circle = new Circle({
      center: evt.mapPoint,
      geodesic: true,
      radius: .6,
      radiusUnit: "esriMiles"
    });

    var cgraphic = new Graphic(circle, circleSymb);
    graphicsLayerCircle.add(cgraphic);

    var pgraphic = new Graphic(evt.mapPoint, config.symbolPointJFlag);
    graphicsLayerPoint.add(pgraphic);
  });
}‍‍‍‍‍‍‍‍

Of course this would now work best using a dojo ToggleButton instead of a standard button:

dijit/form/ToggleButton — The Dojo Toolkit - Reference Guide 

View solution in original post

9 Replies
RobertScheitlin__GISP
MVP Emeritus

Bengi,

   I am not seeing why you are getting that error, but line 24 in your code does not make any sense.

0 Kudos
BehrouzHosseini
Regular Contributor

Thanks Rober,

it was a Typo there but what I am trying to do is Adding a Point into Map using Toolbar facility and also Drawing a Circle around it without using Toolbar Utility

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Bengi,

   Why are you trying to use the Draw toolbar and not just adding a map click event handler when the button is clicked and then in the handler add the circle as in this sample?

Create circles | ArcGIS API for JavaScript 3.22 

0 Kudos
BehrouzHosseini
Regular Contributor

You are right but in this case I need to also display the Point Graphic on map so as you can see I have two graphics layer

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Bengi,

   There will be no problem doing that if you create two different graphics (as a graphic can only exist in one parent layer at a time).

BehrouzHosseini
Regular Contributor

Thanks again but please do not forget the 

$("#btnAddJunctionFlag").on("click", function () {});

 I am actually calling (enabling) this Point creation functionality on calling a DOM (here # btnAddJunctionFlag) and as you know this is different than

map.on("click", function(evt){})

Here is the code in more details

 toolbar = new Draw(map);
 toolbar.activate(Draw.POINT);
 toolbar.on("draw-end", addToMap);

 function addToMap(evt) {
   circle = new Circle({
   center: evt.mapPoint,
   geodesic: true,
   radius: .6,
   radiusUnit: "esriMiles"
 });

    var cgraphic = new Graphic(circle, circleSymb);
    graphicsLayerCircle.add(cgraphic);

    var pgraphic = new Graphic(evt.geometry, config.symbolPointJFlag);
    graphicsLayerPoint.add(pgraphic);
}

Thanks and sorry for confusion

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Bengi,

   That is no problem. As mention in my previous reply you can just add the map on click handler inside the button click handler.

0 Kudos
BehrouzHosseini
Regular Contributor

Sorry Robert I got confused! so you are saying I can add Point to map without using Draw toolbar AND with using 

$("#btnAddJunctionFlag").on("click", function () {});

 can you please let me know how?

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

Bengi,

   Simple, it would look like this:

$("#btnAddJunctionFlag").on("click", function () {‍
  if(clickEvtHandler){
    clickEvtHandler.remove();
  }
  clickEvtHandler = map.on("click", function(evt){
    circle = new Circle({
      center: evt.mapPoint,
      geodesic: true,
      radius: .6,
      radiusUnit: "esriMiles"
    });

    var cgraphic = new Graphic(circle, circleSymb);
    graphicsLayerCircle.add(cgraphic);

    var pgraphic = new Graphic(evt.mapPoint, config.symbolPointJFlag);
    graphicsLayerPoint.add(pgraphic);
  });
}‍‍‍‍‍‍‍‍

Of course this would now work best using a dojo ToggleButton instead of a standard button:

dijit/form/ToggleButton — The Dojo Toolkit - Reference Guide