Skip to content

Commit

Permalink
Prevent calls to getLayoutProperty from causing fatal error when laye…
Browse files Browse the repository at this point in the history
…r doesn't exist
  • Loading branch information
ryanhamley committed Nov 1, 2018
1 parent 922d7b3 commit d06a39a
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -786,12 +786,18 @@ class Style extends Evented {

/**
* Get a layout property's value from a given layer
* @param {string} layer the layer to inspect
* @param {string} layerId the layer to inspect
* @param {string} name the name of the layout property
* @returns {*} the property value
*/
getLayoutProperty(layer: string, name: string) {
return this.getLayer(layer).getLayoutProperty(name);
getLayoutProperty(layerId: string, name: string) {
const layer = this.getLayer(layerId);
if (!layer) {
this.fire(new ErrorEvent(new Error(`The layer '${layerId}' does not exist in the map's style.`)));
return;
}

return layer.getLayoutProperty(name);
}

setPaintProperty(layerId: string, name: string, value: any) {
Expand Down

0 comments on commit d06a39a

Please sign in to comment.