From eb49a6b26de568d17257f333838536d1697e5c6c Mon Sep 17 00:00:00 2001 From: Ricky Brundritt Date: Fri, 9 Oct 2020 12:28:50 -0700 Subject: [PATCH] Minor updates --- README.md | 11 +--------- src/extensions/EventManager.ts | 4 ++-- src/helpers/ControlStyler.ts | 38 +++++++++++++++++++++++++--------- typings/index.d.ts | 4 ++-- 4 files changed, 33 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index e04930e..5bda224 100644 --- a/README.md +++ b/README.md @@ -51,16 +51,7 @@ Check out the [documentation](https://github.com/Azure-Samples/azure-maps-select ## Related Projects -**Open Azure Maps Web SDK modules** - -* [Azure Maps Animation module](https://github.com/Azure-Samples/azure-maps-animations) -* [Azure Maps Geolocation Control module](https://github.com/Azure-Samples/azure-maps-geolocation-control) -* [Azure Maps Fullscreen Control module](https://github.com/Azure-Samples/azure-maps-fullscreen-control) -* [Azure Maps Sync Map module](https://github.com/Azure-Samples/azure-maps-sync-maps) -* [Azure Maps Services UI module](https://github.com/Azure-Samples/azure-maps-services-ui) - -**Additional projects** - +* [Azure Maps Web SDK Open modules](https://github.com/microsoft/Maps/blob/master/AzureMaps.md#open-web-sdk-modules) - A collection of open source modules that extend the Azure Maps Web SDK. * [Azure Maps Web SDK Samples](https://github.com/Azure-Samples/AzureMapsCodeSamples) * [Azure Maps Gov Cloud Web SDK Samples](https://github.com/Azure-Samples/AzureMapsGovCloudCodeSamples) * [Azure Maps & Azure Active Directory Samples](https://github.com/Azure-Samples/Azure-Maps-AzureAD-Samples) diff --git a/src/extensions/EventManager.ts b/src/extensions/EventManager.ts index b07f06a..4d98d16 100644 --- a/src/extensions/EventManager.ts +++ b/src/extensions/EventManager.ts @@ -21,7 +21,7 @@ declare module "azure-maps-control" { * @param target The class to add the event for. * @param callback The event handler callback. */ - add(eventType: "dataselected", target: SelectionControl, callback: (e: SelectionControlEvents) => void): void; + add(eventType: "dataselected", target: SelectionControl, callback: (e: azmaps.Shape[]) => void): void; /** * Adds an event to a class once. @@ -29,7 +29,7 @@ declare module "azure-maps-control" { * @param target The class to add the event for. * @param callback The event handler callback. */ - addOnce(eventType: "dataselected", target: SelectionControl, callback: (e: SelectionControlEvents) => void): void; + addOnce(eventType: "dataselected", target: SelectionControl, callback: (e: azmaps.Shape[]) => void): void; /** * Adds an event to a class. diff --git a/src/helpers/ControlStyler.ts b/src/helpers/ControlStyler.ts index dbd33c9..6bc7161 100644 --- a/src/helpers/ControlStyler.ts +++ b/src/helpers/ControlStyler.ts @@ -3,7 +3,7 @@ import { Utils } from '../helpers/Utils'; /** A class that manages the style of a control. Add's 'light' or 'dark' as a CSS class to the container. */ export class ControlStyler { - /**************************** + /**************************** * Private Properties ***************************/ @@ -24,15 +24,7 @@ export class ControlStyler { constructor(container: HTMLElement, map: azmaps.Map, style: string) { this._container = container; this._map = map; - this._style = style; - - // Set the style or add the auto listener. - if (style.toLowerCase() === azmaps.ControlStyle.auto) { - this._onStyleChange(); - this._map.events.add('styledata', this._onStyleChange); - } else { - container.classList.add(style); - } + this.setStyle(style); } /**************************** @@ -69,6 +61,32 @@ export class ControlStyler { } } + /** + * Sets the style. + * @param style The new style. + */ + public setStyle(style: string) { + const self = this; + + if(style !== self._style){ + self._container.classList.remove(style); + + if(self._style === azmaps.ControlStyle.auto){ + self._map.events.remove('styledata', self._onStyleChange); + } + + // Set the style or add the auto listener. + if (style.toLowerCase() === azmaps.ControlStyle.auto) { + self._onStyleChange(); + self._map.events.add('styledata', self._onStyleChange); + } else { + self._container.classList.add(style); + } + + self._style = style; + } + } + /**************************** * Private Methods ***************************/ diff --git a/typings/index.d.ts b/typings/index.d.ts index f6e8aad..994adf5 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -271,7 +271,7 @@ declare module "azure-maps-control" { * @param target The class to add the event for. * @param callback The event handler callback. */ - add(eventType: "dataselected", target: atlas.control.SelectionControl, callback: (e: atlas.control.SelectionControlEvents) => void): void; + add(eventType: "dataselected", target: atlas.control.SelectionControl, callback: (e: azmaps.Shape[]) => void): void; /** * Adds an event to a class once. @@ -279,7 +279,7 @@ declare module "azure-maps-control" { * @param target The class to add the event for. * @param callback The event handler callback. */ - addOnce(eventType: "dataselected", target: atlas.control.SelectionControl, callback: (e: atlas.control.SelectionControlEvents) => void): void; + addOnce(eventType: "dataselected", target: atlas.control.SelectionControl, callback: (e: azmaps.Shape[]) => void): void; /** * Adds an event to a class.