Listen to label cache again when we have a target
This commit is contained in:
@@ -301,6 +301,11 @@ class PluggableMap extends BaseObject {
|
|||||||
*/
|
*/
|
||||||
this.interactions = optionsInternal.interactions || new Collection();
|
this.interactions = optionsInternal.interactions || new Collection();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {import("./events/Target.js").default}
|
||||||
|
*/
|
||||||
|
this.labelCache_ = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {import("./events.js").EventsKey}
|
* @type {import("./events.js").EventsKey}
|
||||||
*/
|
*/
|
||||||
@@ -512,20 +517,31 @@ class PluggableMap extends BaseObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach a label cache for listening to font changes.
|
* Attach a label cache and listen to font changes. Called by the renderer.
|
||||||
* @param {import("./events/Target.js").default} labelCache Label cache.
|
* @param {import("./events/Target.js").default} labelCache Label cache.
|
||||||
*/
|
*/
|
||||||
attachLabelCache(labelCache) {
|
attachLabelCache(labelCache) {
|
||||||
this.detachLabelCache();
|
this.unlistenLabelCache_();
|
||||||
this.labelCacheListenerKey_ = listen(labelCache, EventType.CLEAR, this.redrawText.bind(this));
|
this.labelCache_ = labelCache;
|
||||||
|
this.listenLabelCache_();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detach the label cache, i.e. no longer listen to font changes.
|
* Listen to font changes.
|
||||||
|
* @private
|
||||||
*/
|
*/
|
||||||
detachLabelCache() {
|
listenLabelCache_() {
|
||||||
|
this.labelCacheListenerKey_ = listen(this.labelCache_, EventType.CLEAR, this.redrawText.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* No longer listen to font changes.
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
unlistenLabelCache_() {
|
||||||
if (this.labelCacheListenerKey_) {
|
if (this.labelCacheListenerKey_) {
|
||||||
unlistenByKey(this.labelCacheListenerKey_);
|
unlistenByKey(this.labelCacheListenerKey_);
|
||||||
|
delete this.labelCacheListenerKey_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1045,7 +1061,7 @@ class PluggableMap extends BaseObject {
|
|||||||
removeEventListener(EventType.RESIZE, this.handleResize_, false);
|
removeEventListener(EventType.RESIZE, this.handleResize_, false);
|
||||||
this.handleResize_ = undefined;
|
this.handleResize_ = undefined;
|
||||||
}
|
}
|
||||||
this.detachLabelCache();
|
this.unlistenLabelCache_();
|
||||||
} else {
|
} else {
|
||||||
targetElement.appendChild(this.viewport_);
|
targetElement.appendChild(this.viewport_);
|
||||||
|
|
||||||
@@ -1060,6 +1076,7 @@ class PluggableMap extends BaseObject {
|
|||||||
this.handleResize_ = this.updateSize.bind(this);
|
this.handleResize_ = this.updateSize.bind(this);
|
||||||
window.addEventListener(EventType.RESIZE, this.handleResize_, false);
|
window.addEventListener(EventType.RESIZE, this.handleResize_, false);
|
||||||
}
|
}
|
||||||
|
this.listenLabelCache_();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.updateSize();
|
this.updateSize();
|
||||||
|
|||||||
Reference in New Issue
Block a user