forked from j20mc/Nativescript-Danem-Google-Maps-Utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ios.js
182 lines (156 loc) · 6.94 KB
/
index.ios.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var _mapView = {};
var heatmaps = {}
const imageSourceModule = require("tns-core-modules/image-source");
const Image = require('@nativescript/core/ui/image');
const utilsModule = require("tns-core-modules/utils/utils");
/***************************************** CLUSTERING *****************************************/
var GMUClusterManagerDelegateImpl = (function (_super) {
__extends(GMUClusterManagerDelegateImpl, _super);
/**
* init @Class
*/
function GMUClusterManagerDelegateImpl() {
var _this = _super !== null && _super.apply(this, arguments) || this;
return _this;
}
GMUClusterManagerDelegateImpl.initWithMapAlgorithmRenderer = function (mapView, algorithm, renderer, owner) {
var delegate = GMUClusterManagerDelegateImpl.new();
delegate._mapView = mapView;
delegate._algorithm = algorithm;
delegate._renderer = renderer
delegate._owner = owner
return delegate;
}
GMUClusterManagerDelegateImpl.prototype.clusterManagerDidTapClusterItem = function (clusterManager, poiItem) {
var owner = this._owner.get();
_mapView.notifyMarkerTapped(poiItem);
return false;
};
GMUClusterManagerDelegateImpl.prototype.clusterManagerDidTapCluster = function (clusterManager, cluster) {
var owner = this._owner.get();
var nsArray = cluster.items;
var listeMarker = utilsModule.ios.collections.nsArrayToJSArray(nsArray);
_mapView.notifyMarkerTapped(listeMarker);
return false;
};
GMUClusterManagerDelegateImpl.ObjCProtocols = [GMUClusterManagerDelegate];
return GMUClusterManagerDelegateImpl;
}(NSObject));
/**
* Delegate for id<GMUClusterRenderer> to provide extra functionality to the default
* renderer.
*/
var GMUClusterRendererDelegateImpl = (function (_super) {
__extends(GMUClusterRendererDelegateImpl, _super);
/**
* init @Class
*/
function GMUClusterRendererDelegateImpl() {
var _this = _super !== null && _super.apply(this, arguments) || this;
return _this;
}
/**
* Creates a new cluster renderer with a given map view and icon generator.
*
* @param mapView The map view to use.
* @param iconGenerator The icon generator to use. Can be subclassed if required.
*/
GMUClusterRendererDelegateImpl.initWithMapViewClusterIconGenerator = function (mapView, iconGenerator, owner) {
var delegate = GMUClusterRendererDelegateImpl.new();
delegate._mapView = mapView;
delegate._iconGenerator = iconGenerator;
delegate._owner = owner;
return delegate;
};
/**
* Raised when a marker (for a cluster or an item) is about to be added to the map.
* Use the marker.userData property to check whether it is a cluster marker or an
* item marker.
*/
GMUClusterRendererDelegateImpl.prototype.rendererWillRenderMarker = function (renderer, marker) {
var owner = this._owner.get();
if (marker.userData instanceof POIItem) {
var mIcon = Image;
mIcon.imageSource = imageSourceModule.fromResource(marker.userData.imageUrl);
marker.icon = mIcon.imageSource.ios;
//marker.title = "test"
} else {
// cluster marker
}
};
GMUClusterRendererDelegateImpl.ObjCProtocols = [GMUClusterRendererDelegate];
return GMUClusterRendererDelegateImpl;
}(NSObject));
function moveCamera(latitude, longitude, zoom) {
let cameraUpdate = GMSCameraPosition.alloc().initWithLatitudeLongitudeZoom(latitude, longitude, zoom)
_mapView.nativeView.animateToCameraPosition(cameraUpdate)
}
exports.moveCamera = moveCamera;
function clearMap() {
_mapView.gMap.clear();
_mapView = {};
}
exports.clearMap = clearMap;
function setupMarkerCluster(mapView, markers) {
_mapView = mapView;
console.log("*** init ios map view: ");
var iconGenerator = GMUDefaultClusterIconGenerator.alloc().init();
var algorithm = GMUNonHierarchicalDistanceBasedAlgorithm.alloc().init();
var renderer = GMUDefaultClusterRenderer.alloc().initWithMapViewClusterIconGenerator(mapView.nativeView, iconGenerator)
var clusterManager = GMUClusterManager.alloc().initWithMapAlgorithmRenderer(mapView.nativeView, algorithm, renderer)
var clusterManagerDelegate = GMUClusterManagerDelegateImpl.initWithMapAlgorithmRenderer(mapView.nativeView, algorithm, renderer, new WeakRef(this))
clusterManager.clearItems();
clusterManager.setDelegateMapDelegate(clusterManagerDelegate, mapView);
var rendererDelegate = GMUClusterRendererDelegateImpl.initWithMapViewClusterIconGenerator(mapView.nativeView, iconGenerator, new WeakRef(this))
renderer.delegate = rendererDelegate;
console.log(_mapView)
console.log("clusterManagerDelegate", clusterManagerDelegate)
console.log("rendererDelegate", rendererDelegate)
console.log("GMUDefaultClusterIconGenerator", iconGenerator instanceof GMUDefaultClusterIconGenerator, iconGenerator); // true
console.log("GMUNonHierarchicalDistanceBasedAlgorithm ", algorithm instanceof GMUNonHierarchicalDistanceBasedAlgorithm, algorithm); // true
console.log("GMUDefaultClusterRenderer : ", renderer instanceof GMUDefaultClusterRenderer, renderer); // true
console.log("GMUClusterManager : ", clusterManager instanceof GMUClusterManager, clusterManager); // true
for (var i = 0; i < markers.length; i++) {
var clusterItem = POIItem.alloc().initWithPositionNameImageUrlTitle(markers[i].position.ios, markers[i].userData, markers[i].infoWindowTemplate, markers[i].title)
clusterManager.addItem(clusterItem)
if (i === markers.length - 1) {
clusterManager.cluster();
}
}
}
exports.setupMarkerCluster = setupMarkerCluster;
/***************************************** HEATMAP *****************************************/
function setupHeatmap(mapView, positions, colors, startPoints) {
var listHeatMap = [];
heatmaps = GMUHeatmapTileLayer.alloc();
console.log("GMUHeatmapTileLayer : ", heatmaps instanceof GMUHeatmapTileLayer, heatmaps); // true
heatmaps.radius = 80
heatmaps.opacity = 0.8
heatmaps.gradient = GMUGradient.alloc().initWithColorsStartPointsColorMapSize(
[colors[0].ios, colors[1].ios],
[startPoints[0], startPoints[1]],
256)
positions.forEach(function (position) {
var coords = GMUWeightedLatLng.alloc().initWithCoordinateIntensity(position.ios, 1.0)
listHeatMap.push(coords)
});
heatmaps.weightedData = listHeatMap;
heatmaps.map = mapView.gMap;
return heatmaps
}
exports.setupHeatmap = setupHeatmap;
function setOpacity(value) {
heatmaps.opacity = value
}
exports.setOpacity = setOpacity;
function setRadius(value) {
heatmaps.radius = value
}
exports.setRadius = setRadius;
function removeHeatmap() {
heatmaps.map = null
}
exports.removeHeatmap = removeHeatmap;
//# sourceMappingURL=index.ios.js.map