Skip to content

Commit

Permalink
fixed(editor): In exceptionally rare instances, timing issues could c…
Browse files Browse the repository at this point in the history
…ause inconsistent triggering of the 'ready' event.

Signed-off-by: Tim Deubler <tim.deubler@here.com>
  • Loading branch information
TerminalTim committed May 10, 2024
1 parent 4370c8d commit d9521e6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {Tile} from '../../tile/Tile';
import TileProvider from '../TileProvider/TileProvider';
import {TileLoadDelegator} from './TileLoadDelegator';
import {tileUtils} from '@here/xyz-maps-core';
import {add} from '@here/xyz-maps-common/src/Vec3';

let UNDEF;

Expand Down
10 changes: 5 additions & 5 deletions packages/display/src/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {Behavior, BehaviorOptions} from './behavior/Behavior';
import {EventDispatcher} from './event/Dispatcher';
import {Search} from './search/Search';
import {MapEvent} from './event/Event';
import MVCRecognizer from './MVCRecognizer';
import MapViewListener from './MapViewListener';
import UI from './ui/UI';
import {JSUtils, Listener} from '@here/xyz-maps-common';
import {ZoomAnimator} from './animation/ZoomAnimator';
Expand Down Expand Up @@ -130,7 +130,7 @@ export class Map {
_s: number = 1; // current scale

private _display: BasicDisplay;
private _mvcRecognizer: MVCRecognizer;
private _mvListener: MapViewListener;
private _rz: number = 0; // rotation z in rad
private _rx: number = 0; // rotation x in rad
private _z: number; // zoom level
Expand Down Expand Up @@ -265,7 +265,7 @@ export class Map {
options['renderOptions'] || {}
);

tigerMap._mvcRecognizer = new MVCRecognizer(tigerMap,
tigerMap._mvListener = new MapViewListener(tigerMap,
function triggerEventListeners(type, detail, sync) {
listeners.trigger(
type,
Expand Down Expand Up @@ -388,7 +388,7 @@ export class Map {
const centerGeo = this._c;
const prevCenterGeo = this._pc;

this._mvcRecognizer.watch(true);
this._mvListener.watch(true);

this._groundResolution = earthCircumference(centerGeo.latitude) / this._worldSizeFixed;

Expand Down Expand Up @@ -1558,7 +1558,7 @@ export class Map {

mapEl.parentNode.removeChild(mapEl);

this._mvcRecognizer.watch(false);
this._mvListener.watch(false);

this._evDispatcher.destroy();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const createEvent = (eventName: string, map, layer): Event => {
};


class MVCRecognizer {
class MapViewListener {
private readyTimer: number;
private watchTimer: number = null;
private viewport: GeoRect;
Expand Down Expand Up @@ -199,4 +199,4 @@ class MVCRecognizer {
};
}

export default MVCRecognizer;
export default MapViewListener;
7 changes: 3 additions & 4 deletions packages/editor/src/API/Editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,14 +749,13 @@ export default class Editor {
const lid = getIdentifier(prov);

if (prov.__type == 'FeatureProvider' && prov.editable && layerMap[lid]) {
delete layerMap[lid];
layers.splice(layers.indexOf(layer), 1);

iEditor.listeners.trigger('_layerRemove', {
layer: layer
});

delete layerMap[lid];

layers.splice(layers.indexOf(layer), 1);

toggleProviderHooks('remove', prov, iEditor);

delete prov._e;
Expand Down
7 changes: 6 additions & 1 deletion packages/editor/src/DisplayListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import {Set} from '@here/xyz-maps-common';
import InternalEditor from './IEditor';
import ObserverHandler from './handlers/ObserverHandler';

export default class DisplayListener {
// private layers = {};
Expand All @@ -27,7 +28,7 @@ export default class DisplayListener {

private busy: Set = null;

private observers: any;
private observers: ObserverHandler;

private iEdit;

Expand All @@ -51,6 +52,10 @@ export default class DisplayListener {

HERE_WIKI.listeners.add('_layerRemove', (ev) => {
ev.detail.layer.removeEventListener('viewportReady', this.onStop);
this.busy?.delete(ev.detail.layer);
if (!this.busy?.size && !this.iEdit.layers.length) {
this.observers.change('ready', true);
}
});
}

Expand Down

0 comments on commit d9521e6

Please sign in to comment.