1 | ;
|
2 | var core_1 = require('@angular/core');
|
3 | var polygon_manager_1 = require('../services/managers/polygon-manager');
|
4 | /**
|
5 | * SebmGoogleMapPolygon renders a polygon on a {@link SebmGoogleMap}
|
6 | *
|
7 | * ### Example
|
8 | * ```typescript
|
9 | * import { Component } from '@angular/core';
|
10 | * import { SebmGoogleMap, SebmGooglePolygon, LatLngLiteral } from 'angular2-maps/core';
|
11 | *
|
12 | * @Component({
|
13 | * selector: 'my-map-cmp',
|
14 | * styles: [`
|
15 | * .semb-map-container {
|
16 | * height: 300px;
|
17 | * }
|
18 | * `],
|
19 | * template: `
|
20 | * <semb-map [latitude]="lat" [longitude]="lng" [zoom]="zoom">
|
21 | * <semb-map-polygon [paths]="paths">
|
22 | * </semb-map-polygon>
|
23 | * </semb-map>
|
24 | * `
|
25 | * })
|
26 | * export class MyMapCmp {
|
27 | * lat: number = 0;
|
28 | * lng: number = 0;
|
29 | * zoom: number = 10;
|
30 | * paths: Array<LatLngLiteral> = [
|
31 | * { lat: 0, lng: 10 },
|
32 | * { lat: 0, lng: 20 },
|
33 | * { lat: 10, lng: 20 },
|
34 | * { lat: 10, lng: 10 },
|
35 | * { lat: 0, lng: 10 }
|
36 | * ]
|
37 | * // Nesting paths will create a hole where they overlap;
|
38 | * nestedPaths: Array<Array<LatLngLiteral>> = [[
|
39 | * { lat: 0, lng: 10 },
|
40 | * { lat: 0, lng: 20 },
|
41 | * { lat: 10, lng: 20 },
|
42 | * { lat: 10, lng: 10 },
|
43 | * { lat: 0, lng: 10 }
|
44 | * ], [
|
45 | * { lat: 0, lng: 15 },
|
46 | * { lat: 0, lng: 20 },
|
47 | * { lat: 5, lng: 20 },
|
48 | * { lat: 5, lng: 15 },
|
49 | * { lat: 0, lng: 15 }
|
50 | * ]]
|
51 | * }
|
52 | * ```
|
53 | */
|
54 | var SebmGoogleMapPolygon = (function () {
|
55 | function SebmGoogleMapPolygon(_polygonManager) {
|
56 | this._polygonManager = _polygonManager;
|
57 | /**
|
58 | * Indicates whether this Polygon handles mouse events. Defaults to true.
|
59 | */
|
60 | this.clickable = true;
|
61 | /**
|
62 | * If set to true, the user can drag this shape over the map. The geodesic
|
63 | * property defines the mode of dragging. Defaults to false.
|
64 | */
|
65 | this.draggable = false;
|
66 | /**
|
67 | * If set to true, the user can edit this shape by dragging the control
|
68 | * points shown at the vertices and on each segment. Defaults to false.
|
69 | */
|
70 | this.editable = false;
|
71 | /**
|
72 | * When true, edges of the polygon are interpreted as geodesic and will
|
73 | * follow the curvature of the Earth. When false, edges of the polygon are
|
74 | * rendered as straight lines in screen space. Note that the shape of a
|
75 | * geodesic polygon may appear to change when dragged, as the dimensions
|
76 | * are maintained relative to the surface of the earth. Defaults to false.
|
77 | */
|
78 | this.geodesic = false;
|
79 | /**
|
80 | * The ordered sequence of coordinates that designates a closed loop.
|
81 | * Unlike polylines, a polygon may consist of one or more paths.
|
82 | * As a result, the paths property may specify one or more arrays of
|
83 | * LatLng coordinates. Paths are closed automatically; do not repeat the
|
84 | * first vertex of the path as the last vertex. Simple polygons may be
|
85 | * defined using a single array of LatLngs. More complex polygons may
|
86 | * specify an array of arrays. Any simple arrays are converted into Arrays.
|
87 | * Inserting or removing LatLngs from the Array will automatically update
|
88 | * the polygon on the map.
|
89 | */
|
90 | this.paths = [];
|
91 | /**
|
92 | * This event is fired when the DOM click event is fired on the Polygon.
|
93 | */
|
94 | this.polyClick = new core_1.EventEmitter();
|
95 | /**
|
96 | * This event is fired when the DOM dblclick event is fired on the Polygon.
|
97 | */
|
98 | this.polyDblClick = new core_1.EventEmitter();
|
99 | /**
|
100 | * This event is repeatedly fired while the user drags the polygon.
|
101 | */
|
102 | this.polyDrag = new core_1.EventEmitter();
|
103 | /**
|
104 | * This event is fired when the user stops dragging the polygon.
|
105 | */
|
106 | this.polyDragEnd = new core_1.EventEmitter();
|
107 | /**
|
108 | * This event is fired when the user starts dragging the polygon.
|
109 | */
|
110 | this.polyDragStart = new core_1.EventEmitter();
|
111 | /**
|
112 | * This event is fired when the DOM mousedown event is fired on the Polygon.
|
113 | */
|
114 | this.polyMouseDown = new core_1.EventEmitter();
|
115 | /**
|
116 | * This event is fired when the DOM mousemove event is fired on the Polygon.
|
117 | */
|
118 | this.polyMouseMove = new core_1.EventEmitter();
|
119 | /**
|
120 | * This event is fired on Polygon mouseout.
|
121 | */
|
122 | this.polyMouseOut = new core_1.EventEmitter();
|
123 | /**
|
124 | * This event is fired on Polygon mouseover.
|
125 | */
|
126 | this.polyMouseOver = new core_1.EventEmitter();
|
127 | /**
|
128 | * This event is fired whe the DOM mouseup event is fired on the Polygon
|
129 | */
|
130 | this.polyMouseUp = new core_1.EventEmitter();
|
131 | /**
|
132 | * This even is fired when the Polygon is right-clicked on.
|
133 | */
|
134 | this.polyRightClick = new core_1.EventEmitter();
|
135 | this._polygonAddedToManager = false;
|
136 | this._subscriptions = [];
|
137 | }
|
138 | /** @internal */
|
139 | SebmGoogleMapPolygon.prototype.ngAfterContentInit = function () {
|
140 | if (!this._polygonAddedToManager) {
|
141 | this._init();
|
142 | }
|
143 | };
|
144 | SebmGoogleMapPolygon.prototype.ngOnChanges = function (changes) {
|
145 | if (!this._polygonAddedToManager) {
|
146 | this._init();
|
147 | return;
|
148 | }
|
149 | this._polygonManager.setPolygonOptions(this, this._updatePolygonOptions(changes));
|
150 | };
|
151 | SebmGoogleMapPolygon.prototype._init = function () {
|
152 | this._polygonManager.addPolygon(this);
|
153 | this._polygonAddedToManager = true;
|
154 | this._addEventListeners();
|
155 | };
|
156 | SebmGoogleMapPolygon.prototype._addEventListeners = function () {
|
157 | var _this = this;
|
158 | var handlers = [
|
159 | { name: 'click', handler: function (ev) { return _this.polyClick.emit(ev); } },
|
160 | { name: 'dbclick', handler: function (ev) { return _this.polyDblClick.emit(ev); } },
|
161 | { name: 'drag', handler: function (ev) { return _this.polyDrag.emit(ev); } },
|
162 | { name: 'dragend', handler: function (ev) { return _this.polyDragEnd.emit(ev); } },
|
163 | { name: 'dragstart', handler: function (ev) { return _this.polyDragStart.emit(ev); } },
|
164 | { name: 'mousedown', handler: function (ev) { return _this.polyMouseDown.emit(ev); } },
|
165 | { name: 'mousemove', handler: function (ev) { return _this.polyMouseMove.emit(ev); } },
|
166 | { name: 'mouseout', handler: function (ev) { return _this.polyMouseOut.emit(ev); } },
|
167 | { name: 'mouseover', handler: function (ev) { return _this.polyMouseOver.emit(ev); } },
|
168 | { name: 'mouseup', handler: function (ev) { return _this.polyMouseUp.emit(ev); } },
|
169 | { name: 'rightclick', handler: function (ev) { return _this.polyRightClick.emit(ev); } },
|
170 | ];
|
171 | handlers.forEach(function (obj) {
|
172 | var os = _this._polygonManager.createEventObservable(obj.name, _this).subscribe(obj.handler);
|
173 | _this._subscriptions.push(os);
|
174 | });
|
175 | };
|
176 | SebmGoogleMapPolygon.prototype._updatePolygonOptions = function (changes) {
|
177 | return Object.keys(changes)
|
178 | .filter(function (k) { return SebmGoogleMapPolygon._polygonOptionsAttributes.indexOf(k) !== -1; })
|
179 | .reduce(function (obj, k) {
|
180 | obj[k] = changes[k].currentValue;
|
181 | return obj;
|
182 | }, {});
|
183 | };
|
184 | /** @internal */
|
185 | SebmGoogleMapPolygon.prototype.id = function () { return this._id; };
|
186 | /** @internal */
|
187 | SebmGoogleMapPolygon.prototype.ngOnDestroy = function () {
|
188 | this._polygonManager.deletePolygon(this);
|
189 | // unsubscribe all registered observable subscriptions
|
190 | this._subscriptions.forEach(function (s) { return s.unsubscribe(); });
|
191 | };
|
192 | SebmGoogleMapPolygon._polygonOptionsAttributes = [
|
193 | 'clickable', 'draggable', 'editable', 'fillColor', 'fillOpacity', 'geodesic', 'icon', 'map',
|
194 | 'paths', 'strokeColor', 'strokeOpacity', 'strokeWeight', 'visible', 'zIndex', 'draggable',
|
195 | 'editable', 'visible'
|
196 | ];
|
197 | SebmGoogleMapPolygon.decorators = [
|
198 | { type: core_1.Directive, args: [{
|
199 | selector: 'sebm-map-polygon',
|
200 | inputs: [
|
201 | 'clickable',
|
202 | 'draggable: polyDraggable',
|
203 | 'editable',
|
204 | 'fillColor',
|
205 | 'fillOpacity',
|
206 | 'geodesic',
|
207 | 'paths',
|
208 | 'strokeColor',
|
209 | 'strokeOpacity',
|
210 | 'strokeWeight',
|
211 | 'visible',
|
212 | 'zIndex',
|
213 | ],
|
214 | outputs: [
|
215 | 'polyClick', 'polyDblClick', 'polyDrag', 'polyDragEnd', 'polyMouseDown', 'polyMouseMove',
|
216 | 'polyMouseOut', 'polyMouseOver', 'polyMouseUp', 'polyRightClick'
|
217 | ]
|
218 | },] },
|
219 | ];
|
220 | /** @nocollapse */
|
221 | SebmGoogleMapPolygon.ctorParameters = function () { return [
|
222 | { type: polygon_manager_1.PolygonManager, },
|
223 | ]; };
|
224 | return SebmGoogleMapPolygon;
|
225 | }());
|
226 | exports.SebmGoogleMapPolygon = SebmGoogleMapPolygon;
|
227 | //# sourceMappingURL=google-map-polygon.js.map |
\ | No newline at end of file |