-
Notifications
You must be signed in to change notification settings - Fork 0
/
apigoogle.html
180 lines (168 loc) · 6.63 KB
/
apigoogle.html
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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Simple Polygon</title>
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto+Slab');
/* Always set the map height explicitly to define the size of the div
* element that contains the map. */
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js" type="text/javascript"></script>
<script src="./lib/maplabel.js"></script>
<script src="./lib/polylabel.js"></script>
<script>
var map;
var infoWindow;
function count_str(cmp, center) {
var cord = { 'top':0,'bot':0,'left':0,'right':0 };
var cities = {
'top': {
'Brazlândia':1,
'Ceilândia':1,
'Cruzeiro':1.1,
'Fercal':1,
'Itapoã':0.35,
'Jardim Botânico':1,
'Lago Norte':2,
'Park Way':1,
'Plano Piloto':3,
'Recanto das Emas':1.5,
'Riacho Fundo II':1,
'Riacho Fundo':1.4,
'Samambaia':1,
'SIA':0.3,
'Sobradinho II':4,
'Sobradinho':1,
'Taguatinga':2,
'Vicente Pires':1,
'Águas Claras':1,
},
'right': {
'Ceilândia':1,
'Cruzeiro':1.2,
'Jardim Botânico':2,
'Lago Norte':3,
'Park Way':1,
'Recanto das Emas':1,
'Riacho Fundo II':1,
'Sobradinho':1.5,
'Vicente Pires':1,
'Águas Claras':0.8,
'SCIA':0.5,
'Itapoã':1
},
'left': {
'Plano Piloto':1,
'Riacho Fundo':0.5,
'Sobradinho II':5
},
'bot': {
'Sudoeste':0.4
}
};
for (key in cities) {
var count = cities[key][cmp];
cord[key] = count*0.015;
}
if (cord['top']) center.lat += cord['top'];
if (cord['bot']) center.lat -= cord['bot'];
if (cord['left']) center.lng -= cord['left'];
if (cord['right']) center.lng += cord['right'];
return center;
}
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 10.8,
center: {lat: -15.77556, lng: -47.79709},
styles: [
{elementType: 'geometry', stylers: [{color: '#242f3e'}]},
{elementType: 'labels', stylers: [{visibility: 'off'}]},
{featureType: 'poi.park', elementType: 'geometry', stylers: [{color: '#263c3f'}]},
{featureType: 'road', elementType: 'geometry', stylers: [{color: '#38414e'}]},
{featureType: 'road', elementType: 'geometry.stroke', stylers: [{color: '#212a37'}]},
{featureType: 'road.highway', elementType: 'geometry', stylers: [{color: '#746855'}]},
{featureType: 'road.highway', elementType: 'geometry.stroke', stylers: [{color: '#1f2835'}]},
{featureType: 'transit', elementType: 'geometry', stylers: [{color: '#2f3948'}]},
{featureType: 'water', elementType: 'geometry', stylers: [{color: '#17263c'}]}
]
});
var localities = ['distrito_federal','brasilia','gama','taguatinga','brazlandia','sobradinho','planaltina','paranoa','nucleo_bandeirante','ceilandia','guara','cruzeiro','samambaia','santa_maria','sao_sebastiao','recanto_das_emas','lago_sul','riacho_fundo','lago_norte','candangolandia','aguas_claras','riacho_fundo_ii','sudoeste_octogonal','varjao','park_way','scia','sobradinho_ii','jardim_botanico','itapoa','sia','vicente_pires','fercal']
localities.forEach(function(key, value){
if (key != 'distrito_federal') key += '2';
map.data.loadGeoJson('http://localhost:3000/jsons?file='+key)
});
map.data.setStyle(function(feature) {
var city = feature.getProperty('name');
var strokeColor;
var fillColor;
var strokeWeight = 2;
var fillOpacity = 0.55;
var strokeOpacity = 1;
if (city == 'Distrito Federal') {
strokeColor = '#000000';
fillOpacity = 0.0;
strokeOpacity = 1.0;
strokeWeight = 6;
} else {
strokeColor = feature.getProperty('Colors')['All']['Total']['strokeColor'];
fillColor = feature.getProperty('Colors')['All']['Total']['fillColor'];
}
return /** @type {google.maps.Data.StyleOptions} */ {
fillColor: fillColor,
strokeColor : strokeColor,
fillOpacity : fillOpacity,
strokeOpacity : strokeOpacity,
strokeWeight : strokeWeight
};
});
google.maps.event.addListener(map.data,'addfeature',function(e){
if(e.feature.getGeometry().getType() === 'Polygon'){
var bounds=new google.maps.LatLngBounds();
var polygon = [];
e.feature.getGeometry().getArray().forEach(function(path){
path.getArray().forEach(function(latLng){
bounds.extend(latLng);
polygon.push([latLng.lat(), latLng.lng()]);
});
});
p = polylabel([polygon], 300);
var center = {'lat': p[0],'lng': p[1]};
e.feature.setProperty('bounds', bounds);
e.feature.setProperty('med_center', center);
var name = e.feature.getProperty('name');
center = count_str(name, center);
if (name != 'Distrito Federal')
var mapLabel = new MapLabel({
text: name,
position: new google.maps.LatLng(center.lat,center.lng),
map: map,
fontSize: 13,
align: 'center',
fontFamily: 'Roboto Slab',
fontColor: '#e2c493',
// strokeColor:'#242f3e',
// strokeColor:'#561643',
strokeColor:'#2C2B3C',
strokeWeight: 3
});
}
});
};
google.maps.event.addDomListener(window, 'load', initMap);
</script>
</body>
</html>