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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
ee5492ccba8e Add configurable base URL.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
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
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
11 var pmapTileSize = 256;
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
12 var pmapTileOrig = pmapTileSize / 2.0;
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
13 var pmapTilePxPerDeg = pmapTileSize / 360.0;
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
14 var pmapTilePxPerRad = pmapTileSize / (2.0 * Math.PI);
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
15
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
16
171
b874aae3e75f Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
17 function pmapMinMax(vval, vmin, vmax)
170
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
18 {
171
b874aae3e75f Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
19 return Math.min(Math.max(vval, vmin), vmax);
b874aae3e75f Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
20 }
b874aae3e75f Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
21
b874aae3e75f Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
22
172
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
23 function pmapLatLngToMapCoords(latLng, zoom)
171
b874aae3e75f Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
24 {
b874aae3e75f Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
25 msiny = pmapMinMax(Math.sin((latLng.lat() * Math.PI) / 180.0), -0.9999, 0.9999);
170
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
26
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
27 px = latLng.lng() * pmapTilePxPerDeg;
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
28 py = 0.5 * Math.log((1 + msiny) / (1 - msiny)) * - pmapTilePxPerRad;
171
b874aae3e75f Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
29
172
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
30 pz = 1 << zoom;
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
31 return new google.maps.Point(px * pz, py * pz);
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
32 }
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
33
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
34
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
35 function pmapMapCoordsToLatLng(point, zoom)
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
36 {
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
37 pz = 1 << zoom;
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
38 px = point.x / pz;
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
39 py = point.y / pz;
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
40
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
41 lng = (px - pmapTileOrig) / pmapTilePxPerDeg;
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
42 latRadians = (py - pmapTileOrig) / - pmapTilePxPerRad;
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
43
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
44 //lat = radiansToDegrees(2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2);
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
45 //lat = (2 * Math.atan(Math.exp(latRadians)) - Math.PI / 2) / (Math.PI / 180);
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
46
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
47 lat = (360 * Math.atan(Math.exp(latRadians))) / Math.PI - 90;
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
48
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
49 return new google.maps.LatLng(lat, lng);
170
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
50 }
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
51
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
52
166
21cf84dcae73 Move code.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
53 function CanvasProjectionOverlay() {}
21cf84dcae73 Move code.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
54 CanvasProjectionOverlay.prototype = new google.maps.OverlayView();
21cf84dcae73 Move code.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
55 CanvasProjectionOverlay.prototype.constructor = CanvasProjectionOverlay;
21cf84dcae73 Move code.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
56 CanvasProjectionOverlay.prototype.onAdd = function(){};
21cf84dcae73 Move code.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
57 CanvasProjectionOverlay.prototype.draw = function(){};
21cf84dcae73 Move code.
Matti Hamalainen <ccr@tnsp.org>
parents: 161
diff changeset
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
254343316a90 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 250
diff changeset
61 function pmapInitializeMap(args)
153
a7f43ddd1c5e Functionalize.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
62 {
171
b874aae3e75f Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
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
b874aae3e75f Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
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
a7f43ddd1c5e Functionalize.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
76 });
91
e4a37528f1a7 Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents: 76
diff changeset
77
171
b874aae3e75f Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 170
diff changeset
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
a7f43ddd1c5e Functionalize.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
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
a7f43ddd1c5e Functionalize.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
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
a7f43ddd1c5e Functionalize.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
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
a7f43ddd1c5e Functionalize.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
98
170
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
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
a7f43ddd1c5e Functionalize.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
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
a7f43ddd1c5e Functionalize.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
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
2324a519ebec Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
144
151
13e75e9e732a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
145 //
152
095754c6b332 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 151
diff changeset
146 // Listener for updating coordinates display
151
13e75e9e732a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 143
diff changeset
147 //
153
a7f43ddd1c5e Functionalize.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
148 function pmapCoordinateListener(point)
93
2324a519ebec Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
149 {
228
2be6060df6cc Use global offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
150 // Round the coordinates so that we hit the pointed square more accurately
172
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
151 var p = pmapLatLngToMapCoords(point.latLng, 7);
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
152 var tx = Math.round((p.x + 1) / 2.0);
c62f0cf2bf16 It almost works \:D\
Matti Hamalainen <ccr@tnsp.org>
parents: 171
diff changeset
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
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
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
fadfd0e0a312 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
158 for (i = 0; i < pmapContinents.length; i++)
93
2324a519ebec Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
159 {
157
fadfd0e0a312 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 153
diff changeset
160 var c = pmapContinents[i];
93
2324a519ebec Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
161 if (c != null && tx > c[1] && tx < c[3] && ty > c[2] && ty < c[4])
2324a519ebec Cosmetic cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
162 {
91
e4a37528f1a7 Convert line ends via dos2unix.
Matti Hamalainen <ccr@tnsp.org>
parents: 76
diff changeset
163 cont = c[0];
170
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
164 cx = tx - c[1];
fb98e644b80c Fix coordinates display.
Matti Hamalainen <ccr@tnsp.org>
parents: 166
diff changeset
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
c5a06121ed95 Adjust coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
170 tx += pmapWorld.ox - 1;
c5a06121ed95 Adjust coordinates.
Matti Hamalainen <ccr@tnsp.org>
parents: 228
diff changeset
171 ty += pmapWorld.oy - 1;
200
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
172
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
173 var str = "Cursor: "+
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
174 "Global X: <span class=\"coord\">"+ tx +"</span>, Y: <span class=\"coord\">"+ ty +"</span>, "+
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
175 "Continent: <span class=\"continent\">"+ cont +"</span> ";
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
176
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
177 if (cx >= 0 && cy >= 0)
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
178 str += "[ Local X: <span class=\"coord\">"+ cx +"</span>, Y: <span class=\"coord\">"+ cy +"</span> ]";
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
179
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
180 document.getElementById("footercontent").innerHTML = str;
153
a7f43ddd1c5e Functionalize.
Matti Hamalainen <ccr@tnsp.org>
parents: 152
diff changeset
181 }
200
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
182
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
183
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
184 function pmapMakeLink()
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
185 {
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
186 if (pmap)
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
187 {
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
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
2be6060df6cc Use global offsets.
Matti Hamalainen <ccr@tnsp.org>
parents: 224
diff changeset
190 var ty = Math.round(p.y) + pmapWorld.oy;
200
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
191
250
ee5492ccba8e Add configurable base URL.
Matti Hamalainen <ccr@tnsp.org>
parents: 235
diff changeset
192 str = pmapBaseURL +"?x="+ tx +"&y="+ ty +"&zoom="+ pmap.getZoom();
200
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
193
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
194 window.prompt("Copy to clipboard: Ctrl+C, Enter", str);
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
195 }
f5aa704b1ddf Add "Make a link" feature.
Matti Hamalainen <ccr@tnsp.org>
parents: 172
diff changeset
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 }