[Maps] If tilemap source already exists, just sync style (#29620) (#29727)

* If source already exists, just sync tilemap style

* Review feedback
This commit is contained in:
Aaron Caldwell 2019-01-31 10:21:00 -07:00 committed by GitHub
parent bb7a67af24
commit 6ae764dbf9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -66,9 +66,11 @@ export class TileLayer extends AbstractLayer {
async syncLayerWithMB(mbMap) {
const source = mbMap.getSource(this.getId());
const layerId = this.getId() + '_raster';
const mbLayerId = this.getId() + '_raster';
if (source) {
// If source exists, just sync style
this._setTileLayerProperties(mbMap, mbLayerId);
return;
}
@ -82,7 +84,7 @@ export class TileLayer extends AbstractLayer {
});
mbMap.addLayer({
id: layerId,
id: mbLayerId,
type: 'raster',
source: sourceId,
minzoom: 0,
@ -90,13 +92,16 @@ export class TileLayer extends AbstractLayer {
});
await this._tileLoadErrorTracker(mbMap, url);
this._setTileLayerProperties(mbMap, mbLayerId);
}
mbMap.setLayoutProperty(layerId, 'visibility', this.isVisible() ? 'visible' : 'none');
mbMap.setLayerZoomRange(layerId, this._descriptor.minZoom, this._descriptor.maxZoom);
_setTileLayerProperties(mbMap, mbLayerId) {
mbMap.setLayoutProperty(mbLayerId, 'visibility', this.isVisible() ? 'visible' : 'none');
mbMap.setLayerZoomRange(mbLayerId, this._descriptor.minZoom, this._descriptor.maxZoom);
this._style && this._style.setMBPaintProperties({
alpha: this.getAlpha(),
mbMap,
layerId,
mbLayerId,
});
}