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

Add a check for undefined layer #10

Merged
merged 2 commits into from
Apr 21, 2017
Merged

Add a check for undefined layer #10

merged 2 commits into from
Apr 21, 2017

Conversation

amishas157
Copy link
Contributor

@amishas157 amishas157 commented Apr 18, 2017

Hi, I ran into following issue while using vt2geojson.

/Users/AmishaSingla/Documents/osm-compare/node_modules/@mapbox/vt2geojson/index.js:78
        for (var i = 0; i < layer.length; i++) {
                                 ^

TypeError: Cannot read property 'length' of undefined
    at /Users/AmishaSingla/Documents/osm-compare/node_modules/@mapbox/vt2geojson/index.js:78:34
    at Array.forEach (native)
    at readTile (/Users/AmishaSingla/Documents/osm-compare/node_modules/@mapbox/vt2geojson/index.js:76:12)
    at Request._callback (/Users/AmishaSingla/Documents/osm-compare/node_modules/@mapbox/vt2geojson/index.js:41:13)
    at Request.self.callback (/Users/AmishaSingla/Documents/osm-compare/node_modules/request/request.js:188:22)
    at emitTwo (events.js:87:13)
    at Request.emit (events.js:172:7)
    at Request.<anonymous> (/Users/AmishaSingla/Documents/osm-compare/node_modules/request/request.js:1171:10)
    at emitOne (events.js:77:13)
    at Request.emit (events.js:169:7)

Here is code snippet:

var retrieveTileData = function (x, y, z, callback) {
  var url = 'http://a.tiles.mapbox.com/v4/mapbox.mapbox-streets-v7/' + z + '/' + x + '/' + y + '.mvt?access_token=pk.eyJ1IjoiYW1pc2hhIiwiYSI6ImNpcWt1bWc4bjAzOXNmdG04bng4dHVhZ3EifQ.bJK6rpjNmiP3kW2pROdScg';
  vt2geojson({
    uri: url,
    layer: ['building', 'road', 'waterway']
  }, function (err, result) {
    if (err) return callback(err, null);
    return callback(null, result);
  });
};

Looked like the layer didn't exist for the waterway type features. This PR might help in resolving the issue.

cc @mapsam

@mapsam
Copy link
Contributor

mapsam commented Apr 18, 2017

@amishas157 great catch! Any interest in adding a test for this?

@amishas157
Copy link
Contributor Author

@mapsam , added the test here: e857da7

@mapsam
Copy link
Contributor

mapsam commented Apr 21, 2017

Marvelous, thanks so much @amishas157!

@mapsam mapsam merged commit bfe2446 into master Apr 21, 2017
@mapsam mapsam deleted the empty-layer-check branch April 21, 2017 16:35
@mapsam mapsam mentioned this pull request Apr 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants