angular2-google-maps
Version:
Angular 2 components for Google Maps
225 lines • 9.19 kB
JavaScript
import { Directive, EventEmitter } from '@angular/core';
import { PolygonManager } from '../services/managers/polygon-manager';
/**
* SebmGoogleMapPolygon renders a polygon on a {@link SebmGoogleMap}
*
* ### Example
* ```typescript
* import { Component } from '@angular/core';
* import { SebmGoogleMap, SebmGooglePolygon, LatLngLiteral } from 'angular2-maps/core';
*
* @Component({
* selector: 'my-map-cmp',
* styles: [`
* .semb-map-container {
* height: 300px;
* }
* `],
* template: `
* <semb-map [latitude]="lat" [longitude]="lng" [zoom]="zoom">
* <semb-map-polygon [paths]="paths">
* </semb-map-polygon>
* </semb-map>
* `
* })
* export class MyMapCmp {
* lat: number = 0;
* lng: number = 0;
* zoom: number = 10;
* paths: Array<LatLngLiteral> = [
* { lat: 0, lng: 10 },
* { lat: 0, lng: 20 },
* { lat: 10, lng: 20 },
* { lat: 10, lng: 10 },
* { lat: 0, lng: 10 }
* ]
* // Nesting paths will create a hole where they overlap;
* nestedPaths: Array<Array<LatLngLiteral>> = [[
* { lat: 0, lng: 10 },
* { lat: 0, lng: 20 },
* { lat: 10, lng: 20 },
* { lat: 10, lng: 10 },
* { lat: 0, lng: 10 }
* ], [
* { lat: 0, lng: 15 },
* { lat: 0, lng: 20 },
* { lat: 5, lng: 20 },
* { lat: 5, lng: 15 },
* { lat: 0, lng: 15 }
* ]]
* }
* ```
*/
export var SebmGoogleMapPolygon = (function () {
function SebmGoogleMapPolygon(_polygonManager) {
this._polygonManager = _polygonManager;
/**
* Indicates whether this Polygon handles mouse events. Defaults to true.
*/
this.clickable = true;
/**
* If set to true, the user can drag this shape over the map. The geodesic
* property defines the mode of dragging. Defaults to false.
*/
this.draggable = false;
/**
* If set to true, the user can edit this shape by dragging the control
* points shown at the vertices and on each segment. Defaults to false.
*/
this.editable = false;
/**
* When true, edges of the polygon are interpreted as geodesic and will
* follow the curvature of the Earth. When false, edges of the polygon are
* rendered as straight lines in screen space. Note that the shape of a
* geodesic polygon may appear to change when dragged, as the dimensions
* are maintained relative to the surface of the earth. Defaults to false.
*/
this.geodesic = false;
/**
* The ordered sequence of coordinates that designates a closed loop.
* Unlike polylines, a polygon may consist of one or more paths.
* As a result, the paths property may specify one or more arrays of
* LatLng coordinates. Paths are closed automatically; do not repeat the
* first vertex of the path as the last vertex. Simple polygons may be
* defined using a single array of LatLngs. More complex polygons may
* specify an array of arrays. Any simple arrays are converted into Arrays.
* Inserting or removing LatLngs from the Array will automatically update
* the polygon on the map.
*/
this.paths = [];
/**
* This event is fired when the DOM click event is fired on the Polygon.
*/
this.polyClick = new EventEmitter();
/**
* This event is fired when the DOM dblclick event is fired on the Polygon.
*/
this.polyDblClick = new EventEmitter();
/**
* This event is repeatedly fired while the user drags the polygon.
*/
this.polyDrag = new EventEmitter();
/**
* This event is fired when the user stops dragging the polygon.
*/
this.polyDragEnd = new EventEmitter();
/**
* This event is fired when the user starts dragging the polygon.
*/
this.polyDragStart = new EventEmitter();
/**
* This event is fired when the DOM mousedown event is fired on the Polygon.
*/
this.polyMouseDown = new EventEmitter();
/**
* This event is fired when the DOM mousemove event is fired on the Polygon.
*/
this.polyMouseMove = new EventEmitter();
/**
* This event is fired on Polygon mouseout.
*/
this.polyMouseOut = new EventEmitter();
/**
* This event is fired on Polygon mouseover.
*/
this.polyMouseOver = new EventEmitter();
/**
* This event is fired whe the DOM mouseup event is fired on the Polygon
*/
this.polyMouseUp = new EventEmitter();
/**
* This even is fired when the Polygon is right-clicked on.
*/
this.polyRightClick = new EventEmitter();
this._polygonAddedToManager = false;
this._subscriptions = [];
}
/** @internal */
SebmGoogleMapPolygon.prototype.ngAfterContentInit = function () {
if (!this._polygonAddedToManager) {
this._init();
}
};
SebmGoogleMapPolygon.prototype.ngOnChanges = function (changes) {
if (!this._polygonAddedToManager) {
this._init();
return;
}
this._polygonManager.setPolygonOptions(this, this._updatePolygonOptions(changes));
};
SebmGoogleMapPolygon.prototype._init = function () {
this._polygonManager.addPolygon(this);
this._polygonAddedToManager = true;
this._addEventListeners();
};
SebmGoogleMapPolygon.prototype._addEventListeners = function () {
var _this = this;
var handlers = [
{ name: 'click', handler: function (ev) { return _this.polyClick.emit(ev); } },
{ name: 'dbclick', handler: function (ev) { return _this.polyDblClick.emit(ev); } },
{ name: 'drag', handler: function (ev) { return _this.polyDrag.emit(ev); } },
{ name: 'dragend', handler: function (ev) { return _this.polyDragEnd.emit(ev); } },
{ name: 'dragstart', handler: function (ev) { return _this.polyDragStart.emit(ev); } },
{ name: 'mousedown', handler: function (ev) { return _this.polyMouseDown.emit(ev); } },
{ name: 'mousemove', handler: function (ev) { return _this.polyMouseMove.emit(ev); } },
{ name: 'mouseout', handler: function (ev) { return _this.polyMouseOut.emit(ev); } },
{ name: 'mouseover', handler: function (ev) { return _this.polyMouseOver.emit(ev); } },
{ name: 'mouseup', handler: function (ev) { return _this.polyMouseUp.emit(ev); } },
{ name: 'rightclick', handler: function (ev) { return _this.polyRightClick.emit(ev); } },
];
handlers.forEach(function (obj) {
var os = _this._polygonManager.createEventObservable(obj.name, _this).subscribe(obj.handler);
_this._subscriptions.push(os);
});
};
SebmGoogleMapPolygon.prototype._updatePolygonOptions = function (changes) {
return Object.keys(changes)
.filter(function (k) { return SebmGoogleMapPolygon._polygonOptionsAttributes.indexOf(k) !== -1; })
.reduce(function (obj, k) {
obj[k] = changes[k].currentValue;
return obj;
}, {});
};
/** @internal */
SebmGoogleMapPolygon.prototype.id = function () { return this._id; };
/** @internal */
SebmGoogleMapPolygon.prototype.ngOnDestroy = function () {
this._polygonManager.deletePolygon(this);
// unsubscribe all registered observable subscriptions
this._subscriptions.forEach(function (s) { return s.unsubscribe(); });
};
SebmGoogleMapPolygon._polygonOptionsAttributes = [
'clickable', 'draggable', 'editable', 'fillColor', 'fillOpacity', 'geodesic', 'icon', 'map',
'paths', 'strokeColor', 'strokeOpacity', 'strokeWeight', 'visible', 'zIndex', 'draggable',
'editable', 'visible'
];
SebmGoogleMapPolygon.decorators = [
{ type: Directive, args: [{
selector: 'sebm-map-polygon',
inputs: [
'clickable',
'draggable: polyDraggable',
'editable',
'fillColor',
'fillOpacity',
'geodesic',
'paths',
'strokeColor',
'strokeOpacity',
'strokeWeight',
'visible',
'zIndex',
],
outputs: [
'polyClick', 'polyDblClick', 'polyDrag', 'polyDragEnd', 'polyMouseDown', 'polyMouseMove',
'polyMouseOut', 'polyMouseOver', 'polyMouseUp', 'polyRightClick'
]
},] },
];
/** @nocollapse */
SebmGoogleMapPolygon.ctorParameters = function () { return [
{ type: PolygonManager, },
]; };
return SebmGoogleMapPolygon;
}());
//# sourceMappingURL=google-map-polygon.js.map