The angular-ready wrapper for the native google.maps.Data
class.
overlays/modules/data/google-maps-data.ts
Properties |
Methods |
|
constructor(map: IGoogleMap, api: GoogleMapsApiService, native: any)
|
||||||||||||
Parameters:
|
||||||||||||
Public Readonly features |
Default value: new FeatureTracker()
|
The tracker of geometry features currently added to the data layer. * |
Public map |
Type: IGoogleMap
|
Inherited from
GoogleMapsDrawableOverlay
|
The map to which this overlay should be added.
|
Public Readonly type |
Type: OverlayType
|
Inherited from
GoogleMapsDrawableOverlay
|
The type of overlay this wrapper holds. Used by the `OverlayTracker` to distinguish between types.
|
Public custom |
Type: any
|
Inherited from
GoogleMapsNativeObjectWrapper
|
Public Readonly native |
Type: TNative
|
Inherited from
GoogleMapsNativeObjectWrapper
|
The instantiated native object to be wrapped.
|
Public addFeature | ||||||||
addFeature(feature: IGoogleMapsFeature)
|
||||||||
Adds a feature to the data layer.
Parameters:
Returns:
IGoogleMapsFeature
The wrapper object for the new feature. |
||||||||
Public addFeature | ||||||
addFeature(options: google.maps.Data.FeatureOptions)
|
||||||
Creates a wrapper object for the feature and adds it to the data layer.
Parameters:
Returns:
IGoogleMapsFeature
The wrapper object for the new feature. |
||||||
Public createMarker | ||||||||||||
createMarker(position: Coord, options?: google.maps.Data.FeatureOptions)
|
||||||||||||
Decorators :
@OutsideAngular()
|
||||||||||||
Creates a marker geometry feature with the specified properties and adds it to the map.
Parameters:
Returns:
IGoogleMapsFeature
The wrapper object for the new feature. |
||||||||||||
Public createPolygon | ||||||||||||
createPolygon(path: CoordPath, options?: google.maps.Data.FeatureOptions)
|
||||||||||||
Decorators :
@OutsideAngular()
|
||||||||||||
Creates a polygon geometry feature with the specified properties and adds it to the map.
Parameters:
Returns:
IGoogleMapsFeature
The wrapper object for the new feature. |
||||||||||||
Public createPolyline | ||||||||||||
createPolyline(path: Path, options?: google.maps.Data.FeatureOptions)
|
||||||||||||
Decorators :
@OutsideAngular()
|
||||||||||||
Creates a polyline geometry feature with the specified properties and adds it to the map.
Parameters:
Returns:
IGoogleMapsFeature
The wrapper object for the new feature. |
||||||||||||
Public getBounds |
getBounds()
|
Inherited from
GoogleMapsDrawableOverlay
|
Returns:
google.maps.LatLngBounds
|
Public loadGeoJson | ||||||||||||
loadGeoJson(url: string, options?: google.maps.Data.GeoJsonOptions)
|
||||||||||||
Decorators :
@OutsideAngular()
|
||||||||||||
Downloads GeoJson data from the specified url, interprets it and creates map features for it. Will automatically take care of the callback required by Google Maps Api internally.
Parameters:
Returns:
Promise<google.maps.Data.Feature[]>
A promise for the features representing the geometries added from the GeoJson. |
||||||||||||
Public removeFeature | ||||||||
removeFeature(feature: google.maps.Data.Feature)
|
||||||||
Removes a feature from the data layer.
Parameters:
Returns:
IGoogleMapsFeature
The removed feature wrapper or |
||||||||
Public removeFeature | ||||||||
removeFeature(feature: IGoogleMapsFeature)
|
||||||||
Removes a feature from the data layer.
Parameters:
Returns:
IGoogleMapsFeature
The removed feature wrapper or |
||||||||
Public removeFeature | ||||||||
removeFeature(featureId: string | number)
|
||||||||
Removes a feature from the data layer.
Parameters:
Returns:
IGoogleMapsFeature
The removed feature wrapper or |
||||||||
Public toGeoJson |
toGeoJson()
|
Creates the GeoJson representation of the data and provides it as an object when the promise resolves. Will automatically take care of the callback required by Google Maps Api internally.
Returns:
Promise<any>
A promise for the GeoJson object. |
Public attach | ||||||||
attach(map: IGoogleMap)
|
||||||||
Inherited from
GoogleMapsDrawableOverlay
|
||||||||
Assigns the overlay to the specified map. If possible, prefer using the appropriate
Parameters:
Returns:
void
|
||||||||
Public detach |
detach()
|
Inherited from
GoogleMapsDrawableOverlay
|
Removes the overlay from the map it is attached to. If possible, prefer using the
Returns:
void
|
Public clearListeners |
clearListeners()
|
Inherited from
GoogleMapsNativeObjectEmittingWrapper
|
Unregisters all handlers of any previously registered native event.
Returns:
void
|
Public listenTo | ||||||||||||
listenTo(eventName: string, handleEvent: (args: any[]) => void)
|
||||||||||||
Inherited from
GoogleMapsNativeObjectEmittingWrapper
|
||||||||||||
Registers a handler to a specific event of the native object and takes care of executing the handler inside angular's zone.
Parameters:
Returns:
void
An function for unregistering the handler from the event. |
||||||||||||
Public stopListeningTo | ||||||||
stopListeningTo(eventName: string)
|
||||||||
Inherited from
GoogleMapsNativeObjectEmittingWrapper
|
||||||||
Unregisters all handlers previously registered to handle a specific event.
Parameters:
Returns:
void
|
||||||||
Public setCustom | ||||||
setCustom(custom: any)
|
||||||
Inherited from
GoogleMapsNativeObjectWrapper
|
||||||
Parameters:
Returns:
void
|
||||||
import { GoogleMapsApiService, NativeObjectWrapper, IGoogleMap, OutsideAngular, Coord, CoordPath, Delegation, Path } from '@bespunky/angular-google-maps/core';
import { GoogleMapsDrawableOverlay } from '../../abstraction/base/google-maps-drawable-overlay';
import { OverlayType } from '../../abstraction/base/overlay-type.enum';
import { isGoogleMapsFeatureOptions } from '../../abstraction/type-guards/feature-options-type-guard';
import { IGoogleMapsData, WrappedDataFunctions } from './i-google-maps-data';
import { IGoogleMapsFeature } from './feature/i-google-maps-feature';
import { GoogleMapsFeature } from './feature/google-maps-feature';
import { FeatureTracker } from './services/feature-tracker';
/** Extends intellisense for `GoogleMapsData` with native data layer functions. */
export interface GoogleMapsData extends WrappedDataFunctions { }
/**
* The angular-ready wrapper for the native `google.maps.Data` class.
*
* @export
* @class GoogleMapsData
* @extends {GoogleMapsDrawableOverlay<google.maps.Data>}
* @implements {IGoogleMapsData}
*/
// @dynamic
@NativeObjectWrapper<GoogleMapsData>({
getMap: Delegation.Exclude,
setMap: Delegation.Exclude
})
export class GoogleMapsData extends GoogleMapsDrawableOverlay<google.maps.Data> implements IGoogleMapsData
{
/**
* The tracker of geometry features currently added to the data layer. *
*/
public readonly features = new FeatureTracker();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
constructor(map: IGoogleMap, api: GoogleMapsApiService, native: any /* See super for docs on `any` */)
{
super(OverlayType.Data, map, api, native);
}
public getBounds(): google.maps.LatLngBounds
{
return this.api.geometry.defineBounds(...this.features.list.map(feature => feature.getBounds()));
}
/**
* Creates a marker geometry feature with the specified properties and adds it to the map.
*
* @param {Coord} position The position at which the marker should be added.
* @param {google.maps.Data.FeatureOptions} [options] (Optional) Any native options to assign to the marker.
* @returns {IGoogleMapsFeature} The wrapper object for the new feature.
*/
@OutsideAngular
public createMarker(position: Coord, options?: google.maps.Data.FeatureOptions): IGoogleMapsFeature
{
options = this.buildOptions(this.api.geometry.createDataPoint(position), options);
return this.addFeature(options);
}
/**
* Creates a polygon geometry feature with the specified properties and adds it to the map.
*
* @param {CoordPath} path The path describing the polygon coordinates.
* @param {google.maps.Data.FeatureOptions} [options] (Optional) Any native options to assign to the polygon.
* @returns {IGoogleMapsFeature} The wrapper object for the new feature.
*/
@OutsideAngular
public createPolygon(path: CoordPath, options?: google.maps.Data.FeatureOptions): IGoogleMapsFeature
{
options = this.buildOptions(this.api.geometry.createDataPolygon(path), options);
return this.addFeature(options);
}
/**
* Creates a polyline geometry feature with the specified properties and adds it to the map.
*
* @param {Path} path The path describing the polyline coordinates.
* @param {google.maps.Data.FeatureOptions} [options] (Optional) Any native options to assign to the polyline.
* @returns {IGoogleMapsFeature} The wrapper object for the new feature.
*/
@OutsideAngular
public createPolyline(path: Path, options?: google.maps.Data.FeatureOptions): IGoogleMapsFeature
{
options = this.buildOptions(this.api.geometry.createDataPolyline(path), options);
return this.addFeature(options);
}
private buildOptions(geometry: google.maps.Data.Geometry, baseOptions?: google.maps.Data.FeatureOptions): google.maps.Data.FeatureOptions
{
return Object.assign({}, baseOptions, { geometry });
}
/**
* Adds a feature to the data layer.
*
* @param {IGoogleMapsFeature} feature The feature wrapper to add.
* @returns {IGoogleMapsFeature} The wrapper object for the new feature.
*/
public addFeature(feature: IGoogleMapsFeature): IGoogleMapsFeature;
/**
* Creates a wrapper object for the feature and adds it to the data layer.
*
* @param {(google.maps.Data.FeatureOptions | IGoogleMapsFeature)} feature The native feature or feature wrapper to add.
* @returns {IGoogleMapsFeature} The wrapper object for the new feature.
*/
public addFeature(options: google.maps.Data.FeatureOptions): IGoogleMapsFeature;
/**
* @ignore
*/
@OutsideAngular
public addFeature(feature: google.maps.Data.FeatureOptions | IGoogleMapsFeature): IGoogleMapsFeature
{
if (isGoogleMapsFeatureOptions(feature))
feature = new GoogleMapsFeature(this, this.api, new google.maps.Data.Feature(feature));
this.native.add(feature.native);
this.features.add(feature);
return feature;
}
/**
* Removes a feature from the data layer.
*
* @param {google.maps.Data.Feature} feature The native feature to remove.
* @returns {IGoogleMapsFeature} The removed feature wrapper or `null` if not found.
*/
public removeFeature(feature: google.maps.Data.Feature): IGoogleMapsFeature;
/**
* Removes a feature from the data layer.
*
* @param {IGoogleMapsFeature} feature The feature to remove.
* @returns {IGoogleMapsFeature} The removed feature wrapper or `null` if not found.
*/
public removeFeature(feature: IGoogleMapsFeature): IGoogleMapsFeature;
/**
* Removes a feature from the data layer.
*
* @param {(number | string)} featureId The id of the feature to remove.
* @returns {IGoogleMapsFeature} The removed feature wrapper or `null` if not found.
*/
public removeFeature(featureId: string | number): IGoogleMapsFeature;
/**
* @ignore
*/
@OutsideAngular
public removeFeature(featureOrId: string | number | google.maps.Data.Feature | IGoogleMapsFeature): IGoogleMapsFeature
{
const removed = this.features.remove(featureOrId);
if (removed)
this.native.remove(removed.native);
return removed;
}
/**
* Looks for a feature in the data layer.
*
* @param {(string | number)} id The id of the feature to look for.
* @returns {google.maps.Data.Feature} The feature associated with the specified id or `null` when not found.
*/
public findFeature(id: string | number): google.maps.Data.Feature { return this.native.getFeatureById(id); }
/**
* Creates the GeoJson representation of the data and provides it as an object when the promise resolves.
* Will automatically take care of the callback required by Google Maps Api internally.
*
* @returns {Promise<any>} A promise for the GeoJson object.
*/
public toGeoJson(): Promise<any>
{
return new Promise(resolve => this.native.toGeoJson(resolve));
}
/**
* Downloads GeoJson data from the specified url, interprets it and creates map features for it.
* Will automatically take care of the callback required by Google Maps Api internally.
* @param {string} url The url to the GeoJson data to download.
* @param {google.maps.Data.GeoJsonOptions} [options] (Optional) Configures the process of reading the GeoJson.
* @returns {google.maps.Data.Feature[]} A promise for the features representing the geometries added from the GeoJson.
*/
@OutsideAngular
public loadGeoJson(url: string, options?: google.maps.Data.GeoJsonOptions): Promise<google.maps.Data.Feature[]>
{
return new Promise(resolve => this.native.loadGeoJson(url, options, resolve));
}
}