-
Notifications
You must be signed in to change notification settings - Fork 4
/
ol-map-part.ts
49 lines (40 loc) · 1.21 KB
/
ol-map-part.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { LitElement } from 'lit'
import Map from 'ol/Map'
import BaseObject from 'ol/Object'
import AttachableMixin from './mixins/Attachable'
import OlMap from './ol-map'
import { forwardEvents } from './lib/events'
/**
* Abstract base class used to create map objects such as layers and interactions
*
* @appliesMixin AttachableMixin
*/
export abstract class OlMapPart<T extends BaseObject> extends AttachableMixin(LitElement, 'map') {
/**
* Called when adding layers to the map.
* Implement to create the OpenLayers object
*
* @abstract
* @returns {Promise<T>}
*/
public abstract createPart(): Promise<T>
public _map: OlMap
protected get _forwardedEvents(): string[] {
return []
}
protected abstract _addToMap(map: Map, part: T): void
protected abstract _removeFromMap(map: Map, part: T): void
protected async _attach({ map }: { map: OlMap }): Promise<(() => void) | null> {
if (map) {
this._map = await map
const olMap = this._map.map!
const part = await this.createPart()
this._addToMap(olMap, part)
forwardEvents(this._forwardedEvents, this, part)
return () => {
this._removeFromMap(olMap, part)
}
}
return null
}
}