Guard PluggableMap against null renderer

This commit is contained in:
EvertEt
2022-03-02 12:05:38 +01:00
parent 4eb2acfbbb
commit 17033e162d
+9 -6
View File
@@ -391,7 +391,7 @@ class PluggableMap extends BaseObject {
this.overlayIdIndex_ = {}; this.overlayIdIndex_ = {};
/** /**
* @type {import("./renderer/Map.js").default} * @type {import("./renderer/Map.js").default|null}
* @private * @private
*/ */
this.renderer_ = null; this.renderer_ = null;
@@ -622,7 +622,7 @@ class PluggableMap extends BaseObject {
* @api * @api
*/ */
forEachFeatureAtPixel(pixel, callback, opt_options) { forEachFeatureAtPixel(pixel, callback, opt_options) {
if (!this.frameState_) { if (!this.frameState_ || !this.renderer_) {
return; return;
} }
const coordinate = this.getCoordinateFromPixelInternal(pixel); const coordinate = this.getCoordinateFromPixelInternal(pixel);
@@ -713,7 +713,7 @@ class PluggableMap extends BaseObject {
* @deprecated * @deprecated
*/ */
forEachLayerAtPixel(pixel, callback, opt_options) { forEachLayerAtPixel(pixel, callback, opt_options) {
if (!this.frameState_) { if (!this.frameState_ || !this.renderer_) {
return; return;
} }
const options = opt_options || {}; const options = opt_options || {};
@@ -738,7 +738,7 @@ class PluggableMap extends BaseObject {
* @api * @api
*/ */
hasFeatureAtPixel(pixel, opt_options) { hasFeatureAtPixel(pixel, opt_options) {
if (!this.frameState_) { if (!this.frameState_ || !this.renderer_) {
return false; return false;
} }
const coordinate = this.getCoordinateFromPixelInternal(pixel); const coordinate = this.getCoordinateFromPixelInternal(pixel);
@@ -1003,7 +1003,7 @@ class PluggableMap extends BaseObject {
/** /**
* Get the map renderer. * Get the map renderer.
* @return {import("./renderer/Map.js").default} Renderer * @return {import("./renderer/Map.js").default|null} Renderer
*/ */
getRenderer() { getRenderer() {
return this.renderer_; return this.renderer_;
@@ -1189,6 +1189,7 @@ class PluggableMap extends BaseObject {
if ( if (
frameState && frameState &&
this.renderer_ &&
this.hasListener(RenderEventType.RENDERCOMPLETE) && this.hasListener(RenderEventType.RENDERCOMPLETE) &&
!frameState.animate && !frameState.animate &&
this.renderComplete_ this.renderComplete_
@@ -1529,7 +1530,9 @@ class PluggableMap extends BaseObject {
} }
this.frameState_ = frameState; this.frameState_ = frameState;
this.renderer_.renderFrame(frameState); /** @type {import("./renderer/Map.js").default} */ (
this.renderer_
).renderFrame(frameState);
if (frameState) { if (frameState) {
if (frameState.animate) { if (frameState.animate) {