UNPKG

agm-direction

Version:
1,168 lines (1,148 loc) 224 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('rxjs/operators'), require('@angular/common')) : typeof define === 'function' && define.amd ? define('agm-direction', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/common'], factory) : (global = global || self, factory((global.ng = global.ng || {}, global.ng.agmDirection = {}), global.ng.core, global.rxjs, global.rxjs.operators, global.ng.common)); }(this, function (exports, core, rxjs, operators, common) { 'use strict'; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __param(paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } } function __metadata(metadataKey, metadataValue) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue); } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } var MapsAPILoader = /** @class */ (function () { function MapsAPILoader() { } MapsAPILoader = __decorate([ core.Injectable() ], MapsAPILoader); return MapsAPILoader; }()); /** * Wrapper class that handles the communication with the Google Maps Javascript * API v3 */ var GoogleMapsAPIWrapper = /** @class */ (function () { function GoogleMapsAPIWrapper(_loader, _zone) { var _this = this; this._loader = _loader; this._zone = _zone; this._map = new Promise(function (resolve) { _this._mapResolver = resolve; }); } GoogleMapsAPIWrapper.prototype.createMap = function (el, mapOptions) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._loader.load().then(function () { var map = new google.maps.Map(el, mapOptions); _this._mapResolver(map); return; }); }); }; GoogleMapsAPIWrapper.prototype.setMapOptions = function (options) { var _this = this; return this._zone.runOutsideAngular(function () { _this._map.then(function (m) { m.setOptions(options); }); }); }; /** * Creates a google map marker with the map context */ GoogleMapsAPIWrapper.prototype.createMarker = function (options, addToMap) { var _this = this; if (options === void 0) { options = {}; } if (addToMap === void 0) { addToMap = true; } return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { if (addToMap) { options.map = map; } return new google.maps.Marker(options); }); }); }; GoogleMapsAPIWrapper.prototype.createInfoWindow = function (options) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function () { return new google.maps.InfoWindow(options); }); }); }; /** * Creates a google.map.Circle for the current map. */ GoogleMapsAPIWrapper.prototype.createCircle = function (options) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { if (typeof options.strokePosition === 'string') { options.strokePosition = google.maps.StrokePosition[options.strokePosition]; } options.map = map; return new google.maps.Circle(options); }); }); }; /** * Creates a google.map.Rectangle for the current map. */ GoogleMapsAPIWrapper.prototype.createRectangle = function (options) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { options.map = map; return new google.maps.Rectangle(options); }); }); }; GoogleMapsAPIWrapper.prototype.createPolyline = function (options) { var _this = this; return this._zone.runOutsideAngular(function () { return _this.getNativeMap().then(function (map) { var line = new google.maps.Polyline(options); line.setMap(map); return line; }); }); }; GoogleMapsAPIWrapper.prototype.createPolygon = function (options) { var _this = this; return this._zone.runOutsideAngular(function () { return _this.getNativeMap().then(function (map) { var polygon = new google.maps.Polygon(options); polygon.setMap(map); return polygon; }); }); }; /** * Creates a new google.map.Data layer for the current map */ GoogleMapsAPIWrapper.prototype.createDataLayer = function (options) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (m) { var data = new google.maps.Data(options); data.setMap(m); return data; }); }); }; /** * Creates a TransitLayer instance for a map * @param {TransitLayerOptions} options - used for setting layer options * @returns {Promise<TransitLayer>} a new transit layer object */ GoogleMapsAPIWrapper.prototype.createTransitLayer = function (options) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { var newLayer = new google.maps.TransitLayer(); newLayer.setMap(options.visible ? map : null); return newLayer; }); }); }; /** * Creates a BicyclingLayer instance for a map * @param {BicyclingLayerOptions} options - used for setting layer options * @returns {Promise<BicyclingLayer>} a new bicycling layer object */ GoogleMapsAPIWrapper.prototype.createBicyclingLayer = function (options) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { var newLayer = new google.maps.BicyclingLayer(); newLayer.setMap(options.visible ? map : null); return newLayer; }); }); }; /** * Determines if given coordinates are insite a Polygon path. */ GoogleMapsAPIWrapper.prototype.containsLocation = function (latLng, polygon) { return google.maps.geometry.poly.containsLocation(latLng, polygon); }; GoogleMapsAPIWrapper.prototype.subscribeToMapEvent = function (eventName) { var _this = this; return new rxjs.Observable(function (observer) { _this._map.then(function (m) { m.addListener(eventName, function (arg) { _this._zone.run(function () { return observer.next(arg); }); }); }); }); }; GoogleMapsAPIWrapper.prototype.clearInstanceListeners = function () { var _this = this; return this._zone.runOutsideAngular(function () { _this._map.then(function (map) { google.maps.event.clearInstanceListeners(map); }); }); }; GoogleMapsAPIWrapper.prototype.setCenter = function (latLng) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { return map.setCenter(latLng); }); }); }; GoogleMapsAPIWrapper.prototype.getZoom = function () { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { return map.getZoom(); }); }); }; GoogleMapsAPIWrapper.prototype.getBounds = function () { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { return map.getBounds(); }); }); }; GoogleMapsAPIWrapper.prototype.getMapTypeId = function () { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { return map.getMapTypeId(); }); }); }; GoogleMapsAPIWrapper.prototype.setZoom = function (zoom) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { return map.setZoom(zoom); }); }); }; GoogleMapsAPIWrapper.prototype.getCenter = function () { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { return map.getCenter(); }); }); }; GoogleMapsAPIWrapper.prototype.panTo = function (latLng) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { return map.panTo(latLng); }); }); }; GoogleMapsAPIWrapper.prototype.panBy = function (x, y) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { return map.panBy(x, y); }); }); }; GoogleMapsAPIWrapper.prototype.fitBounds = function (latLng, padding) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { return map.fitBounds(latLng, padding); }); }); }; GoogleMapsAPIWrapper.prototype.panToBounds = function (latLng, padding) { var _this = this; return this._zone.runOutsideAngular(function () { return _this._map.then(function (map) { return map.panToBounds(latLng, padding); }); }); }; /** * Returns the native Google Maps Map instance. Be careful when using this instance directly. */ GoogleMapsAPIWrapper.prototype.getNativeMap = function () { return this._map; }; /** * Triggers the given event name on the map instance. */ GoogleMapsAPIWrapper.prototype.triggerMapEvent = function (eventName) { return this._map.then(function (m) { return google.maps.event.trigger(m, eventName); }); }; GoogleMapsAPIWrapper.ctorParameters = function () { return [ { type: MapsAPILoader }, { type: core.NgZone } ]; }; GoogleMapsAPIWrapper = __decorate([ core.Injectable(), __metadata("design:paramtypes", [MapsAPILoader, core.NgZone]) ], GoogleMapsAPIWrapper); return GoogleMapsAPIWrapper; }()); /** * This class manages Transit and Bicycling Layers for a Google Map instance. */ var LayerManager = /** @class */ (function () { function LayerManager(_wrapper) { this._wrapper = _wrapper; this._layers = new Map(); } /** * Adds a transit layer to a map instance. * @param {AgmTransitLayer} layer - a TransitLayer object * @param {TransitLayerOptions} options - TransitLayerOptions options * @returns void */ LayerManager.prototype.addTransitLayer = function (layer, options) { var newLayer = this._wrapper.createTransitLayer(options); this._layers.set(layer, newLayer); }; /** * Adds a bicycling layer to a map instance. * @param {AgmBicyclingLayer} layer - a bicycling layer object * @param {BicyclingLayerOptions} options - BicyclingLayer options * @returns void */ LayerManager.prototype.addBicyclingLayer = function (layer, options) { var newLayer = this._wrapper.createBicyclingLayer(options); this._layers.set(layer, newLayer); }; /** * Deletes a map layer * @param {AgmTransitLayer|AgmBicyclingLayer} layer - the layer to delete * @returns Promise<void> */ LayerManager.prototype.deleteLayer = function (layer) { var _this = this; return this._layers.get(layer).then(function (currentLayer) { currentLayer.setMap(null); _this._layers.delete(layer); }); }; /** * Hide/Show a google map layer * @param { AgmTransitLayer|AgmBicyclingLayer} layer - the layer to hide/show * @param {TransitLayerOptions|BicyclingLayerOptions} options - used to set visibility of the layer * @returns Promise<void> */ LayerManager.prototype.toggleLayerVisibility = function (layer, options) { var _this = this; return this._layers.get(layer).then(function (currentLayer) { if (!options.visible) { currentLayer.setMap(null); return; } else { return _this._wrapper.getNativeMap().then(function (map) { currentLayer.setMap(map); }); } }); }; LayerManager.ctorParameters = function () { return [ { type: GoogleMapsAPIWrapper } ]; }; LayerManager = __decorate([ core.Injectable(), __metadata("design:paramtypes", [GoogleMapsAPIWrapper]) ], LayerManager); return LayerManager; }()); var layerId = 0; /* * This directive adds a bicycling layer to a google map instance * <agm-bicycling-layer [visible]="true|false"> <agm-bicycling-layer> * */ var AgmBicyclingLayer = /** @class */ (function () { function AgmBicyclingLayer(_manager) { this._manager = _manager; this._addedToManager = false; this._id = (layerId++).toString(); /** * Hide/show bicycling layer */ this.visible = true; } AgmBicyclingLayer.prototype.ngOnInit = function () { if (this._addedToManager) { return; } this._manager.addBicyclingLayer(this, { visible: this.visible }); this._addedToManager = true; }; AgmBicyclingLayer.prototype.ngOnChanges = function (changes) { if (!this._addedToManager) { return; } if (changes['visible'] != null) { this._manager.toggleLayerVisibility(this, { visible: changes['visible'].currentValue }); } }; /** @internal */ AgmBicyclingLayer.prototype.id = function () { return this._id; }; /** @internal */ AgmBicyclingLayer.prototype.toString = function () { return "AgmBicyclingLayer-" + this._id.toString(); }; /** @internal */ AgmBicyclingLayer.prototype.ngOnDestroy = function () { this._manager.deleteLayer(this); }; AgmBicyclingLayer.ctorParameters = function () { return [ { type: LayerManager } ]; }; __decorate([ core.Input(), __metadata("design:type", Object) ], AgmBicyclingLayer.prototype, "visible", void 0); AgmBicyclingLayer = __decorate([ core.Directive({ selector: 'agm-bicycling-layer', }), __metadata("design:paramtypes", [LayerManager]) ], AgmBicyclingLayer); return AgmBicyclingLayer; }()); var CircleManager = /** @class */ (function () { function CircleManager(_apiWrapper, _zone) { this._apiWrapper = _apiWrapper; this._zone = _zone; this._circles = new Map(); } CircleManager.prototype.addCircle = function (circle) { this._circles.set(circle, this._apiWrapper.createCircle({ center: { lat: circle.latitude, lng: circle.longitude }, clickable: circle.clickable, draggable: circle.draggable, editable: circle.editable, fillColor: circle.fillColor, fillOpacity: circle.fillOpacity, radius: circle.radius, strokeColor: circle.strokeColor, strokeOpacity: circle.strokeOpacity, strokePosition: circle.strokePosition, strokeWeight: circle.strokeWeight, visible: circle.visible, zIndex: circle.zIndex, })); }; /** * Removes the given circle from the map. */ CircleManager.prototype.removeCircle = function (circle) { var _this = this; return this._circles.get(circle).then(function (c) { c.setMap(null); _this._circles.delete(circle); }); }; CircleManager.prototype.setOptions = function (circle, options) { return this._circles.get(circle).then(function (c) { if (typeof options.strokePosition === 'string') { options.strokePosition = google.maps.StrokePosition[options.strokePosition]; } c.setOptions(options); }); }; CircleManager.prototype.getBounds = function (circle) { return this._circles.get(circle).then(function (c) { return c.getBounds(); }); }; CircleManager.prototype.getCenter = function (circle) { return this._circles.get(circle).then(function (c) { return c.getCenter(); }); }; CircleManager.prototype.getRadius = function (circle) { return this._circles.get(circle).then(function (c) { return c.getRadius(); }); }; CircleManager.prototype.setCenter = function (circle) { return this._circles.get(circle).then(function (c) { return c.setCenter({ lat: circle.latitude, lng: circle.longitude }); }); }; CircleManager.prototype.setEditable = function (circle) { return this._circles.get(circle).then(function (c) { return c.setEditable(circle.editable); }); }; CircleManager.prototype.setDraggable = function (circle) { return this._circles.get(circle).then(function (c) { return c.setDraggable(circle.draggable); }); }; CircleManager.prototype.setVisible = function (circle) { return this._circles.get(circle).then(function (c) { return c.setVisible(circle.visible); }); }; CircleManager.prototype.setRadius = function (circle) { return this._circles.get(circle).then(function (c) { return c.setRadius(circle.radius); }); }; CircleManager.prototype.getNativeCircle = function (circle) { return this._circles.get(circle); }; CircleManager.prototype.createEventObservable = function (eventName, circle) { var _this = this; return new rxjs.Observable(function (observer) { var listener = null; _this._circles.get(circle).then(function (c) { listener = c.addListener(eventName, function (e) { return _this._zone.run(function () { return observer.next(e); }); }); }); return function () { if (listener !== null) { listener.remove(); } }; }); }; CircleManager.ctorParameters = function () { return [ { type: GoogleMapsAPIWrapper }, { type: core.NgZone } ]; }; CircleManager = __decorate([ core.Injectable(), __metadata("design:paramtypes", [GoogleMapsAPIWrapper, core.NgZone]) ], CircleManager); return CircleManager; }()); var AgmCircle = /** @class */ (function () { function AgmCircle(_manager) { this._manager = _manager; /** * Indicates whether this Circle handles mouse events. Defaults to true. */ this.clickable = true; /** * If set to true, the user can drag this circle over the map. Defaults to false. */ // tslint:disable-next-line:no-input-rename this.draggable = false; /** * If set to true, the user can edit this circle by dragging the control points shown at * the center and around the circumference of the circle. Defaults to false. */ this.editable = false; /** * The radius in meters on the Earth's surface. */ this.radius = 0; /** * The stroke position. Defaults to CENTER. * This property is not supported on Internet Explorer 8 and earlier. */ this.strokePosition = 'CENTER'; /** * The stroke width in pixels. */ this.strokeWeight = 0; /** * Whether this circle is visible on the map. Defaults to true. */ this.visible = true; /** * This event is fired when the circle's center is changed. */ this.centerChange = new core.EventEmitter(); /** * This event emitter gets emitted when the user clicks on the circle. */ this.circleClick = new core.EventEmitter(); /** * This event emitter gets emitted when the user clicks on the circle. */ this.circleDblClick = new core.EventEmitter(); /** * This event is repeatedly fired while the user drags the circle. */ this.drag = new core.EventEmitter(); /** * This event is fired when the user stops dragging the circle. */ this.dragEnd = new core.EventEmitter(); /** * This event is fired when the user starts dragging the circle. */ this.dragStart = new core.EventEmitter(); /** * This event is fired when the DOM mousedown event is fired on the circle. */ this.mouseDown = new core.EventEmitter(); /** * This event is fired when the DOM mousemove event is fired on the circle. */ this.mouseMove = new core.EventEmitter(); /** * This event is fired on circle mouseout. */ this.mouseOut = new core.EventEmitter(); /** * This event is fired on circle mouseover. */ this.mouseOver = new core.EventEmitter(); /** * This event is fired when the DOM mouseup event is fired on the circle. */ this.mouseUp = new core.EventEmitter(); /** * This event is fired when the circle's radius is changed. */ this.radiusChange = new core.EventEmitter(); /** * This event is fired when the circle is right-clicked on. */ this.rightClick = new core.EventEmitter(); this._circleAddedToManager = false; this._eventSubscriptions = []; } AgmCircle_1 = AgmCircle; /** @internal */ AgmCircle.prototype.ngOnInit = function () { this._manager.addCircle(this); this._circleAddedToManager = true; this._registerEventListeners(); }; /** @internal */ AgmCircle.prototype.ngOnChanges = function (changes) { if (!this._circleAddedToManager) { return; } if (changes['latitude'] || changes['longitude']) { this._manager.setCenter(this); } if (changes['editable']) { this._manager.setEditable(this); } if (changes['draggable']) { this._manager.setDraggable(this); } if (changes['visible']) { this._manager.setVisible(this); } if (changes['radius']) { this._manager.setRadius(this); } this._updateCircleOptionsChanges(changes); }; AgmCircle.prototype._updateCircleOptionsChanges = function (changes) { var options = {}; var optionKeys = Object.keys(changes).filter(function (k) { return AgmCircle_1._mapOptions.indexOf(k) !== -1; }); optionKeys.forEach(function (k) { options[k] = changes[k].currentValue; }); if (optionKeys.length > 0) { this._manager.setOptions(this, options); } }; AgmCircle.prototype._registerEventListeners = function () { var _this = this; var events = new Map(); events.set('center_changed', this.centerChange); events.set('click', this.circleClick); events.set('dblclick', this.circleDblClick); events.set('drag', this.drag); events.set('dragend', this.dragEnd); events.set('dragstart', this.dragStart); events.set('mousedown', this.mouseDown); events.set('mousemove', this.mouseMove); events.set('mouseout', this.mouseOut); events.set('mouseover', this.mouseOver); events.set('mouseup', this.mouseUp); events.set('radius_changed', this.radiusChange); events.set('rightclick', this.rightClick); events.forEach(function (eventEmitter, eventName) { _this._eventSubscriptions.push(_this._manager.createEventObservable(eventName, _this).subscribe(function (value) { switch (eventName) { case 'radius_changed': _this._manager.getRadius(_this).then(function (radius) { return eventEmitter.emit(radius); }); break; case 'center_changed': _this._manager.getCenter(_this).then(function (center) { return eventEmitter.emit({ lat: center.lat(), lng: center.lng() }); }); break; default: eventEmitter.emit({ coords: { lat: value.latLng.lat(), lng: value.latLng.lng() } }); } })); }); }; /** @internal */ AgmCircle.prototype.ngOnDestroy = function () { this._eventSubscriptions.forEach(function (s) { s.unsubscribe(); }); this._eventSubscriptions = null; this._manager.removeCircle(this); }; /** * Gets the LatLngBounds of this Circle. */ AgmCircle.prototype.getBounds = function () { return this._manager.getBounds(this); }; AgmCircle.prototype.getCenter = function () { return this._manager.getCenter(this); }; var AgmCircle_1; AgmCircle._mapOptions = [ 'fillColor', 'fillOpacity', 'strokeColor', 'strokeOpacity', 'strokePosition', 'strokeWeight', 'visible', 'zIndex', 'clickable', ]; AgmCircle.ctorParameters = function () { return [ { type: CircleManager } ]; }; __decorate([ core.Input(), __metadata("design:type", Number) ], AgmCircle.prototype, "latitude", void 0); __decorate([ core.Input(), __metadata("design:type", Number) ], AgmCircle.prototype, "longitude", void 0); __decorate([ core.Input(), __metadata("design:type", Object) ], AgmCircle.prototype, "clickable", void 0); __decorate([ core.Input('circleDraggable'), __metadata("design:type", Object) ], AgmCircle.prototype, "draggable", void 0); __decorate([ core.Input(), __metadata("design:type", Object) ], AgmCircle.prototype, "editable", void 0); __decorate([ core.Input(), __metadata("design:type", String) ], AgmCircle.prototype, "fillColor", void 0); __decorate([ core.Input(), __metadata("design:type", Number) ], AgmCircle.prototype, "fillOpacity", void 0); __decorate([ core.Input(), __metadata("design:type", Object) ], AgmCircle.prototype, "radius", void 0); __decorate([ core.Input(), __metadata("design:type", String) ], AgmCircle.prototype, "strokeColor", void 0); __decorate([ core.Input(), __metadata("design:type", Number) ], AgmCircle.prototype, "strokeOpacity", void 0); __decorate([ core.Input(), __metadata("design:type", String) ], AgmCircle.prototype, "strokePosition", void 0); __decorate([ core.Input(), __metadata("design:type", Object) ], AgmCircle.prototype, "strokeWeight", void 0); __decorate([ core.Input(), __metadata("design:type", Object) ], AgmCircle.prototype, "visible", void 0); __decorate([ core.Input(), __metadata("design:type", Number) ], AgmCircle.prototype, "zIndex", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "centerChange", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "circleClick", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "circleDblClick", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "drag", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "dragEnd", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "dragStart", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "mouseDown", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "mouseMove", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "mouseOut", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "mouseOver", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "mouseUp", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "radiusChange", void 0); __decorate([ core.Output(), __metadata("design:type", core.EventEmitter) ], AgmCircle.prototype, "rightClick", void 0); AgmCircle = AgmCircle_1 = __decorate([ core.Directive({ selector: 'agm-circle', }), __metadata("design:paramtypes", [CircleManager]) ], AgmCircle); return AgmCircle; }()); /** * Manages all Data Layers for a Google Map instance. */ var DataLayerManager = /** @class */ (function () { function DataLayerManager(_wrapper, _zone) { this._wrapper = _wrapper; this._zone = _zone; this._layers = new Map(); } /** * Adds a new Data Layer to the map. */ DataLayerManager.prototype.addDataLayer = function (layer) { var _this = this; var newLayer = this._wrapper.createDataLayer({ style: layer.style, }) .then(function (d) { if (layer.geoJson) { _this.getDataFeatures(d, layer.geoJson).then(function (features) { return d.features = features; }); } return d; }); this._layers.set(layer, newLayer); }; DataLayerManager.prototype.deleteDataLayer = function (layer) { var _this = this; this._layers.get(layer).then(function (l) { l.setMap(null); _this._layers.delete(layer); }); }; DataLayerManager.prototype.updateGeoJson = function (layer, geoJson) { var _this = this; this._layers.get(layer).then(function (l) { l.forEach(function (feature) { l.remove(feature); var index = l.features.indexOf(feature, 0); if (index > -1) { l.features.splice(index, 1); } }); _this.getDataFeatures(l, geoJson).then(function (features) { return l.features = features; }); }); }; DataLayerManager.prototype.setDataOptions = function (layer, options) { this._layers.get(layer).then(function (l) { l.setControlPosition(options.controlPosition); l.setControls(options.controls); l.setDrawingMode(options.drawingMode); l.setStyle(options.style); }); }; /** * Creates a Google Maps event listener for the given DataLayer as an Observable */ DataLayerManager.prototype.createEventObservable = function (eventName, layer) { var _this = this; return new rxjs.Observable(function (observer) { _this._layers.get(layer).then(function (d) { d.addListener(eventName, function (e) { return _this._zone.run(function () { return observer.next(e); }); }); }); }); }; /** * Extract features from a geoJson using google.maps Data Class * @param d : google.maps.Data class instance * @param geoJson : url or geojson object */ DataLayerManager.prototype.getDataFeatures = function (d, geoJson) { return new Promise(function (resolve, reject) { if (typeof geoJson === 'object') { try { var features = d.addGeoJson(geoJson); resolve(features); } catch (e) { reject(e); } } else if (typeof geoJson === 'string') { d.loadGeoJson(geoJson, null, resolve); } else { reject("Impossible to extract features from geoJson: wrong argument type"); } }); }; DataLayerManager.ctorParameters = function () { return [ { type: GoogleMapsAPIWrapper }, { type: core.NgZone } ]; }; DataLayerManager = __decorate([ core.Injectable(), __metadata("design:paramtypes", [GoogleMapsAPIWrapper, core.NgZone]) ], DataLayerManager); return DataLayerManager; }()); var layerId$1 = 0; /** * AgmDataLayer enables the user to add data layers to the map. * * ### Example * ```typescript * import { Component } from 'angular2/core'; * import { AgmMap, AgmDataLayer } from * 'angular-google-maps/core'; * * @Component({ * selector: 'my-map-cmp', * directives: [AgmMap, AgmDataLayer], * styles: [` * .agm-container { * height: 300px; * } * `], * template: ` * <agm-map [latitude]="lat" [longitude]="lng" [zoom]="zoom"> * <agm-data-layer [geoJson]="geoJsonObject" (layerClick)="clicked($event)" [style]="styleFunc"> * </agm-data-layer> * </agm-map> * ` * }) * export class MyMapCmp { * lat: number = -25.274449; * lng: number = 133.775060; * zoom: number = 5; * * clicked(clickEvent) { * console.log(clickEvent); * } * * styleFunc(feature) { * return ({ * clickable: false, * fillColor: feature.getProperty('color'), * strokeWeight: 1 * }); * } * * geoJsonObject: Object = { * "type": "FeatureCollection", * "features": [ * { * "type": "Feature", * "properties": { * "letter": "G", * "color": "blue", * "rank": "7", * "ascii": "71" * }, * "geometry": { * "type": "Polygon", * "coordinates": [ * [ * [123.61, -22.14], [122.38, -21.73], [121.06, -21.69], [119.66, -22.22], [119.00, -23.40], * [118.65, -24.76], [118.43, -26.07], [118.78, -27.56], [119.22, -28.57], [120.23, -29.49], * [121.77, -29.87], [123.57, -29.64], [124.45, -29.03], [124.71, -27.95], [124.80, -26.70], * [124.80, -25.60], [123.61, -25.64], [122.56, -25.64], [121.72, -25.72], [121.81, -26.62], * [121.86, -26.98], [122.60, -26.90], [123.57, -27.05], [123.57, -27.68], [123.35, -28.18], * [122.51, -28.38], [121.77, -28.26], [121.02, -27.91], [120.49, -27.21], [120.14, -26.50], * [120.10, -25.64], [120.27, -24.52], [120.67, -23.68], [121.72, -23.32], [122.43, -23.48], * [123.04, -24.04], [124.54, -24.28], [124.58, -23.20], [123.61, -22.14] * ] * ] * } * }, * { * "type": "Feature", * "properties": { * "letter": "o", * "color": "red", * "rank": "15", * "ascii": "111" * }, * "geometry": { * "type": "Polygon", * "coordinates": [ * [ * [128.84, -25.76], [128.18, -25.60], [127.96, -25.52], [127.88, -25.52], [127.70, -25.60], * [127.26, -25.79], [126.60, -26.11], [126.16, -26.78], [126.12, -27.68], [126.21, -28.42], * [126.69, -29.49], [127.74, -29.80], [128.80, -29.72], [129.41, -29.03], [129.72, -27.95], * [129.68, -27.21], [129.33, -26.23], [128.84, -25.76] * ], * [ * [128.45, -27.44], [128.32, -26.94], [127.70, -26.82], [127.35, -27.05], [127.17, -27.80], * [127.57, -28.22], [128.10, -28.42], [128.49, -27.80], [128.45, -27.44] * ] * ] * } * }, * { * "type": "Feature", * "properties": { * "letter": "o", * "color": "yellow", * "rank": "15", * "ascii": "111" * }, * "geometry": { * "type": "Polygon", * "coordinates": [ * [ * [131.87, -25.76], [131.35, -26.07], [130.95, -26.78], [130.82, -27.64], [130.86, -28.53], * [131.26, -29.22], [131.92, -29.76], [132.45, -29.87], [133.06, -29.76], [133.72, -29.34], * [134.07, -28.80], [134.20, -27.91], [134.07, -27.21], [133.81, -26.31], [133.37, -25.83], * [132.71, -25.64], [131.87, -25.76] * ], * [ * [133.15, -27.17], [132.71, -26.86], [132.09, -26.90], [131.74, -27.56], [131.79, -28.26], * [132.36, -28.45], [132.93, -28.34], [133.15, -27.76], [133.15, -27.17] * ] * ] * } * }, * { * "type": "Feature", * "properties": { * "letter": "g", * "color": "blue", * "rank": "7", * "ascii": "103" * }, * "geometry": { * "type": "Polygon", * "coordinates": [ * [ * [138.12, -25.04], [136.84, -25.16], [135.96, -25.36], [135.26, -25.99], [135, -26.90], * [135.04, -27.91], [135.26, -28.88], [136.05, -29.45], [137.02, -29.49], [137.81, -29.49], * [137.94, -29.99], [137.90, -31.20], [137.85, -32.24], [136.88, -32.69], [136.45, -32.36], * [136.27, -31.80], [134.95, -31.84], [135.17, -32.99], [135.52, -33.43], [136.14, -33.76], * [137.06, -33.83], [138.12, -33.65], [138.86, -33.21], [139.30, -32.28], [139.30, -31.24], * [139.30, -30.14], [139.21, -28.96], [139.17, -28.22], [139.08, -27.41], [139.08, -26.47], * [138.99, -25.40], [138.73, -25.00], [138.12, -25.04] * ], * [ * [137.50, -26.54], [136.97, -26.47], [136.49, -26.58], [136.31, -27.13], [136.31, -27.72], * [136.58, -27.99], [137.50, -28.03], [137.68, -27.68], [137.59, -26.78], [137.50, -26.54] * ] * ] * } * }, * { * "type": "Feature", * "properties": { * "letter": "l", * "color": "green", * "rank": "12", * "ascii": "108" * }, * "geometry": { * "type": "Polygon", * "coordinates": [ * [ * [140.14, -21.04], [140.31, -29.42], [141.67, -29.49], [141.59, -20.92], [140.14, -21.04] * ] * ] * } * }, * { * "type": "Feature", * "properties": { * "letter": "e", * "color": "red", * "rank": "5", * "ascii": "101" * }, * "geometry": { * "type": "Polygon", * "coordinates": [ * [ * [144.14, -27.41], [145.67, -27.52], [146.86, -27.09], [146.82, -25.64], [146.25, -25.04], * [145.45, -24.68], [144.66, -24.60], [144.09, -24.76], [143.43, -25.08], [142.99, -25.40], * [142.64, -26.03], [142.64, -27.05], [142.64, -28.26], [143.30, -29.11], [144.18, -29.57], * [145.41, -29.64], [146.46, -29.19], [146.64, -28.72], [146.82, -28.14], [144.84, -28.42], * [144.31, -28.26], [144.14, -27.41] * ], * [ * [144.18, -26.39], [144.53, -26.58], [145.19, -26.62], [145.72, -26.35], [145.81, -25.91], * [145.41, -25.68], [144.97, -25.68], [144.49, -25.64], [144, -25.99], [144.18, -26.39] * ] * ] * } * } * ] * }; * } * ``` */ var AgmDataLayer = /** @class */ (function () { function AgmDataLayer(_manager) { th