@agm/core
Version:
Angular components for Google Maps
1,123 lines (1,110 loc) • 193 kB
JavaScript
(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/core', ['exports', '@angular/core', 'rxjs', 'rxjs/operators', '@angular/common'], factory) :
(global = global || self, factory((global.agm = global.agm || {}, global.agm.core = {}), global.ng.core, global.rxjs, global.rxjs.operators, global.ng.common));
}(this, (function (exports, i0, 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 __());
}
var __assign = function () {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s)
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
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 };
}
}
var __createBinding = Object.create ? (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
}) : (function (o, m, k, k2) {
if (k2 === undefined)
k2 = k;
o[k2] = m[k];
});
function __exportStar(m, exports) {
for (var p in m)
if (p !== "default" && !exports.hasOwnProperty(p))
__createBinding(exports, m, p);
}
function __values(o) {
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m)
return m.call(o);
if (o && typeof o.length === "number")
return {
next: function () {
if (o && i >= o.length)
o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
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;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
}
;
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n])
i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try {
step(g[n](v));
}
catch (e) {
settle(q[0][3], e);
} }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length)
resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator)
throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function (v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) {
Object.defineProperty(cooked, "raw", { value: raw });
}
else {
cooked.raw = raw;
}
return cooked;
}
;
var __setModuleDefault = Object.create ? (function (o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function (o, v) {
o["default"] = v;
};
function __importStar(mod) {
if (mod && mod.__esModule)
return mod;
var result = {};
if (mod != null)
for (var k in mod)
if (Object.hasOwnProperty.call(mod, k))
__createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
var MapsAPILoader = /** @class */ (function () {
function MapsAPILoader() {
}
return MapsAPILoader;
}());
MapsAPILoader.decorators = [
{ type: i0.Injectable }
];
/**
* 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) {
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
* @returns a new transit layer object
*/
GoogleMapsAPIWrapper.prototype.createTransitLayer = function () {
var _this = this;
return this._zone.runOutsideAngular(function () {
return _this._map.then(function (map) {
var newLayer = new google.maps.TransitLayer();
newLayer.setMap(map);
return newLayer;
});
});
};
/**
* Creates a BicyclingLayer instance for a map
* @returns a new bicycling layer object
*/
GoogleMapsAPIWrapper.prototype.createBicyclingLayer = function () {
var _this = this;
return this._zone.runOutsideAngular(function () {
return _this._map.then(function (map) {
var newLayer = new google.maps.BicyclingLayer();
newLayer.setMap(map);
return newLayer;
});
});
};
/**
* Determines if given coordinates are insite a Polygon path.
*/
GoogleMapsAPIWrapper.prototype.containsLocation = function (latLng, polygon) {
return this._map.then(function () { 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) { return m.addListener(eventName, function () { return _this._zone.run(function () { return observer.next(arguments[0]); }); }); });
});
};
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); });
};
return GoogleMapsAPIWrapper;
}());
GoogleMapsAPIWrapper.decorators = [
{ type: i0.Injectable }
];
GoogleMapsAPIWrapper.ctorParameters = function () { return [
{ type: MapsAPILoader },
{ type: i0.NgZone }
]; };
var CircleManager = /** @class */ (function () {
function CircleManager(_apiWrapper, _zone) {
this._apiWrapper = _apiWrapper;
this._zone = _zone;
this._circles = new Map();
}
CircleManager.prototype.addCircle = function (circle) {
var _this = this;
this._apiWrapper.getNativeMap().then(function () { return _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: google.maps.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 __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
return [2 /*return*/, this._circles.get(circle).then(function (c) {
var actualParam = options.strokePosition;
options.strokePosition = google.maps.StrokePosition[actualParam];
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();
}
};
});
};
return CircleManager;
}());
CircleManager.decorators = [
{ type: i0.Injectable }
];
CircleManager.ctorParameters = function () { return [
{ type: GoogleMapsAPIWrapper },
{ type: i0.NgZone }
]; };
/**
* 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) {
// NOTE: accessing "features" on google.maps.Data is undocumented
_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);
// NOTE: accessing "features" on google.maps.Data is undocumented
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");
}
});
};
return DataLayerManager;
}());
DataLayerManager.decorators = [
{ type: i0.Injectable }
];
DataLayerManager.ctorParameters = function () { return [
{ type: GoogleMapsAPIWrapper },
{ type: i0.NgZone }
]; };
/**
* Class to implement when you what to be able to make it work with the auto fit bounds feature
* of AGM.
*/
var FitBoundsAccessor = /** @class */ (function () {
function FitBoundsAccessor() {
}
return FitBoundsAccessor;
}());
/**
* The FitBoundsService is responsible for computing the bounds of the a single map.
*/
var FitBoundsService = /** @class */ (function () {
function FitBoundsService(loader) {
var _this = this;
this._boundsChangeSampleTime$ = new rxjs.BehaviorSubject(200);
this._includeInBounds$ = new rxjs.BehaviorSubject(new Map());
this.bounds$ = rxjs.from(loader.load()).pipe(operators.flatMap(function () { return _this._includeInBounds$; }), operators.sample(this._boundsChangeSampleTime$.pipe(operators.switchMap(function (time) { return rxjs.timer(0, time); }))), operators.map(function (includeInBounds) { return _this._generateBounds(includeInBounds); }), operators.shareReplay(1));
}
FitBoundsService.prototype._generateBounds = function (includeInBounds) {
var bounds = new google.maps.LatLngBounds();
includeInBounds.forEach(function (b) { return bounds.extend(b); });
return bounds;
};
FitBoundsService.prototype.addToBounds = function (latLng) {
var id = this._createIdentifier(latLng);
if (this._includeInBounds$.value.has(id)) {
return;
}
var boundsMap = this._includeInBounds$.value;
boundsMap.set(id, latLng);
this._includeInBounds$.next(boundsMap);
};
FitBoundsService.prototype.removeFromBounds = function (latLng) {
var boundsMap = this._includeInBounds$.value;
boundsMap.delete(this._createIdentifier(latLng));
this._includeInBounds$.next(boundsMap);
};
FitBoundsService.prototype.changeFitBoundsChangeSampleTime = function (timeMs) {
this._boundsChangeSampleTime$.next(timeMs);
};
FitBoundsService.prototype.getBounds$ = function () {
return this.bounds$;
};
FitBoundsService.prototype._createIdentifier = function (latLng) {
return latLng.lat + "+" + latLng.lng;
};
return FitBoundsService;
}());
FitBoundsService.decorators = [
{ type: i0.Injectable }
];
FitBoundsService.ctorParameters = function () { return [
{ type: MapsAPILoader }
]; };
var AgmGeocoder = /** @class */ (function () {
function AgmGeocoder(loader) {
var _this = this;
var connectableGeocoder$ = new rxjs.Observable(function (subscriber) {
loader.load().then(function () { return subscriber.next(); });
})
.pipe(operators.map(function () { return _this._createGeocoder(); }), operators.multicast(new rxjs.ReplaySubject(1)));
connectableGeocoder$.connect(); // ignore the subscription
// since we will remain subscribed till application exits
this.geocoder$ = connectableGeocoder$;
}
AgmGeocoder.prototype.geocode = function (request) {
var _this = this;
return this.geocoder$.pipe(operators.switchMap(function (geocoder) { return _this._getGoogleResults(geocoder, request); }));
};
AgmGeocoder.prototype._getGoogleResults = function (geocoder, request) {
var geocodeObservable = rxjs.bindCallback(geocoder.geocode);
return geocodeObservable(request).pipe(operators.switchMap(function (_a) {
var _b = __read(_a, 2), results = _b[0], status = _b[1];
if (status === google.maps.GeocoderStatus.OK) {
return rxjs.of(results);
}
return rxjs.throwError(status);
}));
};
AgmGeocoder.prototype._createGeocoder = function () {
return new google.maps.Geocoder();
};
return AgmGeocoder;
}());
AgmGeocoder.ɵprov = i0.ɵɵdefineInjectable({ factory: function AgmGeocoder_Factory() { return new AgmGeocoder(i0.ɵɵinject(MapsAPILoader)); }, token: AgmGeocoder, providedIn: "root" });
AgmGeocoder.decorators = [
{ type: i0.Injectable, args: [{ providedIn: 'root' },] }
];
AgmGeocoder.ctorParameters = function () { return [
{ type: MapsAPILoader }
]; };
var WindowRef = /** @class */ (function () {
function WindowRef() {
}
WindowRef.prototype.getNativeWindow = function () { return window; };
return WindowRef;
}());
var DocumentRef = /** @class */ (function () {
function DocumentRef() {
}
DocumentRef.prototype.getNativeDocument = function () { return document; };
return DocumentRef;
}());
var BROWSER_GLOBALS_PROVIDERS = [WindowRef, DocumentRef];
(function (GoogleMapsScriptProtocol) {
GoogleMapsScriptProtocol[GoogleMapsScriptProtocol["HTTP"] = 1] = "HTTP";
GoogleMapsScriptProtocol[GoogleMapsScriptProtocol["HTTPS"] = 2] = "HTTPS";
GoogleMapsScriptProtocol[GoogleMapsScriptProtocol["AUTO"] = 3] = "AUTO";
})(exports.GoogleMapsScriptProtocol || (exports.GoogleMapsScriptProtocol = {}));
/**
* Token for the config of the LazyMapsAPILoader. Please provide an object of type {@link
* LazyMapsAPILoaderConfig}.
*/
var LAZY_MAPS_API_CONFIG = new i0.InjectionToken('angular-google-maps LAZY_MAPS_API_CONFIG');
var LazyMapsAPILoader = /** @class */ (function (_super) {
__extends(LazyMapsAPILoader, _super);
function LazyMapsAPILoader(config, w, d, localeId) {
if (config === void 0) { config = null; }
var _this = _super.call(this) || this;
_this.localeId = localeId;
_this._SCRIPT_ID = 'agmGoogleMapsApiScript';
_this.callbackName = "agmLazyMapsAPILoader";
_this._config = config || {};
_this._windowRef = w;
_this._documentRef = d;
return _this;
}
LazyMapsAPILoader.prototype.load = function () {
var window = this._windowRef.getNativeWindow();
if (window.google && window.google.maps) {
// Google maps already loaded on the page.
return Promise.resolve();
}
if (this._scriptLoadingPromise) {
return this._scriptLoadingPromise;
}
// this can happen in HMR situations or Stackblitz.io editors.
var scriptOnPage = this._documentRef.getNativeDocument().getElementById(this._SCRIPT_ID);
if (scriptOnPage) {
this._assignScriptLoadingPromise(scriptOnPage);
return this._scriptLoadingPromise;
}
var script = this._documentRef.getNativeDocument().createElement('script');
script.type = 'text/javascript';
script.async = true;
script.defer = true;
script.id = this._SCRIPT_ID;
script.src = this._getScriptSrc(this.callbackName);
this._assignScriptLoadingPromise(script);
this._documentRef.getNativeDocument().body.appendChild(script);
return this._scriptLoadingPromise;
};
LazyMapsAPILoader.prototype._assignScriptLoadingPromise = function (scriptElem) {
var _this = this;
this._scriptLoadingPromise = new Promise(function (resolve, reject) {
_this._windowRef.getNativeWindow()[_this.callbackName] = function () {
resolve();
};
scriptElem.onerror = function (error) {
reject(error);
};
});
};
LazyMapsAPILoader.prototype._getScriptSrc = function (callbackName) {
var protocolType = (this._config && this._config.protocol) || exports.GoogleMapsScriptProtocol.HTTPS;
var protocol;
switch (protocolType) {
case exports.GoogleMapsScriptProtocol.AUTO:
protocol = '';
break;
case exports.GoogleMapsScriptProtocol.HTTP:
protocol = 'http:';
break;
case exports.GoogleMapsScriptProtocol.HTTPS:
protocol = 'https:';
break;
}
var hostAndPath = this._config.hostAndPath || 'maps.googleapis.com/maps/api/js';
var queryParams = {
v: this._config.apiVersion || 'quarterly',
callback: callbackName,
key: this._config.apiKey,
client: this._config.clientId,
channel: this._config.channel,
libraries: this._config.libraries,
region: this._config.region,
language: this._config.language || (this.localeId !== 'en-US' ? this.localeId : null),
};
var params = Object.keys(queryParams)
.filter(function (k) { return queryParams[k] != null; })
.filter(function (k) {
// remove empty arrays
return !Array.isArray(queryParams[k]) ||
(Array.isArray(queryParams[k]) && queryParams[k].length > 0);
})
.map(function (k) {
// join arrays as comma seperated strings
var i = queryParams[k];
if (Array.isArray(i)) {
return { key: k, value: i.join(',') };
}
return { key: k, value: queryParams[k] };
})
.map(function (entry) {
return entry.key + "=" + entry.value;
})
.join('&');
return protocol + "//" + hostAndPath + "?" + params;
};
return LazyMapsAPILoader;
}(MapsAPILoader));
LazyMapsAPILoader.decorators = [
{ type: i0.Injectable }
];
LazyMapsAPILoader.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: i0.Optional }, { type: i0.Inject, args: [LAZY_MAPS_API_CONFIG,] }] },
{ type: WindowRef },
{ type: DocumentRef },
{ type: String, decorators: [{ type: i0.Inject, args: [i0.LOCALE_ID,] }] }
]; };
var MarkerManager = /** @class */ (function () {
function MarkerManager(_mapsWrapper, _zone) {
this._mapsWrapper = _mapsWrapper;
this._zone = _zone;
this._markers = new Map();
}
MarkerManager.prototype.convertAnimation = function (uiAnim) {
return __awaiter(this, void 0, void 0, function () {
return __generator(this, function (_a) {
if (uiAnim === null) {
return [2 /*return*/, null];
}
else {
return [2 /*return*/, this._mapsWrapper.getNativeMap().then(function () { return google.maps.Animation[uiAnim]; })];
}
return [2 /*return*/];
});
});
};
MarkerManager.prototype.deleteMarker = function (markerDirective) {
var _this = this;
var markerPromise = this._markers.get(markerDirective);
if (markerPromise == null) {
// marker already deleted
return Promise.resolve();
}
return markerPromise.then(function (marker) {
return _this._zone.run(function () {
marker.setMap(null);
_this._markers.delete(markerDirective);
});
});
};
MarkerManager.prototype.updateMarkerPosition = function (marker) {
return this._markers.get(marker).then(function (m) { return m.setPosition({ lat: marker.latitude, lng: marker.longitude }); });
};
MarkerManager.prototype.updateTitle = function (marker) {
return this._markers.get(marker).then(function (m) { return m.setTitle(marker.title); });
};
MarkerManager.prototype.updateLabel = function (marker) {
return this._markers.get(marker).then(function (m) { m.setLabel(marker.label); });
};
MarkerManager.prototype.updateDraggable = function (marker) {
return this._markers.get(marker).then(function (m) { return m.setDraggable(marker.draggable); });
};
MarkerManager.prototype.updateIcon = function (marker) {
return this._markers.get(marker).then(function (m) { return m.setIcon(marker.iconUrl); });
};
MarkerManager.prototype.updateOpacity = function (marker) {
return this._markers.get(marker).then(function (m) { return m.setOpacity(marker.opacity); });
};
MarkerManager.prototype.updateVisible = function (marker) {
return this._markers.get(marker).then(function (m) { return m.setVisible(marker.visible); });
};
MarkerManager.prototype.updateZIndex = function (marker) {
return this._markers.get(marker).then(function (m) { return m.setZIndex(marker.zIndex); });
};
MarkerManager.prototype.updateClickable = function (marker) {
return this._markers.get(marker).then(function (m) { return m.setClickable(marker.clickable); });
};
MarkerManager.prototype.updateAnimation = function (marker) {
return __awaiter(this, void 0, void 0, function () {
var m, _a, _b;
return __generator(this, function (_c) {
switch (_c.label) {
case 0: return [4 /*yield*/, this._markers.get(marker)];
case 1:
m = _c.sent();
_b = (_a = m).setAnimation;
return [4 /*yield*/, this.convertAnimation(marker.animation)];
case 2:
_b.apply(_a, [_c.sent()]);
return [2 /*return*/];
}
});
});
};
MarkerManager.prototype.addMarker = function (marker) {
var _this = this;
var markerPromise = new Promise(function (resolve) { return __awaiter(_this, void 0, void 0, function () {
var _a, _b, _c;
return __generator(this, function (_d) {
switch (_d.label) {
case 0:
_b = (_a = this._mapsWrapper).createMarker;
_c = {
position: { lat: marker.latitude, lng: marker.longitude },
label: marker.label,
draggable: marker.draggable,
icon: marker.iconUrl,
opacity: marker.opacity,
visible: marker.visible,
zIndex: marker.zIndex,
title: marker.title,
clickable: marker.clickable
};
return [4 /*yield*/, this.convertAnimation(marker.animation)];
case 1: return [2 /*return*/, _b.apply(_a, [(_c.animation = _d.sent(),
_c)]).then(resolve)];
}
});
}); });
this._markers.set(marker, markerPromise);
};
MarkerManager.prototype.getNativeMarker = function (marker) {
return this._markers.get(marker);
};
MarkerManager.prototype.createEventObservable = function (eventName, marker) {
var _this = this;
return new rxjs.Observable(function (observer) {
_this._markers.get(marker).then(function (m) { return m.addListener(eventName, function (e) { return _this._zone.run(function () { return observer.next(e); }); }); });
});
};
return MarkerManager;
}());
MarkerManager.decorators = [
{ type: i0.Injectable }
];
MarkerManager.ctorParameters = function () { return [
{ type: GoogleMapsAPIWrapper },
{ type: i0.NgZone }
]; };
var InfoWindowManager = /** @class */ (function () {
function InfoWindowManager(_mapsWrapper, _zone, _markerManager) {
this._mapsWrapper = _mapsWrapper;
this._zone = _zone;
this._markerManager = _markerManager;
this._infoWindows = new Map();
}
InfoWindowManager.prototype.deleteInfoWindow = function (infoWindow) {
var _this = this;
var iWindow = this._infoWindows.get(infoWindow);
if (iWindow == null) {
// info window already deleted
return Promise.resolve();
}
return iWindow.then(function (i) {
return _this._zone.run(function () {
i.close();
_this._infoWindows.delete(infoWindow);
});
});
};
InfoWindowManager.prototype.setPosition = function (infoWindow) {
return this._infoWindows.get(infoWindow).then(function (i) { return i.setPosition({
lat: infoWindow.latitude,
lng: infoWindow.longitude,
}); });
};
InfoWindowManager.prototype.setZIndex = function (infoWind