forked from ProHill/VRS-Charts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom-map.js
More file actions
251 lines (235 loc) · 7.87 KB
/
Copy pathcustom-map.js
File metadata and controls
251 lines (235 loc) · 7.87 KB
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<script src="http://maps.googleapis.com/maps/api/js"></script>
<script type="text/javascript">
var map_types = {
tac: {
max_zoom: 12,
default_zoom: 10
},
sec: {
max_zoom: 12,
default_zoom: 10
},
wac: {
max_zoom: 10,
default_zoom: 9
},
enrl: {
max_zoom: 11,
default_zoom: 10
},
enrh: {
max_zoom: 10,
default_zoom: 9
},
"default": {
default_zoom: 10,
clean_zoom: 7
},
"Contrast": {
default_zoom: 10,
clean_zoom: 7
}
};
function updateMap() {
setStateCookie();
}
var state_cookie = "vrs_maptype";
function getStateCookie() {
if (document.cookie.length > 0) {
start = document.cookie.indexOf(state_cookie + "=");
if (start!=-1) {
start += state_cookie.length + 1;
end = document.cookie.indexOf(";", start);
if (end==-1) {
end = document.cookie.length
}
return document.cookie.substring(start, end)
}
}
return null
}
function setStateCookie() {
var d = window.GoogleMap.getMapTypeId();
var b = new Date();
var a = new Date(b.getTime() + 30 * 86400 * 1000);
var c = state_cookie + "=" + window.GoogleMap.getCenter().lat() + "|" + window.GoogleMap.getCenter().lng() + "|" + window.GoogleMap.getZoom() + "|" + d + ";expires=" + a.toGMTString();
document.cookie = c
}
window.contrastStyleArray = [ // The Google map styles to use for the high contrast map.
{
featureType: 'poi',
stylers: [
{ visibility: 'off' }
]
},{
featureType: 'landscape',
stylers: [
{ saturation: -70 },
{ lightness: -30 },
{ gamma: 0.80 }
]
},{
featureType: 'road',
stylers: [
{ visibility: 'simplified' },
{ weight: 0.4 },
{ saturation: -70 },
{ lightness: -30 },
{ gamma: 0.80 }
]
},{
featureType: 'road',
elementType: 'labels',
stylers: [
{ visibility: 'simplified' },
{ saturation: -46 },
{ gamma: 1.82 }
]
},{
featureType: 'administrative',
stylers: [
{ weight: 1 }
]
},{
featureType: 'administrative',
elementType: 'labels',
stylers: [
{ saturation: -100 },
{ weight: 0.1 },
{ lightness: -60 },
{ gamma: 2.0 }
]
},{
featureType: 'water',
stylers: [
{ saturation: -72 },
{ lightness: -25 }
]
},{
featureType: 'administrative.locality',
stylers: [
{ weight: 0.1 }
]
},{
featureType: 'administrative.province',
stylers: [
{ lightness: -43 }
]
},{
"featureType": "transit.line",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "transit.station.bus",
"stylers": [
{ "visibility": "off" }
]
},{
"featureType": "transit.station.rail",
"stylers": [
{ "visibility": "off" }
]
}
];
var l = "hybrid";
function getMapTypeOption(a) {
var b = window.GoogleMap.getMapTypeId();
if (map_types[b] && map_types[b][a]) {
return map_types[b][a]
} else {
return map_types["default"][a]
}
}
function addMapTypes() {
for (var b in map_types) {
if (b == "default") {
continue
}
if (b == "Contrast") {
var contrastMap = new google.maps.StyledMapType(window.contrastStyleArray,
{name: "Contrast"});
var a = {
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'Contrast']
}
};
window.GoogleMap.set(a);
continue
}
var a = {
minZoom: 4,
maxZoom: map_types[b].max_zoom,
name: b,
tileSize: new google.maps.Size(256, 256),
getTileUrl: (function(c) {
return function(f, e) {
var d = f.x%(1<<e);
if (d < 0) {
d = d + (1<<e)
}
var g = (1<<e) - f.y - 1;
return "http://wms.chartbundle.com/tms/1.0.0/" + c + "/" + e + "/" + d + "/" + g + ".png"
}
})(b)
};
window.GoogleMap.mapTypes.set(b, new google.maps.ImageMapType(a))
}
}
function changeMapType() {
var b = document.getElementById("menu_pulldown");
var a = b.options[b.selectedIndex].value;
window.GoogleMap.setMapTypeId(a);
}
function showMapType() {
var b = document.getElementById("menu_pulldown");
for (var a = 0; a < b.options.length; a++) {
if (b.options[a].value == window.GoogleMap.getMapTypeId()) {
b.options[a].selected = true;
break
}
}
}
if(VRS && VRS.globalDispatch && VRS.serverConfig) {
VRS.globalDispatch.hook(VRS.globalEvent.bootstrapCreated, function(bootStrap) {
// Check to see if this version of the bootstrap raises an event once the map has initialised
if(bootStrap.hookMapInitialised) {
// It has the event - hook it
bootStrap.hookMapInitialised(function(pageSettings) {
// This is called once the map has been loaded. The jQuery plugin for the map will be
// held in pageSettings.mapPlugin. Note that this event is also raised when the page
// is loaded in offline mode, so we need to check that mapPlugin is good before we
// use it. We're also going to be using stuff specific to Google Maps, so we need to
// make sure that the map plugin is wrapping Google Maps.
if(pageSettings.mapPlugin && pageSettings.mapPlugin.getNativeType() === 'GoogleMaps') {
// Get the Google Maps map handle
window.GoogleMap = pageSettings.mapPlugin.getNative();
//document.body.onunload = setStateCookie;
var b = getStateCookie();
if (b) {
parts = b.split("|");
f = parseFloat(parts[0]);
a = parseFloat(parts[1]);
m = parseInt(parts[2]);
l = parts[3]
}
window.GoogleMap.set('disableDefaultUI', true);
window.GoogleMap.set('showMapControl', false);
window.GoogleMap.set('zoomControl', true);
addMapTypes();
showMapType();
var existingControlsInTopRight = window.GoogleMap.controls[google.maps.ControlPosition.TOP_RIGHT];
existingControlsInTopRight.push(document.getElementById("main_toolbar"));
google.maps.event.addListener(window.GoogleMap, "center_changed", function() {
localStorage.CenterLat = window.GoogleMap.getCenter().lat();
localStorage.CenterLon = window.GoogleMap.getCenter().lng()
});
google.maps.event.addListener(window.GoogleMap, "zoom_changed", function() {
localStorage.ZoomLvl = window.GoogleMap.getZoom()
});
}
});
}
});
}
</script>