-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.google.js
95 lines (85 loc) · 2.78 KB
/
maps.google.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
/* eslint-disable no-unused-vars */
/* eslint-env browser*/
/*global Map, google
*/
var GoogleMaps = function (container) {
"use strict";
Map.call(this, container);
var version = '3.29',
callback = 'map.start',
key = '',
clientId = '';
this.types = {hybrid: 'hybrid',
road: 'roadmap',
satellite: 'satellite',
terrain: 'terrain'};
this.run = function () {
var script = 'https://maps.google.com/maps/api/js?v=' + version + '&callback=' + callback + '&language=pt_br&libraries=geometry';
if ((this.clientId !== undefined) && (this.clientId !== '')) {
script += '&client=' + this.clientId;
} else if ((this.key !== undefined) && (this.clientId !== '')) {
script += '&key=' + this.key;
}
this.addScript(script);
};
this.start = function () {
var container = document.getElementById(this.container);
this.map = new google.maps.Map(container, {
center: {lat: 0, lng: 0},
zoom: 3
});
this.data.started = true;
if (!this.data.loaded) {
this.data.loader();
}
};
this.addInfo = function (geojson) {
var itens = this.map.data.addGeoJson(geojson),
i = 0,
length = itens.length,
item,
info,
type,
infowindow = new google.maps.InfoWindow(),
setStyle = function (item) {
return item.f;
};
for (i = 0; i < length; i += 1) {
item = itens[i];
info = item.f;
type = item.getGeometry().getType();
if (type === 'Point') {
if ((info.text === null) || (info.text === '')) {
info.text = info.title;
} else if ((info.title === null) || (info.title === '')) {
info.title = info.text.replace(/(<([^>]+)>)/ig, '');
}
this.addOnClick(info);
}
}
this.map.data.setStyle(function (feature) {
return {icon: feature.getProperty('icon')};
});
this.map.data.addListener('click', function (event) {
var type = event.feature.getGeometry().getType();
if (type === 'Point') {
infowindow.setContent(event.feature.getProperty("text"));
infowindow.setPosition(event.feature.getGeometry().get());
infowindow.setOptions({pixelOffset: new google.maps.Size(0, -30)});
infowindow.open(this.map);
}
});
};
this.addOnClick = function (info) {
var infowindow = new google.maps.InfoWindow({
content: info.title
});
};
this.setCenter = function (latlng, zoom) {
this.map.setCenter(latlng);
this.map.setZoom(zoom);
};
this.setType = function (type) {
this.map.setMapTypeId(type);
};
};