-
Notifications
You must be signed in to change notification settings - Fork 1
/
ASoIaF-objects.js
349 lines (327 loc) · 11.3 KB
/
ASoIaF-objects.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
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
//Tile Handling
function getTileCode(a, b) {
//converts tile x,y into keyhole string
var c = Math.pow(2, b);
var d = a.x;
var e = a.y;
var f = 't';
for (var g = 0; g < b; g++) {
c = c / 2;
if (e < c) {
if (d < c) {
f += 'q';
} else {
f += 'r';
d -= c;
}
} else {
if (d < c) {
f += 't';
e -= c;
} else {
f += 's';
d -= c;
e -= c;
}
}
}
return f;
}
//Tile Handling
function isOutsideTileRange(coord, zoom) {
var tileRange = 1 << zoom;
if (coord.x < 0 || coord.x >= tileRange) return true;
if (coord.y < 0 || coord.y >= tileRange) return true;
return false;
}
//Transparent markers placed on top of each city, town, castle, & ruin
function markLocation(map, key, locationOptions) {
//Sample input-> They_Lay_With_Lions: {lat:23.4027, lng:-126.2548, title:"23: Inn (They Lay with Lions)", url:"https://awoiaf.westeros.org/index.php/A_Storm_of_Swords-Chapter_1"},
if (
typeof locationOptions.lat != 'number' ||
typeof locationOptions.lng != 'number'
) {
console.log(
'Location ' + key + ' was missing either the lat or lng attribute.'
);
return false;
}
var title =
typeof locationOptions.title != 'undefined' ? locationOptions.title : '';
var url =
typeof locationOptions.url != 'undefined'
? locationOptions.url
: 'https://awoiaf.westeros.org/index.php/' + key;
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locationOptions.lat, locationOptions.lng),
title: title,
icon: { path: google.maps.SymbolPath.CIRCLE, strokeOpacity: 0, scale: 3 },
map: map,
});
google.maps.event.addListener(marker, 'click', function (event) {
if (ctrlPressed) window.location = '#@' + key;
else window.open(url, '_blank');
});
return marker;
}
//Colored shapes matching the borders of the 9 constituencies of Westeros
function createPolygon(map, regionOptions) {
//Sample input-> {coords:giftCoords, color:"#000000", key:"Gift"} (giftCoords is an array of google.maps.LatLng objects)
if (typeof regionOptions.key != 'string')
return console.log('Region was missing a key attribute.');
if (typeof regionOptions.color != 'string')
return console.log(
'Region ' + regionOptions.key + ' was missing a color attribute.'
);
if (
typeof regionOptions.coords != 'object' ||
regionOptions.coords.length < 3
)
return console.log(
'Region ' + regionOptions.key + ' was missing a coords attribute.'
);
var url = 'https://awoiaf.westeros.org/index.php/' + regionOptions.key;
var polygon = new google.maps.Polygon({
paths: regionOptions.coords,
fillColor: regionOptions.color,
fillOpacity: 0.7,
strokeWeight: 0,
visible: false,
map: map,
});
google.maps.event.addListener(polygon, 'click', function (event) {
window.open(url, '_blank');
});
return polygon;
}
//Coats of arms for every known noble family (some locations were guessed)
function markNobility(map, nobilityOptions) {
//Sample input-> {wikiKey:"House_Bolton", seatKey:"Dreadfort", imgRatio:(120/102), img:"https://awoiaf.westeros.org/images/thumb/7/76/Bolton.png/102px-Bolton.png", isGreat:true, chapters:[196,999]} (seatKey may be replaced with lat & lng)
if (typeof nobilityOptions.img != 'string')
return console.log(
nobilityOptions.wikiKey +
' in the nobility list was missing an img attribute.'
);
if (typeof nobilityOptions.seatKey == 'string')
var coords = checkLocKey(nobilityOptions.seatKey);
else {
if (
typeof nobilityOptions.lat == 'number' &&
typeof nobilityOptions.lng == 'number'
)
var coords = checkLocKey('', nobilityOptions.lat, nobilityOptions.lng);
else return false;
}
if (!coords) return false;
var title =
typeof nobilityOptions.wikiKey == 'string'
? decodeURI(nobilityOptions.wikiKey).replace(/_/g, ' ')
: 'No name listed';
if (typeof nobilityOptions.clue == 'string') {
if (nobilityOptions.clue == 'mountain clan')
title = title.replace(/House/, 'Clan');
else title += ' (somewhere in ' + nobilityOptions.clue + ')';
}
var isGreat =
typeof nobilityOptions.isGreat != 'undefined'
? nobilityOptions.isGreat
: false;
var imgRatio =
typeof nobilityOptions.imgRatio == 'number'
? nobilityOptions.imgRatio
: 4 / 3;
var imgHeight = isGreat ? 60 : 30;
var anchorPoint = $.isArray(nobilityOptions.anchor)
? new google.maps.Point(
nobilityOptions.anchor[0],
nobilityOptions.anchor[1]
)
: new google.maps.Point(imgHeight / imgRatio / 2, imgHeight / 2);
var icon = new google.maps.MarkerImage(
nobilityOptions.img,
null,
null,
anchorPoint,
new google.maps.Size(imgHeight / imgRatio, imgHeight)
);
var marker = new google.maps.Marker({
position: new google.maps.LatLng(coords[0], coords[1]),
title: title,
icon: icon,
visible: false,
map: map,
});
if (typeof nobilityOptions.wikiKey == 'string')
google.maps.event.addListener(marker, 'click', function (event) {
window.open(
'https://awoiaf.westeros.org/index.php/' + nobilityOptions.wikiKey,
'_blank'
);
});
marker['isGreat'] = isGreat;
marker['chapters'] =
typeof nobilityOptions.chapters == 'object'
? nobilityOptions.chapters
: [0, 999];
marker['episodes'] =
typeof nobilityOptions.episodes == 'object'
? nobilityOptions.episodes
: [0, 999];
return marker;
}
//Teardrop markers & lines marking the path of each major character
function markPathSegment(map, overlayOptions) {
if (typeof overlayOptions.icon == 'string') {
switch (overlayOptions.icon) {
case 'skull':
var icon = 'skull.png';
break;
case 'lost':
var icon = 'question-mark.gif';
break;
default:
var icon =
'https://chart.googleapis.com/chart?chst=d_map_xpin_letter&chld=pin' +
overlayOptions.icon; //or d_map_pin_letter_withshadow
}
switch (overlayOptions.icon.substring(0, 3)) {
case '_sl':
icon = { url: icon, anchor: new google.maps.Point(23, 33) };
break;
case '_sr':
icon = { url: icon, anchor: new google.maps.Point(0, 33) };
break;
}
if (typeof overlayOptions.key == 'string') {
//Sample input-> {icon:"greyC", chapters:[0,17], episodes:[0,1], key:"Winterfell"}
checkResults = checkLocKey(overlayOptions.key);
if (!checkResults)
return console.log(
'Item ' +
overlayOptions.key +
' in the character path list does not match a known location.'
);
var overlay = new google.maps.Marker({
position: new google.maps.LatLng(checkResults[0], checkResults[1]),
icon: icon,
visible: false,
map: map,
});
} else {
//Sample input-> {icon:"greyE", chapters:[15,19], episodes:[1,1], coord:[26.4312,-114.1406]}
if (typeof overlayOptions.coord != 'object')
return console.log(
'One item in the character path list is missing a coord attribute.'
);
if (overlayOptions.coord.length != 2)
return console.log(
'One item in the character path list has an inappropriate coord attribute: ' +
overlayOptions.coord
);
if (!checkLocKey('', overlayOptions.coord[0], overlayOptions.coord[1]))
return console.log(
'One item in the character path list has coordinates outside the edges of the map: ' +
overlayOptions.coord
);
var overlay = new google.maps.Marker({
position: new google.maps.LatLng(
overlayOptions.coord[0],
overlayOptions.coord[1]
),
icon: icon,
visible: false,
map: map,
});
}
} //icons
if (typeof overlayOptions.line == 'string') {
//Sample input-> {line:"#808080", chapters:[20], episodes:2, path:[[26.4312,-114.1406], "Darry", [16.0669,-109.5263],"Hayford","King%27s_Landing"]}
if (typeof overlayOptions.line != 'string')
return console.log(
'One item in the character path list has neither a icon nor line attribute.'
);
if (typeof overlayOptions.path != 'object')
return console.log(
'One item in the character path list is missing a path attribute.'
);
//Parse the array of coordinates in the path attribute
var path = [];
var checkResults = [];
for (i in overlayOptions.path) {
if (typeof overlayOptions.path[i] == 'string') {
checkResults = checkLocKey(overlayOptions.path[i]);
if (!checkResults) continue;
path.push(new google.maps.LatLng(checkResults[0], checkResults[1]));
}
if (typeof overlayOptions.path[i] == 'object') {
if (overlayOptions.path[i].length != 2) continue;
if (
!checkLocKey('', overlayOptions.path[i][0], overlayOptions.path[i][1])
)
continue;
path.push(
new google.maps.LatLng(
overlayOptions.path[i][0],
overlayOptions.path[i][1]
)
);
}
}
var overlay = new google.maps.Polyline({
path: path,
strokeColor: overlayOptions.line,
strokeOpacity: 1.0,
strokeWeight: 8,
visible: false,
map: map,
});
//TEMPORARY
//google.maps.event.addListener(overlay, 'click', function(event) {
// new google.maps.InfoWindow({position:event.latLng, content:Math.round(event.latLng.lat()*10000)/10000+","+Math.round(event.latLng.lng()*10000)/10000 }).open(map);
//});
} //lines
if (typeof overlayOptions.arrow == 'string') {
//Sample input-> {arrow:"#808080", chapters:59, coord:[42.0329, -125.5078], heading:210}
if (typeof overlayOptions.coord != 'object')
return console.log(
'One arrow in the character path list is missing a coord attribute.'
);
if (overlayOptions.coord.length != 2)
return console.log(
'One arrow in the character path list has an inappropriate coord attribute: ' +
overlayOptions.coord
);
if (typeof overlayOptions.heading != 'number')
return console.log(
'One arrow in the character path list is missing a heading attribute.'
);
var overlay = new ArrowOverlay(
map,
new google.maps.LatLng(overlayOptions.coord[0], overlayOptions.coord[1]),
overlayOptions.heading,
overlayOptions.arrow,
1
);
} //arrows
overlay['chapters'] = [999, 999];
if (typeof overlayOptions.chapters == 'number')
overlay.chapters[0] = overlayOptions.chapters;
if (typeof overlayOptions.chapters == 'object') {
if (overlayOptions.chapters.length == 2)
if (typeof overlayOptions.chapters[1] == 'number')
overlay.chapters[1] = overlayOptions.chapters[1];
if (typeof overlayOptions.chapters[0] == 'number')
overlay.chapters[0] = overlayOptions.chapters[0];
}
overlay['episodes'] = [99, 99];
if (typeof overlayOptions.episodes == 'number')
overlay.episodes[0] = overlayOptions.episodes;
if (typeof overlayOptions.episodes == 'object') {
if (overlayOptions.episodes.length == 2)
if (typeof overlayOptions.episodes[1] == 'number')
overlay.episodes[1] = overlayOptions.episodes[1];
if (typeof overlayOptions.episodes[0] == 'number')
overlay.episodes[0] = overlayOptions.episodes[0];
}
return overlay;
}