Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d3.geoBounds is not working #51

Closed
shrfarzk opened this issue Aug 1, 2016 · 2 comments
Closed

d3.geoBounds is not working #51

shrfarzk opened this issue Aug 1, 2016 · 2 comments
Assignees

Comments

@shrfarzk
Copy link

shrfarzk commented Aug 1, 2016

I stumbled upon an error while trying to use d3.geoBounds, and while trying to understand the cause of it I found something that is most likely a bug in area.js

Here's the part of the code I think is causing the error

export var areaRingSum;

var areaSum,
    lambda00,
    phi00,
    lambda0,
    cosPhi0,
    sinPhi0;

export var areaStream = {
  point: noop,
  lineStart: noop,
  lineEnd: noop,
  polygonStart: function() {
    areaRingSum.reset(); // <<< areaRingSum was never initialized
    areaStream.lineStart = areaRingStart;
    areaStream.lineEnd = areaRingEnd;
  },
  polygonEnd: function() {
    var areaRing = +areaRingSum;
    areaSum.add(areaRing < 0 ? tau + areaRing : areaRing);
    this.lineStart = this.lineEnd = this.point = noop;
  },
  sphere: function() {
    areaSum.add(tau);
  }
}

And here's the error

Cannot read property 'reset' of undefined
    at Object.areaStream.polygonStart (...\node_modules\d3-geo\build\d3-geo.js:169:18)
    at Object.boundsStream.polygonStart (...\node_modules\d3-geo\build\d3-geo.js:278:18)
    at streamPolygon (...\node_modules\d3-geo\build\d3-geo.js:143:12)
    at Object.streamGeometryType.MultiPolygon (...\node_modules\d3-geo\build\d3-geo.js:126:23)
    at streamGeometry (...\node_modules\d3-geo\build\d3-geo.js:88:40)
    at Object.streamObjectType.Feature (...node_modules\d3-geo\build\d3-geo.js:94:7)
    at geoStream (...\node_modules\d3-geo\build\d3-geo.js:150:36)
    at Object.bounds [as geoBounds] (...\node_modules\d3-geo\build\d3-geo.js:400:5)

I think it's worth noting that d3.geoCentroid and d3.geoLength all work on the same GeoJson object that causes the error when passed to d3.geoBounds

Also, d3.geoBounds returns [NaN, NaN] when a point is passed instead of a multipolygon, but I don't know the cause of this.

@mbostock mbostock self-assigned this Aug 1, 2016
@mbostock
Copy link
Member

mbostock commented Aug 1, 2016

Thanks for the report. I will look into it.

@mbostock
Copy link
Member

mbostock commented Aug 1, 2016

Also, d3.geoBounds returns [NaN, NaN] when a point is passed instead of a multipolygon, but I don't know the cause of this.

Works fine for me:

d3.geoBounds({type: "Point", coordinates: [-123, 39]}) // [[-123, 39], [-123, 39]]

Please file a separate issue if you can demonstrate a bug in computing the bounds of points.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants