Mercurial > hg > batmud > gmap2
annotate markers.js @ 296:625cac7c230d gmap2
Use CSS class instead of direct style / background color manipulation.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 19 Nov 2016 02:27:01 +0200 |
parents | 5c15b45947f2 |
children | 87a17b1fccb5 |
rev | line source |
---|---|
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
1 // $Id: markers.js 2284 2009-09-21 12:47:20Z jeskko $ |
192
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
2 |
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
3 // Marker types |
289
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
4 var LOCF_M_SCENIC1 = (0x000001); /* '?' Scenic marker */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
5 var LOCF_M_SCENIC2 = (0x000002); /* '%' Shrine marker/etc */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
6 var LOCF_M_PCITY = (0x000004); /* 'C' Player city */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
7 var LOCF_M_CITY = (0x000008); /* 'c' City */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
8 var LOCF_M_MASK = (0x00000F); |
192
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
9 |
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
10 // Location types |
289
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
11 var LOCF_T_SHRINE = (0x000010); /* 'S' Raceshrine */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
12 var LOCF_T_GUILD = (0x000020); /* 'G' Guild */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
13 var LOCF_T_SS = (0x000040); /* 'P' Player guild/Secret Society */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
14 var LOCF_T_MONSTER = (0x000080); /* 'M' Special monster */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
15 var LOCF_T_TRAINER = (0x000100); /* 'T' Guild trainer */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
16 var LOCF_T_FORT = (0x000200); /* 'F' Regions fort */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
17 var LOCF_T_MASK = (0x00FFF0); |
192
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
18 var LOCF_MASK = (LOCF_M_MASK | LOCF_T_MASK); |
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
19 |
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
20 // Extra flags |
289
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
21 var LOCF_INVIS = (0x010000); /* '-' Invisible marker / Don't show label */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
22 var LOCF_CLOSED = (0x020000); /* '!' Area is CLOSED */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
23 var LOCF_INSTANCED = (0x040000); /* 'I' Location is "instanced" for each player */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
24 var LOCF_INVALID = (0x400000); /* Possibly invalid location */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
25 var LOCF_NOMARKER = (0x800000); /* Location has no marker in mapdata or explicitly defined */ |
07530034b221
Add instance flag. Not used here yet, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
234
diff
changeset
|
26 var LOCF_Q_MASK = (0xFF0000); |
192
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
27 |
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
28 |
129 | 29 // List of marker types |
157 | 30 var pmapMarkerTypes = |
129 | 31 [ |
32 ["Guilds", "guild"], | |
33 ["PCities", "pcity"], | |
34 ["Shrines", "shrine"], | |
35 ["Areas", "default"], | |
231 | 36 ["Mob", "monster"], |
232
1706a1bb2a32
Add trainer markers to toggleables.
Matti Hamalainen <ccr@tnsp.org>
parents:
231
diff
changeset
|
37 ["Trn", "trainer"], |
129 | 38 ]; |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
39 |
94 | 40 |
192
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
41 // Some global vars |
157 | 42 var pmapMMgr; |
43 var pmapAreas = []; | |
44 var pmapMarkers = []; | |
204
2a2a5e992b9f
Fix some errors of accessing nonexisting elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
45 var pmapMIndex; |
184
fc2c2385049b
Make map markers change visibility with selections as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
46 var pmapMarkerInfo = []; |
174 | 47 var pmapSideBuiltinHTML, pmapSidePublicHTML, pmapSidePrivateHTML; |
48 var pmapInfoWindow; | |
129 | 49 |
50 | |
51 function pmapMyClick(i) | |
94 | 52 { |
175 | 53 pmap.panTo(pmapMarkers[i].getPosition()); |
137 | 54 setTimeout("pmapShowInfo("+ i +")", 1000); |
55 } | |
56 | |
57 | |
58 function pmapShowInfo(i) | |
59 { | |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
60 google.maps.event.trigger(pmapMarkers[i], "click"); |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
61 } |
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
62 |
94 | 63 |
192
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
64 function pmapLocGetLocationType(flags, def) |
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
65 { |
205 | 66 switch (flags & LOCF_M_MASK) |
67 { | |
68 case LOCF_M_CITY: return "city"; | |
69 case LOCF_M_PCITY: return "pcity"; | |
70 default: | |
71 switch (flags & LOCF_T_MASK) | |
72 { | |
73 case LOCF_T_SHRINE: return "shrine"; | |
74 case LOCF_T_GUILD: return "guild"; | |
75 case LOCF_T_SS: return "ss"; | |
76 case LOCF_T_MONSTER: return "monster"; | |
77 case LOCF_T_TRAINER: return "trainer"; | |
78 case LOCF_T_FORT: return "fort"; | |
79 } | |
80 break; | |
81 } | |
82 return def ? def : "default"; | |
192
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
83 } |
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
84 |
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
85 |
196
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
86 function pmapCreateMarker(m, mclass) |
94 | 87 { |
196
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
88 type = pmapLocGetLocationType(m["flags"], m["type"]); |
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
89 if (m["name"].indexOf('FERRY') == 0) |
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
90 type = "ferry"; |
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
91 |
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
92 pname = (type != "default" ? type.toUpperCase()+" " : "") + m["name"]; |
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
93 |
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
94 if (m["flags"] & LOCF_CLOSED) |
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
95 pname += " (CLOSED)"; |
189 | 96 |
182 | 97 var marker = new MarkerWithLabel( |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
98 { |
196
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
99 position: pmapMapCoordsToLatLng(new google.maps.Point(m["x"] * 2 + 1, m["y"] * 2 + 1), 7), |
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
100 icon: pmapIcons[type], |
182 | 101 draggable: false, |
196
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
102 labelContent: m["name"], |
217 | 103 labelAnchor: new google.maps.Point(25, 0), |
182 | 104 labelClass: "labels", |
105 labelStyle: {opacity: 0.75} | |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
106 }); |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
107 |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
108 google.maps.event.addListener(marker, "click", function() |
94 | 109 { |
196
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
110 pmapInfoWindow.setContent("<div class=\"infowin\">"+ m["html"] +"</div>"); |
176 | 111 pmapInfoWindow.open(pmap, this); |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
112 }); |
129 | 113 |
196
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
114 if (mclass == "builtin") pmapSideBuiltinHTML += '<div id="marker'+ pmapMIndex +'" class="c_'+ m["continent"].toLowerCase()+'"><div> </div><a href="javascript:pmapMyClick('+ pmapMIndex +')">'+ pname +'</a></div>'; |
189 | 115 if (mclass == "private") pmapSidePrivateHTML += '<a href="javascript:pmapMyClick(' + pmapMIndex + ')">' + pname + '</a><br>'; |
116 if (mclass == "public") pmapSidePublicHTML += '<a href="javascript:pmapMyClick(' + pmapMIndex + ')">' + pname + '</a><br>'; | |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
117 |
184
fc2c2385049b
Make map markers change visibility with selections as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
118 pmapMarkers[pmapMIndex] = marker; |
223
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
119 pmapMarkerInfo[pmapMIndex] = [type, m["continent"], m]; |
184
fc2c2385049b
Make map markers change visibility with selections as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
120 pmapMIndex++; |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
121 |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
122 if (pmapAreas[type] == undefined) |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
123 pmapAreas[type] = []; |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
124 |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
125 pmapAreas[type].push(marker); |
196
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
126 |
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
127 return marker; |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
128 } |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
129 |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
130 |
222 | 131 // Wrapper function for adding markers, |
132 // checks if the array is defined first. | |
164
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
133 function pmapAddMarkers(mlist, minzoom, maxzoom) |
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
134 { |
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
135 if (mlist) |
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
136 pmapMMgr.addMarkers(mlist, minzoom, maxzoom); |
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
137 } |
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
138 |
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
139 |
153 | 140 function pmapInitializeMarkers() |
94 | 141 { |
224
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
142 pmapInfoWindow = new google.maps.InfoWindow; |
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
143 |
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
144 google.maps.event.addListener(pmap, 'click', function() |
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
145 { |
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
146 pmapInfoWindow.close(); |
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
147 }); |
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
148 |
169 | 149 pmapMMgr = new MarkerManager(pmap); |
150 google.maps.event.addListener(pmapMMgr, 'loaded', pmapLoadMarkers); | |
151 } | |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
152 |
169 | 153 |
154 function pmapLoadMarkers() | |
155 { | |
204
2a2a5e992b9f
Fix some errors of accessing nonexisting elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
156 pmapMIndex = 0; |
180
662e8b5ec9a5
Close infowindow when needed.
Matti Hamalainen <ccr@tnsp.org>
parents:
176
diff
changeset
|
157 |
174 | 158 // |
159 // Parse regular markers from JSON | |
160 // | |
169 | 161 XDownloadUrl("markers.json", function(data, responseCode) |
94 | 162 { |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
163 var markers = JSON.parse(data); |
157 | 164 pmapSideBuiltinHTML = ""; |
174 | 165 pmapSidePublicHTML = ""; |
166 pmapSidePrivateHTML = ""; | |
153 | 167 |
168 for (var nid = 0; nid < markers.length; nid++) | |
169 { | |
196
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
170 pmapCreateMarker(markers[nid], "builtin"); |
153 | 171 } |
172 | |
190
d6e16437ee06
Adjust marker zoom level visibility ranges, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
173 pmapAddMarkers(pmapAreas["default"], 7, 11); |
164
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
174 pmapAddMarkers(pmapAreas["guild"], 6, 11); |
190
d6e16437ee06
Adjust marker zoom level visibility ranges, again.
Matti Hamalainen <ccr@tnsp.org>
parents:
189
diff
changeset
|
175 pmapAddMarkers(pmapAreas["shrine"], 6, 11); |
192
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
176 pmapAddMarkers(pmapAreas["trainer"], 6, 11); |
164
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
177 pmapAddMarkers(pmapAreas["ferry"], 4, 11); |
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
178 pmapAddMarkers(pmapAreas["city"], 4, 11); |
153 | 179 |
192
260644076c07
Change handling of marker type.
Matti Hamalainen <ccr@tnsp.org>
parents:
190
diff
changeset
|
180 pmapAddMarkers(pmapAreas["monster"], 8, 11); |
164
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
181 pmapAddMarkers(pmapAreas["pcity"], 8, 11); |
231 | 182 pmapAddMarkers(pmapAreas["fort"], 8, 11); |
157 | 183 pmapMMgr.refresh(); |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
184 |
224
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
223
diff
changeset
|
185 google.maps.event.trigger(pmap, "foobar"); |
157 | 186 document.getElementById("sidecontent").innerHTML = pmapSideBuiltinHTML; |
153 | 187 }); |
188 | |
189 // | |
174 | 190 // Parse tradelane markers from another JSON |
153 | 191 // |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
192 XDownloadUrl("tradelane.json", function(data,responseCode) |
153 | 193 { |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
194 var markers = JSON.parse(data); |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
195 |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
196 for (var nid = 0; nid < markers.length; nid++) |
153 | 197 { |
196
1307410acf6d
Simplify by getting rid of one wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
198 pmapCreateMarker(markers[nid], "tradelane"); |
153 | 199 } |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
200 |
164
5489c1e24521
Rename things, and add a wrapper function.
Matti Hamalainen <ccr@tnsp.org>
parents:
163
diff
changeset
|
201 pmapAddMarkers(pmapAreas["tradelane"], 5, 11); |
157 | 202 pmapMMgr.refresh(); |
153 | 203 }); |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
204 |
153 | 205 // |
206 // Create GMap polylines from tradelane line data | |
207 // | |
210
265debcae71c
Rename tradelane polyline datafile.
Matti Hamalainen <ccr@tnsp.org>
parents:
205
diff
changeset
|
208 XDownloadUrl("trlines.json", function(data,responseCode) |
94 | 209 { |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
210 var lines = JSON.parse(data); |
153 | 211 |
212 // Go through array of line elements | |
213 for (var nid = 0; nid < lines.length; nid++) | |
214 { | |
163 | 215 var points = lines[nid]; |
153 | 216 var coords = []; |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
217 |
153 | 218 // Create polyline points |
219 for (var npt = 0; npt < points.length; npt++) | |
220 { | |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
221 var pt = points[npt]; |
172 | 222 coords.push(pmapMapCoordsToLatLng(new google.maps.Point(pt["x"] * 2 + 1, pt["y"] * 2 + 1), 7)); |
153 | 223 } |
224 | |
225 // Create new polyline and add it to map overlay | |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
226 var poly = new google.maps.Polyline({ |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
227 path: coords, |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
228 strokeColor: "#ffffff", |
231 | 229 strokeWeight: 2, |
230 strokeOpacity: 0.6 | |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
231 }); |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
232 |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
233 poly.setMap(pmap); |
153 | 234 } |
235 }); | |
172 | 236 |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
237 |
153 | 238 // |
163 | 239 // Create map control elements |
153 | 240 // |
294 | 241 var str = "<div class=\"vcontinents\">"; |
153 | 242 var n = 0; |
157 | 243 for (var i = 0; i < pmapContinents.length; i++) |
94 | 244 { |
226 | 245 var c = pmapContinents[i][0]; |
294 | 246 str += "<span id=\"sp"+c+"\" class=\"continent\"><a href=\"javascript:pmapToggleVisContinent('"+c+"')\">"+c+"</a></span>\n"; |
247 // if (n == 2) str += "<br />\n"; | |
226 | 248 n++; |
153 | 249 } |
250 | |
294 | 251 str += "<span id=\"spall_c\" class=\"continent\"><a href=\"javascript:pmapToggleVisContinent('all_c')\">All</a></span>\n"; |
153 | 252 |
294 | 253 str += "</div>\n"; |
254 str +="<div class=\"vtypes\">\n"; | |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
255 |
153 | 256 n = 0; |
157 | 257 for (var i = 0; i < pmapMarkerTypes.length; i++) |
153 | 258 { |
157 | 259 var q = pmapMarkerTypes[i]; |
153 | 260 if (q != null) |
261 { | |
262 var c = q[1]; | |
294 | 263 str += "<span id=\"sp"+c+"\" class=\"vtype\"><a href=\"javascript:pmapToggleVisType('"+c+"')\">"+pmapMarkerTypes[i][0]+"</a></span>\n"; |
264 // if (n == 2) str += "<br />\n"; | |
153 | 265 n++; |
266 } | |
267 } | |
268 | |
294 | 269 str += "<span id=\"spall_t\" class=\"vtype\"><a href=\"javascript:pmapToggleVisType('all_t')\">All</a></span></div>\n"; |
153 | 270 |
271 document.getElementById("controls").innerHTML = str; | |
272 | |
233
1a89174b7152
Improvements in filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
273 // |
1a89174b7152
Improvements in filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
274 // Set default states |
1a89174b7152
Improvements in filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
275 // |
153 | 276 pmapSetVisContinent("all_c", true); |
277 pmapSetVisType("all_t", true); | |
278 pmapUpdateVisible(); | |
279 } | |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
280 |
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
281 |
223
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
282 function pmapGetMarkerIndexByCoords(mx, my) |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
283 { |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
284 for (var i = 0; i < pmapMarkerInfo.length; i++) |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
285 { |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
286 var m = pmapMarkerInfo[i][2]; |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
287 if (m["x"] == mx && m["y"] == my) |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
288 return i; |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
289 } |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
290 |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
291 return null; |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
292 } |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
293 |
b8dfdc61acbd
Add function for finding marker index by global coords.
Matti Hamalainen <ccr@tnsp.org>
parents:
222
diff
changeset
|
294 |
129 | 295 // |
163 | 296 // Map menu / sidebar control code |
129 | 297 // |
123 | 298 var markerVisStates = []; |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
299 |
153 | 300 |
233
1a89174b7152
Improvements in filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
301 function pmapSetFilterVisState(c, show) |
94 | 302 { |
123 | 303 markerVisStates[c] = show; |
296
625cac7c230d
Use CSS class instead of direct style / background color manipulation.
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
304 var elem = document.getElementById("sp" + c); |
625cac7c230d
Use CSS class instead of direct style / background color manipulation.
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
305 elem.classList.add(show ? "visible" : "hidden"); |
625cac7c230d
Use CSS class instead of direct style / background color manipulation.
Matti Hamalainen <ccr@tnsp.org>
parents:
294
diff
changeset
|
306 elem.classList.remove(!show ? "visible" : "hidden"); |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
307 } |
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
308 |
123 | 309 |
129 | 310 function pmapUpdateVisible() |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
311 { |
184
fc2c2385049b
Make map markers change visibility with selections as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
182
diff
changeset
|
312 for (var i = 0; i < pmapMarkerInfo.length; i++) |
94 | 313 { |
204
2a2a5e992b9f
Fix some errors of accessing nonexisting elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
314 var elem = document.getElementById("marker" + i); |
2a2a5e992b9f
Fix some errors of accessing nonexisting elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
315 if (elem) |
2a2a5e992b9f
Fix some errors of accessing nonexisting elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
316 { |
2a2a5e992b9f
Fix some errors of accessing nonexisting elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
317 var show = markerVisStates[pmapMarkerInfo[i][0]] && markerVisStates[pmapMarkerInfo[i][1]]; |
2a2a5e992b9f
Fix some errors of accessing nonexisting elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
318 elem.style.display = show ? "block" : "none"; |
2a2a5e992b9f
Fix some errors of accessing nonexisting elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
319 pmapMarkers[i].setVisible(show); |
2a2a5e992b9f
Fix some errors of accessing nonexisting elements.
Matti Hamalainen <ccr@tnsp.org>
parents:
199
diff
changeset
|
320 } |
67 | 321 } |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
322 } |
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
323 |
94 | 324 |
129 | 325 function pmapSetVisContinent(c, show) |
94 | 326 { |
327 if (c == "all_c") | |
328 { | |
157 | 329 for (var i = 0; i < pmapContinents.length; i++) |
233
1a89174b7152
Improvements in filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
330 pmapSetFilterVisState(pmapContinents[i][0], show); |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
331 } |
233
1a89174b7152
Improvements in filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
332 pmapSetFilterVisState(c, show); |
43 | 333 } |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
334 |
94 | 335 |
129 | 336 function pmapSetVisType(c, show) |
94 | 337 { |
338 if (c == "all_t") | |
339 { | |
233
1a89174b7152
Improvements in filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
340 for (var i in pmapAreas) |
1a89174b7152
Improvements in filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
341 markerVisStates[i] = show; |
1a89174b7152
Improvements in filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
342 |
157 | 343 for (var i = 0; i < pmapMarkerTypes.length; i++) |
233
1a89174b7152
Improvements in filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
344 pmapSetFilterVisState(pmapMarkerTypes[i][1], show); |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
345 } |
233
1a89174b7152
Improvements in filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
232
diff
changeset
|
346 pmapSetFilterVisState(c, show); |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
347 } |
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
348 |
94 | 349 |
129 | 350 function pmapToggleVisContinent(c) |
94 | 351 { |
234
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
352 var first = true; |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
353 if (c == "all_c") |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
354 first = false; |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
355 else |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
356 { |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
357 for (var i = 0; i < pmapContinents.length; i++) |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
358 { |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
359 var q = pmapContinents[i][0]; |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
360 if (!markerVisStates[q]) |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
361 { |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
362 first = false; |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
363 break; |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
364 } |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
365 } |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
366 } |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
367 |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
368 if (first) |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
369 { |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
370 pmapSetVisContinent("all_c", false); |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
371 pmapSetVisContinent(c, true); |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
372 } |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
373 else |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
374 pmapSetVisContinent(c, !markerVisStates[c]); |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
375 |
129 | 376 pmapUpdateVisible(); |
53 | 377 } |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
90
diff
changeset
|
378 |
94 | 379 |
129 | 380 function pmapToggleVisType(c) |
94 | 381 { |
234
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
382 var first = true; |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
383 if (c == "all_t") |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
384 first = false; |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
385 else |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
386 { |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
387 for (var i = 0; i < pmapMarkerTypes.length; i++) |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
388 { |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
389 var q = pmapMarkerTypes[i][1]; |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
390 if (!markerVisStates[q]) |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
391 { |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
392 first = false; |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
393 break; |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
394 } |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
395 } |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
396 } |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
397 |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
398 if (first) |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
399 { |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
400 pmapSetVisType("all_t", false); |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
401 pmapSetVisType(c, true); |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
402 } |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
403 else |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
404 pmapSetVisType(c, !markerVisStates[c]); |
8a14983244b0
Some more work on filtering controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
233
diff
changeset
|
405 |
129 | 406 pmapUpdateVisible(); |
53 | 407 } |