Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/mapviewer/mapCenter.html
blob: 41d5a9c46530dad2d3d593326fa6b6295f39855c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
<html>
<head id="head">
	<title>Offline Map</title>
<script src="MediaMarker.js" type="text/javascript"></script>
<script src="file:///home/olpc/Library/MapPack/Maps.js" type="text/javascript"></script>
<script type="text/javascript">
var zm=10;
var realZm=800;
var xOff=0;
var yOff=0;
var factor=0.75;
var westBound=-74.44;
var northBound=20.14;
var portMapOn=false;
var markerList=[];
var lineList=[];
var editTxt="Edit";
var addTxt="Add";
var describeTxt="Describe this place";
var ajaxPort,cometPort,mID,canvas;
var isMedia=false;
var addingInfo=false;
var iMarker = null;
var addingMedia=false;
var addingLines=false;
var currentLine=-1;
var addingPasteMap=false;
var pasteType="";
var mediaWin=null;
var isOffXO=false;
function gup(nm){nm=nm.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");var rxS="[\\?&]"+nm+"=([^&#]*)";var rx=new RegExp(rxS);var rs=rx.exec(window.location.href);if(!rs){return null;}else{return rs[1];}}
function init(){
	ajaxPort = gup("ajaxPort");
	cometPort = gup("cometPort");
	lhCometInit();
	canvas = $("mapCover").getContext("2d");
	try{
		//fix all image links
		for(var m=0;m<maps.length;m++){
			if(isOffXO){
				maps[m].link="../../MapPack/" + maps[m].link;
			}
			else{
				maps[m].link="file:///home/olpc/Library/MapPack/" + maps[m].link;
			}
			if(m>0){
				maps[m].mapdiv=$("overlay-"+maps[m].mapCode);
				maps[m].isOn=false;
			}
			else{
				// set base map
				$("mapItself").src=maps[0].link;
			}
		}
	}
	catch(e){
		// testing without XO Laptop, assume it's in a neighboring folder
		isOffXO=true;
		var newScript = document.createElement('script');
		newScript.src = "../../MapPack/Maps.js"
		newScript.type = "text/javascript";
		newScript.onload = init;
		$("head").appendChild(newScript);
		return;
	}
	/*
	var grandG={x:0.5904,y:0.5987,width:0.0168,zoom:18,isOn:false,src:"GrandGoave.jpg"};
		grandG.mapdiv=$("overlay-5");
	var sofMira={x:0.4894,y:0.598,width:0.015,zoom:16,isOn:false,src:"SofMiragoane.jpg"};
		sofMira.mapdiv=$("overlay-3");
	*/	
	var southWest = toLatLng(0,600);
	var northEast = toLatLng(800,0);
	var newScript = document.createElement('script');
	newScript.src = "http://127.0.0.1:" + ajaxPort + "/mediaQuery.js?s=" + southWest[0] + "&w=" + southWest[1] + "&n=" + northEast[0] + "&e=" + northEast[1];
	newScript.type = "text/javascript";
	newScript.onload = lhAjax;
	$("head").appendChild(newScript);
	//addPt(-1.95575,30.437354,"blue crates thing","blue",false);
	//addPt(0.021026,32.441184,"blue",false);
	//moveTo(18.52876,-73.512198,20);
	//addLine("x00x2","#00f",8,[[19,-73],[18.9,-71]]);
	//addLine("poly-x00x3","#f00",8,[[19.7,-72.79],[20.1,-73.173],[19.79,-73.31]]);
}
function lineMode(type){
	if(addingLines){
		addingLines = false;
		$("mapCover").className = "-moz-grab";
		var newScript = document.createElement('script');
		var dLine = lineList[currentLine];
		var ptOutput = [];
		for(var p=0;p<dLine.pts.length;p++){
			ptOutput.push(dLine.pts[p][0] + "|" + dLine.pts[p][1]);
		}
		ptOutput = ptOutput.join("|");
		newScript.src = "http://127.0.0.1:" + ajaxPort + "/addLine.js?id=" + dLine.id + "&col=" + dLine.color.replace("#","") + "&thick=4&pts=" + ptOutput;
		newScript.type = "text/javascript";
		newScript.onload = lhAjax;
		$("head").appendChild(newScript);
		//showInfo(newScript.src);
		currentLine = -1;
		updateLines();
	}
	else{
		addingLines = true;
		$("mapCover").className = "crosshairMap";
		var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
		var colorchars = "0123456789abcdef";
		var string_length = 8;
		var lineID = '';
		for(var i=0; i<string_length; i++) {
			var rnum = Math.floor(Math.random() * chars.length);
			lineID += chars.substring(rnum,rnum+1);
		}
		if(type.indexOf("poly") != -1){
			lineID = "poly-" + lineID;
		}
		var randColor = "";
		for(var i=0; i<3; i++){
			var rnum = Math.floor(Math.random() * colorchars.length);
			randColor += colorchars.substring(rnum,rnum+1);
		}
		currentLine = lineList.length;
		addLine(lineID,randColor,4,[]);
	}
}
function placeVertex(event){
	var vert = toLatLng(event.clientX,event.clientY);
	lineList[currentLine].pts.push(vert)
	updateLines();
}
function addLine(line_id,line_color,line_thick,line_pts){
	try{
		if(line_pts.indexOf("|") != -1){
			//in |-separated format from Python
			line_pts_b = line_pts.split("|");
			line_pts=[];
			for(var lpi=0;lpi<line_pts_b.length;lpi+=2){
				line_pts.push([line_pts_b[lpi],line_pts_b[lpi+1]]);
			}
		}
	}
	catch(e){}
	for(var l=0;l<lineList.length;l++){
		if(lineList[l].id==line_id){
			lineList[l].color="#"+line_color;
			lineList[l].thickness=line_thick;
			lineList[l].pts=line_pts;
			updateLines();
			return;
		}
	}
	lineList.push({id:line_id,color:"#"+line_color,thickness:line_thick,pts:line_pts});
	if(!addingLines){
		currentLine=lineList.length-1;
		addingLines=true;
		lineMode('new');
	}
}
function updateLines(){
	if(lineList.length == 0){ return }
	$("mapCover").width=$("mapCover").width;
	for(var l=0;l<lineList.length;l++){
		var dLine=lineList[l];
		if(dLine.pts.length < 2){continue}
		var lastPt=dLine.pts[0];
		var drewLast=false;
		var firstPt=lastPt;
		if(dLine.id.indexOf("poly")==-1){
			canvas.strokeStyle=dLine.color;
			canvas.lineWidth=dLine.thickness;
		}
		else{
			canvas.fillStyle=dLine.color;
			canvas.lineWidth=0;
			//canvas.strokeStyle="#000";
			drewLast=true;
		}
		if(inBounds(pixel(lastPt[0],lastPt[1]))||drewLast){
			drewLast = true;
			canvas.beginPath();
			canvas.moveTo(parseInt(pixel(lastPt[0],lastPt[1])[0]),parseInt(pixel(lastPt[0],lastPt[1])[1]));
		}
		for(var p=1;p<dLine.pts.length;p++){
			var thisPt=dLine.pts[p];
			if(drewLast){
				canvas.lineTo(parseInt(pixel(thisPt[0],thisPt[1])[0]),parseInt(pixel(thisPt[0],thisPt[1])[1]));
			}
			else{
				if(inBounds(pixel(lastPt[0],lastPt[1]))){
					drewLast=true;
					canvas.beginPath();
					canvas.moveTo(parseInt(pixel(lastPt[0],lastPt[1])[0]),parseInt(pixel(lastPt[0],lastPt[1])[1]));
					canvas.lineTo(parseInt(pixel(thisPt[0],thisPt[1])[0]),parseInt(pixel(thisPt[0],thisPt[1])[1]));
				}
			}
			lastPt=thisPt;
		}
		if(drewLast){
			if(dLine.id.indexOf("poly")==-1){
				canvas.stroke();
			}
			else{
				canvas.closePath();
				canvas.fill();
			}
		}
	}
	if(currentLine>=0){
		//draw a square at each point in the line or polygon
		for(var p=0;p<lineList[currentLine].pts.length;p++){
			var thisPt=lineList[currentLine].pts[p];
			canvas.fillStyle="#000";
			canvas.fillRect(parseInt(pixel(thisPt[0],thisPt[1])[0])-6,parseInt(pixel(thisPt[0],thisPt[1])[1])-6,12,12);
		}
	}
}
function inBounds(px){
	if(px[0]<0){return false;}
	if(px[0]>820){return false;}
	if(px[1]<0){return false;}
	if(px[1]>520){return false;}
	return true;
}
function mapPaste(type){
	addingPasteMap=true;
	pasteType=type;
	$("mapCover").className = "crosshairMap";
}
function placeOverlay(event){
	addingPasteMap=false;
	$("mapCover").className="-moz-grab";
	var ctr = toLatLng(event.clientX,event.clientY);
	var standardZoom = 17;
	if(zm < 13){
		standardZoom = 10;
	}
	else if(zm < 16){
		standardZoom = 12;
	}
	else if(zm < 18){
		standardZoom = 14;
	}
	else{
		standardZoom = 15;
	}
	addPt(toLatLng(304,152)[0],toLatLng(304,152)[1],"","orange",false);
	var minimap = markerList[markerList.length-1].iconDiv;
	minimap.onclick="";
	if(pasteType=='osm'){
		minimap.src="http://pafciu17.dev.openstreetmap.org/?module=map&width=640&height=404&center="+ctr[1]+","+ctr[0]+"&zoom="+standardZoom;
	}
	else{
		minimap.src="http://maps.google.com/maps/api/staticmap?sensor=false&key=ABQIAAAAxkKtrWN5q-vPTLRVmO_r6RRFDCLHCbUG3VrjXnZmMRXvQdFL3RS-b-ld9hTrkIgQlYsxPQ1kYq6y9A&size=640x404&format=jpg&center="+ctr[0]+","+ctr[1]+"&zoom="+standardZoom+"&maptype=hybrid";
	}
	minimap.onclick="";
	minimap.style.zIndex=-1;
	var bds = getStandardBounds(ctr,standardZoom); // returns [ sw=[lat,lng] , ne=[lat,lng] ]	
	var osmMap={north:bds[1][0],east:bds[1][1],west:bds[0][1],mapCode:-1,showZoom:zm-1,isOn:true};
	osmMap.mapdiv=minimap;
	maps.push(osmMap);
	markerList.pop();
	portMapGo();
}
function filterTags(sTerms){
	sTerms = unescape(sTerms).toLowerCase();
	sTerms = replaceAll(sTerms," ","");
	for(var m=0;m<markerList.length;m++){
		var formattedInfo = replaceAll(markerList[m].info.toLowerCase()," ","");
		if(formattedInfo.indexOf(sTerms) != -1){
			moveTo(markerList[m].pt[0],markerList[m].pt[1]);
			closeiWin();
			isMedia=false;
			showInfo(markerList[m].info);
			var bigMarker = markerList[m].iconDiv;
			bigMarker.width=parseInt(1.8*bigMarker.width);
			setTimeout(function(){bigMarker.width/=1.8},5000);
			return;
		}
	}
}
function replaceAll(src,old,fix){
	while(src.indexOf(old) != -1){
		src = src.replace(old,fix);
	}
	return src;
}
function lhCometInit()
{	var newScript = document.createElement('script');
	var d = new Date();
	newScript.src = "http://127.0.0.1:" + cometPort + "/comet.js?t="+d.getTime()
	newScript.type = "text/javascript";
	newScript.onload = lhCometResponse;
	$("head").appendChild(newScript);
}
function lhCometResponse(){ lhCometInit(); }
function moveTo(lat,lng){moveTo(lat,lng,zm)}
function moveTo(lat,lng,zoom){
	while(zoom > zm){zoomIn()}
	while(zoom < zm){zoomOut()}
	var currentOffset = pixel(lat,lng);
	xOff+=(410-1*currentOffset[0]);
	yOff+=(260-1*currentOffset[1]);
	$("mapItself").style.left=xOff;
	$("mapItself").style.top=yOff;
	portMapGo();
}
function preAddInfo(){
	closeiWin();
	addingInfo=true;
	$("mapCover").className = "crosshairMap";
}
function placeInfoMarker(event){
	addingInfo = false;
	var loc = toLatLng(event.clientX,event.clientY);
	addPt(loc[0],loc[1],describeTxt,"magenta",true);
	addedMedia();
}
function addPt(lat,lng,text,color,showNow){
	for(var i=0;i<markerList.length;i++){
		if(markerList[i].pt[0] == lat){
			if(markerList[i].pt[1] == lng){
				markerList[i].info = unescape(text);
				return;
			}
		}
	}
	var mk = MediaMarker();
	mID="info-"+markerList.length;
	mk.initialize([lat,lng],null,mID,null,unescape(text),color+"_map_dot.png");
	mk.iconDiv=document.createElement("img");
	mk.iconDiv.className="marker";
	mk.iconDiv.src=mk.icon;
	var px=pixel(mk.pt[0],mk.pt[1]);
	mk.iconDiv.style.left=parseInt(px[0]-mk.iconDiv.width/2)+"px";
	mk.iconDiv.style.top=parseInt(px[1]-mk.iconDiv.height/2)+"px";
	mk.iconDiv.style.position="absolute";
	mk.iconDiv.style.display="block";
	mk.iconDiv.onclick=function(event){mID=mk.markerId;isMedia=false;showInfo(mk.get_info());}
	document.body.appendChild(mk.iconDiv);
	markerList.push(mk);
	if(showNow){
		isMedia = false;
		mID=mk.getMarkerId();
		showInfo(text);
	}
}
function pixel(lat,lng){
	//top left is estimated to be 20.18025 N, -74.62984 W
	var latdiff = (maps[0].north - 1.00*lat)*latFactor*Math.pow(1.35,zm-10.0);
	var lngdiff = (1.00*lng - maps[0].west)*lngFactor*Math.pow(1.35,zm-10.0);
	var x = lngdiff*1.00 + xOff*1.00;
	var y = latdiff*1.00 + yOff*1.00;
	return [x,y];
}
function zoomIn(){
	var centerLL = toLatLng(410,260);
	zm+=1;
	realZm*=1.35;
	$("mapItself").style.width=parseInt(realZm)+"px";
	xOff=1*$("mapItself").style.left.replace("px","").replace("pt","");
	yOff=1*$("mapItself").style.top.replace("px","").replace("pt","");
	moveTo(centerLL[0],centerLL[1]);
}
function zoomOut(){
	var centerLL = toLatLng(410,260);
	zm-=1;
	realZm/=1.35;
	$("mapItself").style.width=parseInt(realZm);
	xOff=1*$("mapItself").style.left.replace("px","").replace("pt","");
	yOff=1*$("mapItself").style.top.replace("px","").replace("pt","");
	moveTo(centerLL[0],centerLL[1]);
}
function moveLeft(){
	xOff+=2000/zm;
	$("mapItself").style.left=parseInt(xOff);
	portMapGo();
}
function moveRight(){
	xOff-=2000/zm;
	$("mapItself").style.left=parseInt(xOff);
	portMapGo();
}
function moveUp(){
	yOff+=2000/zm;
	$("mapItself").style.top=parseInt(yOff);
	portMapGo();
}
function moveDown(){
	yOff-=2000/zm;
	$("mapItself").style.top=parseInt(yOff);
	portMapGo();
}
function mrkWithId(id){
	for(var i=0;i<markerList.length;i++){
		if(markerList[i].getMarkerId() == id){
			return markerList[i];
		}
	}
}
function editInfoMarker(id){
	iMarker = mrkWithId(id);
	mID = id;
	isMedia = true;
	showInfo("<textarea id='infoText' style='height:400;width:350;'>" + iMarker.get_info() + "</textarea><br/><input type='button' class='centerButton' value='" + addTxt + "' onclick='updateInfo(\"" + iMarker.getMarkerId() + "\")'/>");
}
function updateInfo(id){
	closeiWin();
	var iMarker = mrkWithId(id);
	iMarker.info = $("infoText").value;
	var loc = iMarker.getLatLng();
	var newScript = document.createElement('script');
	newScript.src = "http://127.0.0.1:" + ajaxPort + "/addInfoMarker.js?lat=" + loc[0] + "&lng=" + loc[1] + "&info=" + iMarker.info + "&icon=" + iMarker.icon + "&isNew=True";
	newScript.type = "text/javascript";
	newScript.onload = lhAjax;
	$("head").appendChild(newScript);
}
function lhAjax(){}
function updateMarkers(){
	for(var m=0;m<markerList.length;m++){
		var lat=markerList[m].pt[0];
		var lng=markerList[m].pt[1];
		var px=pixel(lat,lng);
		markerList[m].iconDiv.style.left=parseInt(px[0]-markerList[m].iconDiv.width/2);
		markerList[m].iconDiv.style.top=parseInt(px[1]-markerList[m].iconDiv.height/2);
	}
}
function getStandardBounds(centerLL,zoom){
	var sw=[1*centerLL[0]-0.55618*Math.pow(2,(9-1*zoom)),centerLL[1]*1 - 0.98877*Math.pow(2,(9-1*zoom))];
	var ne=[1*centerLL[0]+0.55618*Math.pow(2,(9-1*zoom)),centerLL[1]*1 + 0.98877*Math.pow(2,(9-1*zoom))];
	return [sw,ne];
}
function portMapGo(){
	//skip m=0, that's the base map
	for(var m=1;m<maps.length;m++){
		if(zm>=maps[m].showZoom){
			if((pixel(maps[m].north,maps[m].east)[0]<0)||(pixel(maps[m].north,maps[m].west)[0]>820)){
				maps[m].isOn=false;
				if(maps[m].mapCode > 0){
					if(maps[m].mapdiv.src.indexOf(maps[m].link.replace("../../",""))!=-1){
						maps[m].mapdiv.style.display="none";
					}
				}
				else{
					maps[m].mapdiv.style.display="none";
				}
			}
			else if((pixel(maps[m].north,maps[m].west)[1]+1*maps[m].mapdiv.height<0)||(pixel(maps[m].north,maps[m].west)[1]>620)){
				maps[m].isOn=false;
				if(maps[m].mapCode > 0){
					if(maps[m].mapdiv.src.indexOf(maps[m].link.replace("../../",""))!=-1){
						maps[m].mapdiv.style.display="none";
					}
				}
				else{
					maps[m].mapdiv.style.display="none";
				}
			}
			else{
				maps[m].isOn=true;
				if(maps[m].mapCode > 0){
					//shared image-div
					if(maps[m].mapdiv.src.indexOf(maps[m].link.replace("../../",""))==-1){
						//swap between major maps
						maps[m].mapdiv.src=maps[m].link;
					}
				}
				var topleft = pixel(maps[m].north,maps[m].west);
				var mWidth = pixel(maps[m].north,maps[m].east)[0]-topleft[0];
				maps[m].mapdiv.style.width = parseInt(mWidth);
				maps[m].mapdiv.style.left=parseInt(topleft[0]);
				maps[m].mapdiv.style.top=parseInt(topleft[1]);
				maps[m].mapdiv.style.display="block";
			}
		}
		else{
			if(maps[m].mapdiv.src.indexOf(maps[m].src)!=-1){
				maps[m].mapdiv.style.display="none";
			}
			maps[m].isOn=false;
		}
	}
	updateMarkers();
	updateLines();
}
function showInfo(er){
	//if(er==''){return}
	if(!isMedia){
		if(er.indexOf("::") != -1){
			if(er.indexOf('wiki::') != -1){ er = '<b>' + er.replace('wiki::','</b><iframe height="400" width="350" src="http://simple.m.wikipedia.org/wiki/') + '"></iframe>'; }
			else if(er.indexOf('img::') != -1){ er = '<b>' + er.replace('img::','</b><br/><img style="max-height:400;max-width:350;" src="') + '"/>'; }
			else if(er.indexOf('pic::') != -1){ er = '<b>' + er.replace('pic::','</b><br/><img style="max-height:400;max-width:350;" src="') + '"/>'; }
			else if(er.indexOf('google::') != -1){ er = er.replace('google::','<iframe height="400" width="350" src="http://google.com/search?q=') + '"></iframe>'; }
			else if(er.indexOf('vid::') != -1){ er = '<b>' + er.replace('vid::','</b><br/><object width="400" height="350" type="application/ogg" data="') + '"></object>'; }
			else if((er.indexOf('wiki') != -1)&&(er.indexOf('::') > er.indexOf('wiki'))){
				var erBegin = er.substring(0,er.lastIndexOf('wiki'));
				er = er.substring(er.lastIndexOf('wiki'));
				var wikiCode = er.substring(4,er.indexOf('::'));
				er = er.substring(er.indexOf('::') + 2);
				er = '<b>' + erBegin + '</b><iframe height="400" width="350" src="http://' + wikiCode + '.m.wikipedia.org/wiki/' + er + '"></iframe>';
			}
		}
		er+="<br/><input type='button' class='centerButton' value='" + editTxt + "' onclick='editInfoMarker(" + '"' + mID + '"' + ")'/>";
	}
	$("iWin").innerHTML = er;
	$("iEnc").style.display = "block";
	$("iWin").style.display = "block";
}
function closeiWin(){
	$("iWin").style.display = "none";
	$("iEnc").style.display = "none";
	mediaWin=null;
	var newScript = document.createElement('script');
	var d = new Date();
	newScript.src = "http://127.0.0.1:" + ajaxPort + "/hideMedia.js?t="+d.getTime()
	newScript.type = "text/javascript";
	$("head").appendChild(newScript);
}
function toLatLng(x,y){
	x+=".000000";
	y+=".000000";
	x-=xOff;
	y-=yOff;
	var latdiff = y / latFactor / Math.pow(1.35,zm-10);
	var lngdiff = x / lngFactor / Math.pow(1.35,zm-10);
	var mapLat = maps[0].north - latdiff;
	var mapLng = maps[0].west + lngdiff;
	return [mapLat.toFixed(5),mapLng.toFixed(5)];
}
function updateLoc(){
	var ctr = toLatLng(410,260);
	var newScript = document.createElement('script');
	if(mediaWin != null){
		newScript.src = "http://127.0.0.1:" + ajaxPort + "/updateLocation.js?lat=" + ctr[0] + "&lng=" + ctr[1] + "&z=" + zm + "&x=" + ($("iEnc").offsetLeft*1 + 25) + "&y=" + ($("iEnc").offsetTop*1 + 30);
	}
	else{
		newScript.src = "http://127.0.0.1:" + ajaxPort + "/updateLocation.js?lat=" + ctr[0] + "&lng=" + ctr[1] + "&z=" + zm + "&x=-1&y=-1";
	}
	newScript.type = "text/javascript";
	newScript.onload = lhAjax;
	$("head").appendChild(newScript);
}
function infoImg(id){
	showMedia('<div style="color:#fff;font-size:45pt;width:200;">a<br/>b<br/>a<br/>b<br/><Media>a</div>');
	var newScript=document.createElement('script');
	newScript.src="http://127.0.0.1:" + ajaxPort + "/showMedia.js?id=" + id + "&x=" + ($("iEnc").offsetLeft*1 + 25) + "&y=" + ($("iEnc").offsetTop*1 + 10) + "&up=true&rt=true";
	newScript.type="text/javascript";
	newScript.onload=lhAjax;
	$("head").appendChild(newScript);
}
function showMedia(er){
	mediaWin = $("iWin");
	$("iWin").innerHTML = er;
	$("iEnc").style.display = "block";
	$("iWin").style.display = "block";
}
function preAddMedia()
{	if(!mediaWin){closeiWin();}
	addingMedia = true;
	updateLoc();
	$("mapCover").className="crosshairMap";
}
function placeAddMedia(event){	
	var pt=toLatLng(event.clientX, event.clientY);
	var newScript=document.createElement('script');
	newScript.src="http://127.0.0.1:" + ajaxPort + "/placeAddMedia.js?lat=" + pt[0] + "&lng=" + pt[1];
	newScript.type="text/javascript";
	newScript.onload=lhAjax;
	$("head").appendChild(newScript);
	addedMedia();
}
function postAddMedia( lat, lng, url, basename, tags ){
	var mk=MediaMarker();
	mk.initialize([lat,lng],url,basename,tags);
	mk.iconDiv=document.createElement("img");
	mk.iconDiv.className="marker";
	mk.iconDiv.src="orange_map_dot.png";
	var px=pixel(mk.pt[0],mk.pt[1]);
	mk.iconDiv.style.left=parseInt(px[0]-mk.iconDiv.width/2)+"px";
	mk.iconDiv.style.top=parseInt(px[1]-mk.iconDiv.height/2)+"px";
	mk.iconDiv.style.position="absolute";
	mk.iconDiv.style.display="block";
	mk.iconDiv.onclick=function(event){mID=mk.markerId;infoImg(mID);}
	document.body.appendChild(mk.iconDiv);
	markerList.push(mk);
	hidePics();
	addedMedia();
	infoImg(mk.markerId);
	updateLoc();
}
function addedMedia()
{	addingMedia=false;
	$("mapCover").className="-moz-grab";
}
function clickToZoom(event){
	var ctr = toLatLng(event.clientX,event.clientY);
	moveTo(ctr[0],ctr[1],zm+1);
}
function $(id){return document.getElementById(id)}
</script>
<style type="text/css">
body{font-family:arial}
#iEnc{position:absolute;left:150;top:30;-moz-border-radius:10;border:2px solid #000;background:#fff;width:390;padding:3;padding-left:10;display:none;z-index:10}
input.cBtn{float:right}
input:hover{color:#000;cursor:pointer}
canvas.crosshairMap{cursor:crosshair}
img.marker{cursor:pointer}
</style>
</head>
<body onload="init()">
	<img id="mapItself" src="" style="position:absolute;left:0px;top:0px;width:800px;z-Index:-5"/>
	<div id="miniMaps">
		<img id="overlay-1" src="orange_map_dot.png" style="position:absolute;display:none;z-index:-4;"/>
		<img id="overlay-2" src="orange_map_dot.png" style="position:absolute;display:none;z-index:-4;"/>
		<img id="overlay-3" src="orange_map_dot.png" style="position:absolute;display:none;z-index:-4;"/>
		<img id="overlay-4" src="orange_map_dot.png" style="position:absolute;display:none;z-index:-4;"/>
		<img id="overlay-5" src="orange_map_dot.png" style="position:absolute;display:none;z-index:-4;"/>
	</div>
	<canvas id="mapCover" style="position:absolute;left:0px;top:0px;" width="820" height="520" onclick="if(addingMedia){placeAddMedia(event)}if(addingInfo){placeInfoMarker(event)}if(addingLines){placeVertex(event)}if(addingPasteMap){placeOverlay(event)}" ondblclick="clickToZoom(event)"></canvas>
	<div style="position:absolute;left:20px;top:80px;background-color:#fff;border:1px solid #000;z-index:100;">
		<input type="button" value="+" style="font-size:12pt;z-index:101;" onclick="zoomIn()"/>
		<input type="button" value="-" style="font-size:12pt;z-index:101;" onclick="zoomOut()"/>
		<table>
		<tr><td></td><td><input type="button" value="&uarr;" style="font-size:12pt;z-index:101;" onclick="moveUp()"/></td><td></td></tr>
		<tr><td><input type="button" value="&larr;" style="font-size:12pt;z-index-101;" onclick="moveLeft()"/></td><td></td><td><input type="button" value="&rarr;" style="font-size:12pt;" onclick="moveRight()"/></td></tr>
		<tr><td></td><td><input type="button" value="&darr;" style="font-size:12pt;z-index:101;" onclick="moveDown()"/></td><td></td></tr>
		</table>
	</div>
	<div id="iEnc"><input type="button" class="cBtn" onclick="closeiWin()" value="x"/><div id="iWin"></div></div>
</body>
</html>