1 | "use strict";
|
2 | var core_1 = require('@angular/core');
|
3 | var Observable_1 = require('rxjs/Observable');
|
4 | var maps_api_loader_1 = require('./maps-api-loader/maps-api-loader');
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var GoogleMapsAPIWrapper = (function () {
|
10 | function GoogleMapsAPIWrapper(_loader, _zone) {
|
11 | var _this = this;
|
12 | this._loader = _loader;
|
13 | this._zone = _zone;
|
14 | this._map =
|
15 | new Promise(function (resolve) { _this._mapResolver = resolve; });
|
16 | }
|
17 | GoogleMapsAPIWrapper.prototype.createMap = function (el, mapOptions) {
|
18 | var _this = this;
|
19 | return this._loader.load().then(function () {
|
20 | var map = new google.maps.Map(el, mapOptions);
|
21 | _this._mapResolver(map);
|
22 | return;
|
23 | });
|
24 | };
|
25 | GoogleMapsAPIWrapper.prototype.setMapOptions = function (options) {
|
26 | this._map.then(function (m) { m.setOptions(options); });
|
27 | };
|
28 | |
29 |
|
30 |
|
31 | GoogleMapsAPIWrapper.prototype.createMarker = function (options) {
|
32 | if (options === void 0) { options = {}; }
|
33 | return this._map.then(function (map) {
|
34 | options.map = map;
|
35 | return new google.maps.Marker(options);
|
36 | });
|
37 | };
|
38 | GoogleMapsAPIWrapper.prototype.createInfoWindow = function (options) {
|
39 | return this._map.then(function () { return new google.maps.InfoWindow(options); });
|
40 | };
|
41 | |
42 |
|
43 |
|
44 | GoogleMapsAPIWrapper.prototype.createCircle = function (options) {
|
45 | return this._map.then(function (map) {
|
46 | options.map = map;
|
47 | return new google.maps.Circle(options);
|
48 | });
|
49 | };
|
50 | GoogleMapsAPIWrapper.prototype.createPolyline = function (options) {
|
51 | return this.getNativeMap().then(function (map) {
|
52 | var line = new google.maps.Polyline(options);
|
53 | line.setMap(map);
|
54 | return line;
|
55 | });
|
56 | };
|
57 | GoogleMapsAPIWrapper.prototype.createPolygon = function (options) {
|
58 | return this.getNativeMap().then(function (map) {
|
59 | var polygon = new google.maps.Polygon(options);
|
60 | polygon.setMap(map);
|
61 | return polygon;
|
62 | });
|
63 | };
|
64 | |
65 |
|
66 |
|
67 | GoogleMapsAPIWrapper.prototype.containsLocation = function (latLng, polygon) {
|
68 | return google.maps.geometry.poly.containsLocation(latLng, polygon);
|
69 | };
|
70 | GoogleMapsAPIWrapper.prototype.subscribeToMapEvent = function (eventName) {
|
71 | var _this = this;
|
72 | return Observable_1.Observable.create(function (observer) {
|
73 | _this._map.then(function (m) {
|
74 | m.addListener(eventName, function (arg) { _this._zone.run(function () { return observer.next(arg); }); });
|
75 | });
|
76 | });
|
77 | };
|
78 | GoogleMapsAPIWrapper.prototype.setCenter = function (latLng) {
|
79 | return this._map.then(function (map) { return map.setCenter(latLng); });
|
80 | };
|
81 | GoogleMapsAPIWrapper.prototype.getZoom = function () { return this._map.then(function (map) { return map.getZoom(); }); };
|
82 | GoogleMapsAPIWrapper.prototype.getBounds = function () {
|
83 | return this._map.then(function (map) { return map.getBounds(); });
|
84 | };
|
85 | GoogleMapsAPIWrapper.prototype.setZoom = function (zoom) {
|
86 | return this._map.then(function (map) { return map.setZoom(zoom); });
|
87 | };
|
88 | GoogleMapsAPIWrapper.prototype.getCenter = function () {
|
89 | return this._map.then(function (map) { return map.getCenter(); });
|
90 | };
|
91 | GoogleMapsAPIWrapper.prototype.panTo = function (latLng) {
|
92 | return this._map.then(function (map) { return map.panTo(latLng); });
|
93 | };
|
94 | GoogleMapsAPIWrapper.prototype.fitBounds = function (latLng) {
|
95 | return this._map.then(function (map) { return map.fitBounds(latLng); });
|
96 | };
|
97 | GoogleMapsAPIWrapper.prototype.panToBounds = function (latLng) {
|
98 | return this._map.then(function (map) { return map.panToBounds(latLng); });
|
99 | };
|
100 | |
101 |
|
102 |
|
103 | GoogleMapsAPIWrapper.prototype.getNativeMap = function () { return this._map; };
|
104 | |
105 |
|
106 |
|
107 | GoogleMapsAPIWrapper.prototype.triggerMapEvent = function (eventName) {
|
108 | return this._map.then(function (m) { return google.maps.event.trigger(m, eventName); });
|
109 | };
|
110 | GoogleMapsAPIWrapper.decorators = [
|
111 | { type: core_1.Injectable },
|
112 | ];
|
113 |
|
114 | GoogleMapsAPIWrapper.ctorParameters = function () { return [
|
115 | { type: maps_api_loader_1.MapsAPILoader, },
|
116 | { type: core_1.NgZone, },
|
117 | ]; };
|
118 | return GoogleMapsAPIWrapper;
|
119 | }());
|
120 | exports.GoogleMapsAPIWrapper = GoogleMapsAPIWrapper;
|
121 |
|
\ | No newline at end of file |