From b5f187b5567277e7aded2c9f171e69b4d0dcf32f Mon Sep 17 00:00:00 2001 From: Arno Kaimbacher Date: Wed, 7 Sep 2022 15:15:39 +0200 Subject: [PATCH] - add BasemapControl as typescript module --- .../{BasemapControl.js => BasemapControl.ts} | 56 +++++++++++++++---- src/js/controls/Control.ts | 2 +- webpack.config.js | 2 +- 3 files changed, 47 insertions(+), 13 deletions(-) rename src/js/controls/{BasemapControl.js => BasemapControl.ts} (71%) diff --git a/src/js/controls/BasemapControl.js b/src/js/controls/BasemapControl.ts similarity index 71% rename from src/js/controls/BasemapControl.js rename to src/js/controls/BasemapControl.ts index 600baf8..e5b4e00 100644 --- a/src/js/controls/BasemapControl.js +++ b/src/js/controls/BasemapControl.ts @@ -3,20 +3,42 @@ import { MobileDialog } from "./MobileDialog"; import * as dom from '../core/domUtil'; import * as util from '../core/utilities'; import * as domEvent from '../core/domEvent'; +import { Map } from "../core/Map"; import './BasemapControl.css'; +interface BasemapOptions { + title: string + position: string + width?: string + height?: string + parentDiv?: string +} + export class BasemapControl extends Control { - defaultTitle = '3DViewer'; + options: BasemapOptions = { + title: 'Default Title', + position: 'topleft', + width: '300px', + height: '100%', + parentDiv: undefined + }; + + // private _map: Map; + private _layersLink; + private dialog: MobileDialog + private basemaps: any; constructor(title, options) { - super(title, options); + // super(title, options); + super(); + this.options.title = title; util.setOptions(this, options); } - onAdd(map) { - let container = this._initLayout(map); + onAdd(map: Map): HTMLElement { + let container: HTMLElement = this._initLayout(); this._map = map; return container; } @@ -37,17 +59,22 @@ export class BasemapControl extends Control { let html = this._initBasemapHtml(basemaps.services); // domEvent.on(link, 'click', this.expand, this); - domEvent.on(link, 'click', domEvent.stopPropagation); - domEvent.on(link, 'mousedown', domEvent.stopPropagation); - domEvent.on(link, 'dblclick', domEvent.stopPropagation); - domEvent.on(link, 'click', domEvent.preventDefault); - domEvent.on(link, 'click', () => { - this.dialog.show(html); - }, this); + domEvent.on(this._layersLink, 'click', domEvent.stopPropagation); + domEvent.on(this._layersLink, 'mousedown', domEvent.stopPropagation); + domEvent.on(this._layersLink, 'dblclick', domEvent.stopPropagation); + domEvent.on(this._layersLink, 'click', domEvent.preventDefault); + // domEvent.on(link, 'click', this.showDialog(html), this); + domEvent.on(this._layersLink, 'click', () => { + this.showDialog(html); + }, this); return container; } + private showDialog(html) { + this.dialog.show(html); + } + _initBasemapHtml(basemapServices) { let buttonDiv = dom.createDom('div'); @@ -102,4 +129,11 @@ export class BasemapControl extends Control { } } + onRemove(): void { + domEvent.off(this._layersLink, 'click', this.showDialog); + //C.destroy(this.domNode); + //this.getContainer().parentNode.removeChild(this.getContainer()); + this._layersLink = null; + } + } \ No newline at end of file diff --git a/src/js/controls/Control.ts b/src/js/controls/Control.ts index ad925eb..d58ae0f 100644 --- a/src/js/controls/Control.ts +++ b/src/js/controls/Control.ts @@ -31,7 +31,7 @@ abstract class Control extends EventEmitter { abstract onRemove(map): void; - abstract onAdd(map) : HTMLElement; + abstract onAdd(map: any) : HTMLElement; addTo(map: Map): Control { this._map = map; diff --git a/webpack.config.js b/webpack.config.js index cf3b604..250615a 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -137,7 +137,7 @@ module.exports = (env, argv) => { colors: true, }, // devtool: (isProduction === true) ? 'hidden-source-map' : 'inline-source-map', - devtool: (isProduction === true) ? 'hidden-source-map' : 'eval', + devtool: (isProduction === true) ? 'hidden-source-map' : 'inline-source-map', optimization: { minimize: isProduction,