tangrams / tangram

WebGL map rendering engine for creative cartography
https://tangram.city
MIT License
2.22k stars 290 forks source link

skip empty layers #747

Closed meetar closed 4 years ago

meetar commented 4 years ago

This PR addresses errors thrown in an edge case, when an untiled data source is drawn with the all_layers flag set:

sources:
    untiled:
        type: GeoJSON
        url: geometry.json

layers:
    water:
        data: { source: untiled, all_layers: true }

In this case, errors will be thrown, once per worker per tile, if the bounds of the geometry do not intersect the tile, even if bounds is set on the datasource:

log.js:50 Tangram v0.20.0 [error]: tile load error for tilezen/16/16/5/6: TypeError: Cannot read property 'features' of undefined
    at Function.getDataForSource (blob:http://localhost:8000/7f727039-252b-43cc-8df8-bbb96e936b31:17445:41)
    at Function.buildGeometry (blob:http://localhost:8000/7f727039-252b-43cc-8df8-bbb96e936b31:17261:32)
    at blob:http://localhost:8000/7f727039-252b-43cc-8df8-bbb96e936b31:20765:26
log @ log.js:50
WorkerBrokerMainThreadHandler @ worker_broker.js:236
log.js:47 Tangram v0.20.0 [error]: Error building tile tilezen/16/16/5/6: TypeError: Cannot read property 'features' of undefined
    at Function.getDataForSource (blob:http://localhost:8000/7f727039-252b-43cc-8df8-bbb96e936b31:17445:41)
    at Function.buildGeometry (blob:http://localhost:8000/7f727039-252b-43cc-8df8-bbb96e936b31:17261:32)
    at blob:http://localhost:8000/7f727039-252b-43cc-8df8-bbb96e936b31:20765:26
log @ log.js:47

This PR checks for undefined data within a given layer in a given tile when the all_layers flag is set, and replaces the errors with a warning. There may well be a better way to handle this :D

bcamper commented 4 years ago

Thanks for finding this case. It turns out we can do this just by removing the checks for layer and feature presence, because the code calling this is already setup to handle a null/undefined value for geom. This also made me realize we can remove similar checks when specifying multiple layers by name, further down in the function. So that's a win. 77b9edb2452d40ecd17a7e212e2a2a5889cebd75