JavaScript Buffer method gives TypeError b is undefined

2363
2
Jump to solution
04-18-2016 05:48 PM
MarkNorbury
Esri Contributor

I’m looking for some help with the buffer tool in the JavaScript API.  I have looked online but with no success.  I am getting a Latitude, a Longitude and a buffer distance from the user then attempting to buffer this point.  This is a custom widget that I'm creating in the Esri Web AppBuilder Developer Edition.

Here’s my code snippet.

var dblLat = domAttr.get(this.inputLat, 'value');

    var dblLong = domAttr.get(this.inputLong, 'value');

    if (dblLat =="" || dblLong =="" || isNaN(dblLat) || isNaN(dblLong)) {

     new Message({message: this.nls.notANumber});

     return;

    }

    if (this.pointLayer){

     //Remove old point layer from map.

     this.map.graphics.remove(this.pointLayer);

    }

    console.log("Placing point on the map.");

    this.ptLatLong = new Point(dblLong, dblLat);

    var pointSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10,

   new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,

   new Color([0,0,255]), 1),

   new Color([0,0,255]));

    this.pointLayer = new Graphic(this.ptLatLong, pointSymbol);

    //Add the point to the graphics layer.

    this.map.graphics.add(this.pointLayer);

var bufferDistance = this.txtBufferDistance.value;

var bufferedGeometry = geometryEngine.buffer(this.ptLatLong,bufferDistance,'meters',true);

This fails at the last line with:

TypeError: b is undefined

It seems to be a problem with the actual geometry, this.ptLatLong.  Elsewhere I have a similar line of code to buffer other geometries entered by the user and it works with no errors.  I've also tried geometryEngine.geodesicBuffer and this gives the same error.

Any help would be appreciated.  Thanks.

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Mark,

  You need to specify the points spatial reference when you create it so that geometryEngine.buffer knows what WKID it is dealing with. Actually I would use webMercatorUtils.geographicToWebMercator to make the point a webmercator point before you add it to the map.

View solution in original post

2 Replies
RobertScheitlin__GISP
MVP Emeritus

Mark,

  You need to specify the points spatial reference when you create it so that geometryEngine.buffer knows what WKID it is dealing with. Actually I would use webMercatorUtils.geographicToWebMercator to make the point a webmercator point before you add it to the map.

MarkNorbury
Esri Contributor

Thanks, Robert.  That is what I need.

Here's the line that I've amended in code, and it works now.

this.ptLatLong = webMercatorUtils.geographicToWebMercator(new Point(dblLong, dblLat));

0 Kudos