Mercurial > hg > batmud > gmap2
annotate map.js @ 269:ce747cd9ec59 gmap2
Add error situation handling.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 13 Apr 2014 23:41:40 +0300 |
parents | 98115d71bb64 |
children | 561640ed2204 |
rev | line source |
---|---|
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
1 // $Id: map.js 2404 2009-12-24 20:01:32Z jeskko $ |
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
2 |
250 | 3 var pmapBaseURL; |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
4 var pmap; |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
5 var pmapCanvas; |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
6 |
266
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
7 var pmapPlrPrevPos = {"x": 8192, "y": 8192}; |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
8 var pmapPlrMarker; |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
9 var pmapUpdateTime, pmapUpdateDelay; |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
10 |
170 | 11 var pmapTileSize = 256; |
12 var pmapTileOrig = pmapTileSize / 2.0; | |
13 var pmapTilePxPerDeg = pmapTileSize / 360.0; | |
14 var pmapTilePxPerRad = pmapTileSize / (2.0 * Math.PI); | |
15 | |
16 | |
171 | 17 function pmapMinMax(vval, vmin, vmax) |
170 | 18 { |
171 | 19 return Math.min(Math.max(vval, vmin), vmax); |
20 } | |
21 | |
22 | |
172 | 23 function pmapLatLngToMapCoords(latLng, zoom) |
171 | 24 { |
25 msiny = pmapMinMax(Math.sin((latLng.lat() * Math.PI) / 180.0), -0.9999, 0.9999); | |
170 | 26 |
27 px = latLng.lng() * pmapTilePxPerDeg; | |
28 py = 0.5 * Math.log((1 + msiny) / (1 - msiny)) * - pmapTilePxPerRad; | |
171 | 29 |
172 | 30 pz = 1 << zoom; |
31 return new google.maps.Point(px * pz, py * pz); | |
32 } | |
33 | |
34 | |
35 function pmapMapCoordsToLatLng(point, zoom) | |
36 { | |
37 pz = 1 << zoom; | |
38 px = point.x / pz; | |
39 py = point.y / pz; | |
40 | |
41 lng = (px - pmapTileOrig) / pmapTilePxPerDeg; | |
42 latRadians = (py - pmapTileOrig) / - pmapTilePxPerRad; | |
43 | |
44 //lat = radiansToDegrees(2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2); | |
45 //lat = (2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2) / (Math.PI / 180); | |
46 | |
47 lat = (360 * Math.atan(Math.exp(latRadians))) / Math.PI - 90; | |
48 | |
49 return new google.maps.LatLng(lat, lng); | |
170 | 50 } |
51 | |
52 | |
166 | 53 function CanvasProjectionOverlay() {} |
54 CanvasProjectionOverlay.prototype = new google.maps.OverlayView(); | |
55 CanvasProjectionOverlay.prototype.constructor = CanvasProjectionOverlay; | |
56 CanvasProjectionOverlay.prototype.onAdd = function(){}; | |
57 CanvasProjectionOverlay.prototype.draw = function(){}; | |
58 CanvasProjectionOverlay.prototype.onRemove = function(){}; | |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
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 |
262 | 61 function pmapInitializeMap(args) |
153 | 62 { |
171 | 63 // Initialize custom imagemap with our tiles |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
64 var pmapBatMap = new google.maps.ImageMapType( |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
65 { |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
66 getTileUrl: function(coord, zoom) |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
67 { |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
68 return "tiles/"+ zoom +"/"+ coord.y +"/"+ coord.x +".png"; |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
69 }, |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
70 |
171 | 71 tileSize: new google.maps.Size(pmapTileSize, pmapTileSize), |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
72 maxZoom: 10, |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
73 minZoom: 3, |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
74 radius: 1738000, |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
75 name: 'BatMap' |
153 | 76 }); |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
77 |
171 | 78 // Create map controller object |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
79 pmap = new google.maps.Map(document.getElementById("map"), |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
80 { |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
81 zoom: 3, |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
82 center: new google.maps.LatLng(-15, 10), |
153 | 83 |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
84 streetViewControl: false, |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
85 draggableCursor: 'crosshair', |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
86 draggingCursor: 'pointer', |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
87 mapTypeControl: false, |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
88 scaleControl: false, |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
89 rotateControl: false, |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
90 overviewMapControl: false, |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
91 }); |
153 | 92 |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
93 pmap.mapTypes.set('BatMap', pmapBatMap); |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
94 pmap.setMapTypeId('BatMap'); |
153 | 95 |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
96 pmapCanvas = new CanvasProjectionOverlay(); |
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
97 pmapCanvas.setMap(pmap); |
153 | 98 |
170 | 99 google.maps.event.addListener(pmap, "mousemove", pmapCoordinateListener); |
265
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
100 |
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
101 if (typeof(args) == "object") |
224
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
200
diff
changeset
|
102 { |
266
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
103 var posSet = false; |
265
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
104 if ("zoom" in args && "x" in args && "y" in args) |
224
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
200
diff
changeset
|
105 { |
266
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
106 pmapPlrPrevPos = {"x": args.x, "y": args.y}; |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
107 posSet = true; |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
108 |
265
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
109 google.maps.event.addDomListener(pmap, "foobar", function() |
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
110 { |
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
111 pmap.setZoom(args.zoom); |
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
112 pmap.panTo(pmapMapCoordsToLatLng(new google.maps.Point(args.x, args.y), 6)); |
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
113 var tgtMarker = pmapGetMarkerIndexByCoords(args.x, args.y); |
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
114 if (tgtMarker) |
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
115 pmapMyClick(tgtMarker); |
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
116 }); |
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
117 } |
266
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
118 |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
119 if ("token" in args && args.token != "") |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
120 { |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
121 // Create player position marker |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
122 pmapPlrMarker = new google.maps.Marker( |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
123 { |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
124 position: pmapMapCoordsToLatLng(new google.maps.Point(0, 0)), |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
125 draggable: false, |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
126 map: pmap |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
127 }); |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
128 |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
129 if (!posSet) |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
130 pmap.setZoom(9); |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
131 |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
132 pmapToken = args.token; |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
133 pmapUpdateTime = Date.now(); |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
134 pmapUpdateDelay = 0; |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
135 pmapUpdatePID = setInterval("pmapUpdatePlayerPosition()", 500); |
265
e908103cdcd8
Change how map initialization arguments are handled.
Matti Hamalainen <ccr@tnsp.org>
parents:
263
diff
changeset
|
136 } |
224
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
200
diff
changeset
|
137 } |
153 | 138 |
224
85ee47035acf
Open marker info window if specified coordinates hit it exactly.
Matti Hamalainen <ccr@tnsp.org>
parents:
200
diff
changeset
|
139 pmapInitializeNav(); |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
140 pmapInitializeIcons(); |
153 | 141 pmapInitializeMarkers(); |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
142 } |
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
143 |
93 | 144 |
151 | 145 // |
152 | 146 // Listener for updating coordinates display |
151 | 147 // |
153 | 148 function pmapCoordinateListener(point) |
93 | 149 { |
228 | 150 // Round the coordinates so that we hit the pointed square more accurately |
172 | 151 var p = pmapLatLngToMapCoords(point.latLng, 7); |
152 var tx = Math.round((p.x + 1) / 2.0); | |
153 var ty = Math.round((p.y + 1) / 2.0); | |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
154 |
200 | 155 var cx, cy; |
161
074b6936ec4f
"Kind of works", but not really. Almost nothing works. And even that
Matti Hamalainen <ccr@tnsp.org>
parents:
157
diff
changeset
|
156 var cont = "Deep Sea"; |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
157 |
157 | 158 for (i = 0; i < pmapContinents.length; i++) |
93 | 159 { |
157 | 160 var c = pmapContinents[i]; |
93 | 161 if (c != null && tx > c[1] && tx < c[3] && ty > c[2] && ty < c[4]) |
162 { | |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
163 cont = c[0]; |
170 | 164 cx = tx - c[1]; |
165 cy = ty - c[2]; | |
91
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
166 break; |
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
167 } |
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
168 } |
e4a37528f1a7
Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents:
76
diff
changeset
|
169 |
230 | 170 tx += pmapWorld.ox - 1; |
171 ty += pmapWorld.oy - 1; | |
200 | 172 |
173 var str = "Cursor: "+ | |
174 "Global X: <span class=\"coord\">"+ tx +"</span>, Y: <span class=\"coord\">"+ ty +"</span>, "+ | |
175 "Continent: <span class=\"continent\">"+ cont +"</span> "; | |
176 | |
177 if (cx >= 0 && cy >= 0) | |
178 str += "[ Local X: <span class=\"coord\">"+ cx +"</span>, Y: <span class=\"coord\">"+ cy +"</span> ]"; | |
179 | |
180 document.getElementById("footercontent").innerHTML = str; | |
153 | 181 } |
200 | 182 |
183 | |
184 function pmapMakeLink() | |
185 { | |
186 if (pmap) | |
187 { | |
188 var p = pmapLatLngToMapCoords(pmap.getCenter(), 6); | |
235
0e6fa3f5684d
Adjust generated link coordinates so that they match what we desire.
Matti Hamalainen <ccr@tnsp.org>
parents:
230
diff
changeset
|
189 var tx = Math.round(p.x) + pmapWorld.ox - 1; |
228 | 190 var ty = Math.round(p.y) + pmapWorld.oy; |
200 | 191 |
250 | 192 str = pmapBaseURL +"?x="+ tx +"&y="+ ty +"&zoom="+ pmap.getZoom(); |
200 | 193 |
194 window.prompt("Copy to clipboard: Ctrl+C, Enter", str); | |
195 } | |
196 } | |
266
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
197 |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
198 |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
199 function pmapUpdatePlayerPosition() |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
200 { |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
201 if (pmapToken && Date.now() - pmapUpdateTime >= pmapUpdateDelay) |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
202 { |
268
98115d71bb64
Some adjustments to realtime player position update code.
Matti Hamalainen <ccr@tnsp.org>
parents:
266
diff
changeset
|
203 pmapUpdateTime = Date.now(); |
266
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
204 // XDownloadUrl("http://www.bat.org/playerpos.php?token="+pmapToken, |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
205 XDownloadUrl("http://tnsp.org/gmapng/playerpos.php?token="+pmapToken, |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
206 function(data, responseCode) |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
207 { |
269
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
208 if (typeof(data) == "string") |
266
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
209 { |
269
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
210 if (data.match(/error/i)) |
266
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
211 { |
269
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
212 // In case of an error, stop updating |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
213 clearInterval(pmapUpdatePID); |
266
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
214 } |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
215 else |
269
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
216 if (data != "") |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
217 { |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
218 var pos = JSON.parse(data); |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
219 if (typeof(pos) == "object" && (pos.x != pmapPlrPrevPos.x || pos.y != pmapPlrPrevPos.y)) |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
220 { |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
221 pmapPlrMarker.setPosition(pmapMapCoordsToLatLng(new google.maps.Point(pos.x * 2 + 1, pos.y * 2 + 1), 7)); |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
222 pmap.panTo(pmapMapCoordsToLatLng(new google.maps.Point(pos.x, pos.y), 6)); |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
223 pmapPlrPrevPos = pos; |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
224 pmapUpdateDelay = 500; |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
225 } |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
226 else |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
227 if (pmapUpdateDelay < 5000) |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
228 pmapUpdateDelay += 500; |
ce747cd9ec59
Add error situation handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
268
diff
changeset
|
229 } |
266
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
230 } |
268
98115d71bb64
Some adjustments to realtime player position update code.
Matti Hamalainen <ccr@tnsp.org>
parents:
266
diff
changeset
|
231 else |
98115d71bb64
Some adjustments to realtime player position update code.
Matti Hamalainen <ccr@tnsp.org>
parents:
266
diff
changeset
|
232 pmapUpdateDelay = 10000; |
98115d71bb64
Some adjustments to realtime player position update code.
Matti Hamalainen <ccr@tnsp.org>
parents:
266
diff
changeset
|
233 }, |
98115d71bb64
Some adjustments to realtime player position update code.
Matti Hamalainen <ccr@tnsp.org>
parents:
266
diff
changeset
|
234 function() |
98115d71bb64
Some adjustments to realtime player position update code.
Matti Hamalainen <ccr@tnsp.org>
parents:
266
diff
changeset
|
235 { |
98115d71bb64
Some adjustments to realtime player position update code.
Matti Hamalainen <ccr@tnsp.org>
parents:
266
diff
changeset
|
236 pmapUpdateDelay = 10000; |
266
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
237 }); |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
238 } |
b50a7ab76548
Implement client-side code for tracking player position.
Matti Hamalainen <ccr@tnsp.org>
parents:
265
diff
changeset
|
239 } |