Automates and facilitates tracking of overlays on the map and provide quick overlay creation methods.
overlays/superpower/services/overlays-superpower.service.ts
Properties |
|
Methods |
|
constructor(tracker: OverlaysTracker, api: GoogleMapsApiService)
|
||||||||||||
Creates an instance of OverlaysSuperpower.
Parameters:
|
||||||||||||
Public createCircle | ||||||||||||||||
createCircle(center: BoundsLike, radius: number, options?: google.maps.CircleOptions)
|
||||||||||||||||
Creates a polygon with the specified properties and adds it to the map.
Parameters:
Returns:
GoogleMapsCircle
The wrapper object created for the new circle. |
||||||||||||||||
Public createDataLayer | ||||||||
createDataLayer(options?: google.maps.Data.DataOptions)
|
||||||||
Creates a data layer with the specified properties and adds it to the map.
Parameters:
Returns:
GoogleMapsData
The wrapper object created for the new data layer. |
||||||||
Public createMarker | ||||||||||||
createMarker(position: BoundsLike, options?: google.maps.MarkerOptions)
|
||||||||||||
Creates a marker with the specified properties and adds it to the map.
Parameters:
Returns:
GoogleMapsMarker
The wrapper object created for the new marker. |
||||||||||||
Public createPolygon | ||||||||||||
createPolygon(path: CoordPath, options?: google.maps.PolygonOptions)
|
||||||||||||
Creates a polygon with the specified properties and adds it to the map.
Parameters:
Returns:
GoogleMapsPolygon
The wrapper object created for the new polygon. |
||||||||||||
Public createPolyline | ||||||||||||
createPolyline(path: CoordPath, options?: google.maps.PolylineOptions)
|
||||||||||||
Creates a polyline with the specified properties and adds it to the map.
Parameters:
Returns:
GoogleMapsPolyline
The wrapper object created for the new polyline. |
||||||||||||
Public removeOverlay | ||||||||
removeOverlay(overlay: TOverlay)
|
||||||||
Type parameters:
|
||||||||
Removes the specified overlay from the map.
Parameters:
Returns:
void
|
||||||||
Public attach | ||||||
attach(map: IGoogleMap)
|
||||||
Inherited from
Superpower
|
||||||
Parameters:
Returns:
void
|
||||||
Public tracker |
Type: OverlaysTracker
|
The tracker following the presence of overlays on the map.
|
import { Injectable } from '@angular/core';
import { GoogleMapModule, Superpower, GoogleMapsApiService, BoundsLike, CoordPath } from '@bespunky/angular-google-maps/core';
import { DrawableOverlay } from '../../abstraction/types/abstraction';
import { GoogleMapsMarker } from '../../modules/marker/google-maps-marker';
import { GoogleMapsPolygon } from '../../modules/polygon/google-maps-polygon';
import { GoogleMapsPolyline } from '../../modules/polyline/google-maps-polyline';
import { GoogleMapsCircle } from '../../modules/circle/google-maps-circle';
import { GoogleMapsData } from '../../modules/data/google-maps-data';
import { IOverlaysSuperpower } from '../i-overlays-superpower';
import { OverlaysTracker } from './overlays-tracker';
/**
* Automates and facilitates tracking of overlays on the map and provide quick overlay creation methods.
*
* @export
* @class OverlaysSuperpower
* @extends {Superpower}
* @implements {IOverlaysSuperpower}
*/
@Injectable({
providedIn: GoogleMapModule
})
export class OverlaysSuperpower extends Superpower implements IOverlaysSuperpower
{
/**
* Creates an instance of OverlaysSuperpower.
*
* @param {OverlaysTracker} tracker The tracker following the presence of overlays on the map.
* @param {GoogleMapsApiService} api The instance of the maps api service.
*/
constructor(public tracker: OverlaysTracker, private api: GoogleMapsApiService)
{
super();
}
/**
* Creates a marker with the specified properties and adds it to the map.
*
* @param {BoundsLike} position The position at which the marker should be added.
* @param {google.maps.MarkerOptions} [options] (Optional) Any native options to assign to the marker.
* @returns {GoogleMapsMarker} The wrapper object created for the new marker.
*/
public createMarker(position: BoundsLike, options?: google.maps.MarkerOptions): GoogleMapsMarker
{
options = { ...options, position: this.api.geometry.centerOf(position) };
const native = new google.maps.Marker(options);
// Marker creation will cause rendering. Run outside...
return this.createOverlay(() => new GoogleMapsMarker(this.map, this.api, native));
}
/**
* Creates a polygon with the specified properties and adds it to the map.
*
* @param {CoordPath} path The path describing the polygon coordinates.
* @param {google.maps.PolygonOptions} [options] (Optional) Any native options to assign to the polygon.
* @returns {GoogleMapsPolygon} The wrapper object created for the new polygon.
*/
public createPolygon(path: CoordPath, options?: google.maps.PolygonOptions): GoogleMapsPolygon
{
options = { ...options, paths: this.api.geometry.toLiteralMultiPath(path) };
const native = new google.maps.Polygon(options);
return this.createOverlay(() => new GoogleMapsPolygon(this.map, this.api, native));
}
/**
* Creates a polyline with the specified properties and adds it to the map.
*
* @param {Path} path The path describing the polyline coordinates.
* @param {google.maps.PolylineOptions} [options] (Optional) Any native options to assign to the polyline.
* @returns {GoogleMapsPolyline} The wrapper object created for the new polyline.
*/
public createPolyline(path: CoordPath, options?: google.maps.PolylineOptions): GoogleMapsPolyline
{
options = { ...options, path: this.api.geometry.toLiteralMultiPath(path)[0] };
const native = new google.maps.Polyline(options);
return this.createOverlay(() => new GoogleMapsPolyline(this.map, this.api, native));
}
/**
* Creates a polygon with the specified properties and adds it to the map.
*
* @param {BoundsLike} center The center of the circle.
* @param {number} radius The radius in meters on the Earth's surface.
* @param {google.maps.CircleOptions} [options] (Optional) Any native options to assign to the circle.
* @returns {GoogleMapsCircle} The wrapper object created for the new circle.
*/
public createCircle(center: BoundsLike, radius: number, options?: google.maps.CircleOptions): GoogleMapsCircle
{
options = { ...options, center: this.api.geometry.centerOf(center), radius };
const native = new google.maps.Circle(options);
return this.createOverlay(() => new GoogleMapsCircle(this.map, this.api, native));
}
/**
* Creates a data layer with the specified properties and adds it to the map.
*
* @param {google.maps.Data.DataOptions} [options] (Optional) Any native options to assign to the data layer.
* @returns {GoogleMapsData} The wrapper object created for the new data layer.
*/
public createDataLayer(options?: google.maps.Data.DataOptions): GoogleMapsData
{
const native = new google.maps.Data(options);
return this.createOverlay(() => new GoogleMapsData(this.map, this.api, native));
}
// TODO: Add here create methods for any new featured overlay type (e.g. polygons, polylines, etc.)
private createOverlay<TOverlay extends DrawableOverlay>(createObject: () => TOverlay): TOverlay
{
// Overlay creation will cause rendering. Run outside...
const overlay = this.api.runOutsideAngular(createObject);
this.tracker.add(overlay);
return overlay;
}
/**
* Removes the specified overlay from the map.
*
* @template TOverlay The type of overlay being removed.
* @param {TOverlay} overlay The wrapper of the overlay to remove.
*/
public removeOverlay<TOverlay extends DrawableOverlay>(overlay: TOverlay): void
{
// Overlay removal will cause rendering. Run outside...
this.api.runOutsideAngular(() => overlay.detach());
this.tracker.remove(overlay);
}
}