Description

Provides the base functionality for wrapper objects which wrap a native overlay object. Wrappers like GoogleMapsPolygon, GoogleMapsMarker etc. should extend this class.

Extends

GoogleMapsNativeObjectEmittingWrapper

Implements

IGoogleMapsDrawableOverlay

Index

overlays/abstraction/base/google-maps-drawable-overlay.ts

Properties
Methods

Constructor

constructor(type: OverlayType, map: IGoogleMap, api: GoogleMapsApiService, native: TNative)

Creates an instance of GoogleMapsDrawableOverlay.

⚠️ See GoogleMapsNativeObjectEmittingWrapper for docs on the native parameter's type. ⚠️

Parameters:
Name Type Optional Description
type OverlayType No

The type of overlay this wrapper holds. Used by the OverlayTracker to distinguish between types.

map IGoogleMap No

The map to which this overlay should be added.

api GoogleMapsApiService No

The instance of the low-level api.

native TNative No

The native overlay to wrap.

Properties

Public map
Type: IGoogleMap
The map to which this overlay should be added.
Public Readonly type
Type: OverlayType
The type of overlay this wrapper holds. Used by the `OverlayTracker` to distinguish between types.
Public custom
Type: any
Public Readonly native
Type: TNative
The instantiated native object to be wrapped.

Methods

Public attach
attach(map: IGoogleMap)

Assigns the overlay to the specified map. If possible, prefer using the appropriate GoogleMap.createXXX() method instead. If not possible, it is the responsability of the caller to add the overlay to the OverlayTracker in the GoogleMap.overlays object. Otherwise, inconsistencies and unexpected behaviours might occur.

Parameters:
Name Type Optional Description
map IGoogleMap No

The map to dispaly the overlay on.

Returns: void
Public detach
detach()

Removes the overlay from the map it is attached to. If possible, prefer using the GoogleMap.removeOverlay() method instead. If not possible, it is the responsability of the caller to remove the overlay from the OverlayTracker in the GoogleMap.overlays object. Otherwise, inconsistencies and unexpected behaviours might occur.

Returns: void
Public Abstract getBounds
getBounds()
Returns: google.maps.LatLngBounds
Public clearListeners
clearListeners()

Unregisters all handlers of any previously registered native event.

Returns: void
Public listenTo
listenTo(eventName: string, handleEvent: (args: any[]) => void)

Registers a handler to a specific event of the native object and takes care of executing the handler inside angular's zone.

Parameters:
Name Type Optional Description
eventName string No

The name of the native event to register the handler for.

handleEvent function No

The function to execute when the event is triggered by the native object.

Returns: void

An function for unregistering the handler from the event.

Public stopListeningTo
stopListeningTo(eventName: string)

Unregisters all handlers previously registered to handle a specific event.

Parameters:
Name Type Optional Description
eventName string No

The name of the native event for which to unregister all handlers.

Returns: void
Public setCustom
setCustom(custom: any)
Parameters:
Name Type Optional
custom any No
Returns: void
import { GoogleMapsNativeObjectEmittingWrapper, GoogleMapsApiService, IGoogleMap } from '@bespunky/angular-google-maps/core';
import { IGoogleMapsNativeDrawableOverlay } from '../native/i-google-maps-native-drawable-overlay';
import { IGoogleMapsDrawableOverlay       } from './i-google-maps-drawable-overlay';
import { OverlayType                      } from './overlay-type.enum';

/**
 * Provides the base functionality for wrapper objects which wrap a native overlay object. Wrappers like `GoogleMapsPolygon`, `GoogleMapsMarker` etc. should extend this class.
 *
 * @export
 * @abstract
 * @class GoogleMapsDrawableOverlay
 * @extends {GoogleMapsNativeObjectEmittingWrapper<TNative>}
 * @implements {IGoogleMapsDrawableOverlay<TNative>}
 * @template TNative The type of drawable overlay being wrapped.
 */
export abstract class GoogleMapsDrawableOverlay<TNative extends IGoogleMapsNativeDrawableOverlay>
                extends GoogleMapsNativeObjectEmittingWrapper<TNative>
                implements IGoogleMapsDrawableOverlay<TNative>
{
    /**
     * Creates an instance of GoogleMapsDrawableOverlay.
     * 
     * ⚠️ See {@link GoogleMapsNativeObjectEmittingWrapper} for docs on the `native` parameter's type. ⚠️
     * 
     * @param {OverlayType} type The type of overlay this wrapper holds. Used by the `OverlayTracker` to distinguish between types.
     * @param {IGoogleMap} map The map to which this overlay should be added.
     * @param {GoogleMapsApiService} api The instance of the low-level api.
     * @param {TNative} native The native overlay to wrap.
     */
    constructor(public readonly type: OverlayType, public map: IGoogleMap, api: GoogleMapsApiService, native: TNative)
    {
        super(api, native);

        this.attach(map);
    }

    /**
     * Assigns the overlay to the specified map. If possible, prefer using the appropriate `GoogleMap.createXXX()` method instead.
     * If not possible, it is the responsability of the caller to add the overlay to the `OverlayTracker` in the `GoogleMap.overlays` object.
     * Otherwise, inconsistencies and unexpected behaviours might occur.
     *
     * @param {IGoogleMap} map The map to dispaly the overlay on.
     */
    public attach(map: IGoogleMap): void
    {
        this.map = map;

        this.setNativeMapOutside(map.native);
    }

    /**
     * Removes the overlay from the map it is attached to. If possible, prefer using the `GoogleMap.removeOverlay()` method instead.
     * If not possible, it is the responsability of the caller to remove the overlay from the `OverlayTracker` in the `GoogleMap.overlays` object.
     * Otherwise, inconsistencies and unexpected behaviours might occur.
     */
    public detach(): void
    {
        this.map = null;

        this.setNativeMapOutside(null);
    }

    private setNativeMapOutside(map: google.maps.Map)
    {
        this.api.runOutsideAngular(() => this.native.setMap(map));
    }

    public abstract getBounds(): google.maps.LatLngBounds;
}

results matching ""

    No results matching ""