Filter:   InfoImg
download overview-summary-kaMap.js.html
Language: NonCode
LOC: 0
Project Info
ka-map
Server: Maptools
Type: cvs
Maptools\k\ka‑map\ka‑map\docs\
   _BrowserIdent.html
   _eventManager.html
   _layer.html
   _map.html
   _overlayLayer.html
   _queueManager.html
   _wmsLayer.html
   allclasses-frame.html
   allclasses-noframe.html
   GLOBALS.html
   help-doc.html
   index-all.html
   index.html
   kaDoc.html
   kaKeymap.html
   kaLegend.html
   kaMap.html
   kaNavigator.html
   kaOverlay.html
   kaQuery.html
   kaTool.html
   kaXmlFeature.html
   kaXmlGraphicElement.html
   kaXmlIcon.html
   kaXmlLabel.html
   kaXmlLinestring.html
   kaXmlOverlay.html
   kaXmlPoint.html
   kaXmlPolygon.html
   kaXmlSymbol.html
   overview-DHTMLapi.js.html
   overview-frame.html
   overview-kaKeymap.js.html
   overview-kaLegend.js.html
   overview-kaMap.js.html
   overview-kaOverlay.js.html
   overview-kaQuery.js.html
   ...view-kaScalebar.js.html
   overview-kaTool.js.html
   ...ew-kaXmlOverlay.js.html
   overview-kaZoomer.js.html
   ...ew-overlayLayer.js.html
   overview-scalebar.js.html
   ...ummary-DHTMLapi.js.html
   ...ummary-kaKeymap.js.html
   ...ummary-kaLegend.js.html
   ...w-summary-kaMap.js.html
   ...mmary-kaOverlay.js.html
   ...summary-kaQuery.js.html
   ...mary-kaScalebar.js.html
   ...-summary-kaTool.js.html
   ...ry-kaXmlOverlay.js.html
   ...ummary-kaZoomer.js.html
   ...ry-overlayLayer.js.html
   ...ummary-scalebar.js.html
   ...ummary-wmsLayer.js.html
   ...iew-summary-xhr.js.html
   overview-summary.html
   overview-tree.html
   overview-wmsLayer.js.html
   overview-xhr.js.html
   ScaleBar.html
   stylesheet.css

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
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
<!doctype html public "-//W3C//DTD HTML 4.0 Frameset//EN""http://www.w3.org/TR/REC-html40/frameset.dtd">
<html>
<head>
<title>
ka-Map Overview
</title>
<link rel ="stylesheet" type="text/css" href="stylesheet.css" title="Style">
<script>
function asd() {
	
		parent.document.title="kaMap.js Overview";
	
}
</script>
</head>
<body bgcolor="white" onload="asd();">

<!-- ========== START OF NAVBAR ========== -->
<a name="navbar_top"><!-- --></a>
<table border="0" width="100%" cellpadding="1" cellspacing="0">
<tr>
<td colspan=2 bgcolor="#EEEEFF" class="NavBarCell1">
<a name="navbar_top_firstrow"><!-- --></a>
<table border="0" cellpadding="0" cellspacing="3">
  <tr align="center" valign="top">
  
  
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-summary.html"><font class="NavBarFont1"><b>Overview</b></font></a>&nbsp;</td>
  <td bgcolor="#FFFFFF" class="NavBarCell1Rev">	&nbsp;<font class="NavBarFont1Rev"><b>File</b></font>&nbsp;</td>
  

  <td bgcolor="#FFFFFF" class="NavBarCell1"> 	<font class="NavBarFont1">Class</font>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="overview-tree.html"><font class="NavBarFont1"><b>Tree</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="index-all.html"--><font class="NavBarFont1"><b>Index</b></font></a>&nbsp;</td>
  <td bgcolor="#EEEEFF" class="NavBarCell1">    <a href="help-doc.html"><font class="NavBarFont1"><b>Help</b></font></a>&nbsp;</td>
  </tr>
</table>
</td>
<td bgcolor="#EEEEFF" align="right" valign="top">
<em>
<b>ka-Map</b></em>
</td>
</tr>

<tr>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
&nbsp;PREV&nbsp;
&nbsp;NEXT</font></td>
<td bgcolor="white" class="NavBarCell2"><font size="-2">
  <a href="index.html" target="_top"><b>FRAMES</b></a>  &nbsp;
&nbsp;<a href="overview-summary.html" target="_top"><b>NO FRAMES</b></a>
&nbsp;&nbsp;
<script>
  <!--
  if(window==top) {
    document.writeln('<A HREF="allclasses-noframe.html" TARGET=""><B>All Classes</B></A>');
  }
  //-->
</script>
<noscript>
<a href="allclasses-noframe.html" target=""><b>All Classes</b></a>
</noscript>
</font></td>
</tr>
</table>
<!-- =========== END OF NAVBAR =========== -->

<hr>
<center>
	
	   <h2>kaMap.js</h2>
	
</center>

	


<h4>Summary</h4>
<p>
	
		No overview generated for 'kaMap.js'<BR/><BR/>
	
</p>

<hr>


    <table border="1" cellpadding="3" cellspacing="0" width="100%">
    <tr bgcolor="#CCCCFF" class="TableHeadingColor">
    <td colspan=2><font size="+2">
    
        <b>Class Summary</b>
    
    </font></td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="_eventManager.html">_eventManager</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="_layer.html">_layer</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="_map.html">_map</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="_queueManager.html">_queueManager</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    <tr bgcolor="white" class="TableRowColor">
    <td width="15%"><b><a href="kaMap.html">kaMap</a></b></td>
    <td>&nbsp;</td>
    </tr>
    
    </table>
    <hr/> 


<!-- ========== METHOD SUMMARY =========== -->

	<a name="method_summary"><!-- --></a>
	<table border="1" cellpadding="3" cellspacing="0" width="100%">
		<tr bgcolor="#CCCCFF" class="TableHeadingColor">
			<td colspan=2>
				<font size="+2">
					<b>Method Summary</b>
				</font>
			</td>
		</tr>
	
		
		   <tr bgcolor="white" class="TableRowColor">
		      <td align="right" valign="top" width="1%">
			 <font size="-1">
			    <code>static&nbsp;void</code>
			 </font>
		      </td>
		      <td>
			 <code>
			    <b>
			       <a href="GLOBALS.html#!s!_queueManager_execute">_queueManager_execute</a></b>( pos)
			 </code>
			 <br>
			 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 
		      </td>
		   </tr>
		
		   <tr bgcolor="white" class="TableRowColor">
		      <td align="right" valign="top" width="1%">
			 <font size="-1">
			    <code>static&nbsp;Object</code>
			 </font>
		      </td>
		      <td>
			 <code>
			    <b>
			       <a href="GLOBALS.html#!s!safeParseInt">safeParseInt</a></b>( val )
			 </code>
			 <br>
			 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			 special helper function to parse an integer value safely in case
 it is represented in IEEE format (scientific notation).
		      </td>
		   </tr>
		
	
	</table>
    <p>

<!-- ========== END METHOD SUMMARY =========== -->


        <pre class="sourceview"><span class="comment">/**********************************************************************
 *
 * $Id: overview-summary-kaMap.js.html,v 1.1 2006/03/15 15:56:58 pspencer Exp $
 *
 * purpose: core engine for implementing a tiled, continuous pan mapping
 *          engine.
 *
 * author: Paul Spencer (pspencer<span class="attrib">@dmsolutions</span>.ca)
 *
 * The original kaMap code was written by DM Solutions Group.
 * bug fixes contributed by Lorenzo Becchi and Andrea Cappugi
 * max_extents support by Tim Schaub
 *
 * TODO:
 *
 *   - convert to prototype
 *   - code refactoring for simplification/speed
 *   - code refactoring
 *
 **********************************************************************
 *
 * Copyright (c) 2005, DM Solutions Group Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 **********************************************************************/</span>

<span class="comment">/**
 * kaMap! events
 */</span>
var gnLastEventId = 0;
var KAMAP_ERROR = gnLastEventId ++;
var KAMAP_WARNING = gnLastEventId ++;
var KAMAP_NOTICE = gnLastEventId++;
var KAMAP_INITIALIZED = gnLastEventId ++;
var KAMAP_MAP_INITIALIZED = gnLastEventId ++;
var KAMAP_EXTENTS_CHANGED = gnLastEventId ++;
var KAMAP_SCALE_CHANGED = gnLastEventId ++;
var KAMAP_LAYERS_CHANGED = gnLastEventId ++;
var KAMAP_LAYER_STATUS_CHANGED = gnLastEventId ++;
var KAMAP_CONTEXT_MENU = gnLastEventId ++;
var KAMAP_METAEXTENTS_CHANGED = gnLastEventId++;
var KAMAP_MAP_CLICKED = gnLastEventId++;

<span class="comment">/******************************************************************************
 * kaMap main class
 *
 * construct a new kaMap instance.  Pass the id of the div to put the kaMap in
 *
 * this class is the main API for any application.  Only use the functions
 * provided by this API to ensure everything functions correctly
 *
 * szID - string, the id of a div to put the kaMap! into
 *
 *****************************************************************************/</span>
<span class="reserved">function</span> kaMap( szID ) {
    <span class="reserved">this</span>.isCSS = false;
    <span class="reserved">this</span>.isW3C = false;
    <span class="reserved">this</span>.isIE4 = false;
    <span class="reserved">this</span>.isNN4 = false;
    <span class="reserved">this</span>.isIE6CSS = false;

    <span class="reserved">if</span> (document.images) {
        <span class="reserved">this</span>.isCSS = (document.body &amp;&amp; document.body.style) ? true : false;
        <span class="reserved">this</span>.isW3C = (<span class="reserved">this</span>.isCSS &amp;&amp; document.getElementById) ? true : false;
        <span class="reserved">this</span>.isIE4 = (<span class="reserved">this</span>.isCSS &amp;&amp; document.all) ? true : false;
        <span class="reserved">this</span>.isNN4 = (document.layers) ? true : false;
        <span class="reserved">this</span>.isIE6CSS = (document.compatMode &amp;&amp; document.compatMode.indexOf(<span class="literal">"CSS1"</span>) &gt;= 0) ? true : false;
    }

    <span class="reserved">this</span>.domObj = <span class="reserved">this</span>.getRawObject( szID );
    <span class="reserved">this</span>.domObj.style.overflow = <span class="literal">'hidden'</span>;

    <span class="reserved">this</span>.hideLayersOnMove = false;
    <span class="comment">//if true layer not checked are loaded if false aren't loaded</span>
    <span class="reserved">this</span>.loadUnchecked=false;
    <span class="comment">/**
     * initialization states
     * 0 - not initialized
     * 1 - initializing
     * 2 - initialized
     */</span>
    <span class="reserved">this</span>.initializationState = 0;

    <span class="comment">//track mouse down events</span>
    <span class="reserved">this</span>.bMouseDown = false;

    <span class="comment">//track last recorded mouse position</span>
    <span class="reserved">this</span>.lastx = 0;
    <span class="reserved">this</span>.lasty = 0;

    <span class="comment">//keep a reference to the inside layer since we use it a lot</span>
    <span class="reserved">this</span>.theInsideLayer = null;

    <span class="comment">//viewport width and height are used in many calculations</span>
    <span class="reserved">this</span>.viewportWidth = safeParseInt(<span class="reserved">this</span>.domObj.style.width);
    <span class="reserved">this</span>.viewportHeight = safeParseInt(<span class="reserved">this</span>.domObj.style.height);

    <span class="comment">//track amount the inside layer has moved to help in wrapping images</span>
    <span class="reserved">this</span>.xOffset = 0;
    <span class="reserved">this</span>.yOffset = 0;

    <span class="comment">//track current origin offset value</span>
    <span class="reserved">this</span>.xOrigin = 0;
    <span class="reserved">this</span>.yOrigin = 0;

    <span class="comment">//the name of the current map</span>
    <span class="reserved">this</span>.currentMap = <span class="literal">''</span>;

    <span class="comment">//the current width and height in tiles</span>
    <span class="reserved">this</span>.nWide = 0;
    <span class="reserved">this</span>.nHigh = 0;

    <span class="comment">//current top and left are tracked when the map moves</span>
    <span class="comment">//to start the map at some offset, these would be set to</span>
    <span class="comment">//the appropriate pixel value.</span>
    <span class="reserved">this</span>.nCurrentTop = 0; <span class="comment">//null;</span>
    <span class="reserved">this</span>.nCurrentLeft = 0; <span class="comment">//null;</span>

    <span class="comment">//keep a live reference to aPixel to help with caching problems - hish</span>
    <span class="reserved">this</span>.aPixel = new Image(1,1);
    <span class="reserved">this</span>.aPixel.src = <span class="literal">'images/a_pixel.gif'</span>;

    <span class="comment">//error stack for tracking images that have failed to load</span>
    <span class="reserved">this</span>.imgErrors = new Array();

    <span class="comment">//an array of available maps</span>
    <span class="reserved">this</span>.aMaps = new Array();

    <span class="comment">//tile size and buffer size determine how many tiles to create</span>
    <span class="reserved">this</span>.tileWidth = null;
    <span class="reserved">this</span>.tileHeight = null;
    <span class="reserved">this</span>.nBuffer = 1;

    <span class="reserved">this</span>.baseURL = <span class="literal">''</span>;

    <span class="comment">//size of a pixel, geographically - assumed to be square</span>
    <span class="reserved">this</span>.cellSize = null;

    <span class="comment">//image id counter - helps with reloading failed images</span>
    <span class="reserved">this</span>.gImageID = 0;

    <span class="comment">//event manager</span>
    <span class="reserved">this</span>.eventManager = new _eventManager();

    <span class="comment">//slider stuff</span>
    <span class="reserved">this</span>.as=slideid=null;
    <span class="reserved">this</span>.accelerationFactor=1;
    <span class="reserved">this</span>.pixelsPerStep = 30;
    <span class="reserved">this</span>.timePerStep = 25;

    <span class="comment">//this is a convenience to allow redirecting the client code to a server</span>
    <span class="comment">//other than the one that this file was loaded from.  This may not</span>
    <span class="comment">//work depending on security settings, except for loading tiles since</span>
    <span class="comment">//those come directly from a php script instead of an XmlHttpRequest.</span>
    <span class="comment">//</span>
    <span class="comment">//by default, if this is empty, it loads from the same site as the</span>
    <span class="comment">//page loaded from.  If set, it should be a full http:// reference to the</span>
    <span class="comment">//directory in which init.php, tile.php and the other scripts are located.</span>
    <span class="reserved">this</span>.server = <span class="literal">''</span>;

    <span class="comment">//similarly, this is the global initialization script called once per page</span>
    <span class="comment">//load ... the result of this script tell the client what other scripts</span>
    <span class="comment">//are used for the other functions</span>
    <span class="reserved">this</span>.init = <span class="literal">"init.php"</span>;

    <span class="comment">//these are the values that need to be initialized by the init script</span>
    <span class="reserved">this</span>.tileURL = null;

    <span class="reserved">this</span>.aObjects = [];
    <span class="reserved">this</span>.aCanvases = [];
    <span class="reserved">this</span>.layersHidden = false;

    <span class="reserved">this</span>.aTools = [];

    <span class="comment">/* register the known events */</span>
    <span class="reserved">for</span> (var i=0; i&lt;gnLastEventId; i++) {
        <span class="reserved">this</span>.registerEventID( i );
    }
    <span class="reserved">this</span>.createLayers();
};

kaMap.<span class="reserved">prototype</span>.seekLayer = <span class="reserved">function</span>(doc, name) {
    var theObj;
    <span class="reserved">for</span> (var i = 0; i &lt; doc.layers.length; i++) {
        <span class="reserved">if</span> (doc.layers[i].name == name) {
            theObj = doc.layers[i];
            break;
        }
        <span class="comment">// dive into nested layers if necessary</span>
        <span class="reserved">if</span> (doc.layers[i].document.layers.length &gt; 0) {
            theObj = <span class="reserved">this</span>.seekLayer(document.layers[i].document, name);
        }
    }
    <span class="reserved">return</span> theObj;
};

<span class="comment">// Convert object name string or object reference</span>
<span class="comment">// into a valid element object reference</span>
kaMap.<span class="reserved">prototype</span>.getRawObject = <span class="reserved">function</span>(obj) {
    var theObj;
    <span class="reserved">if</span> (typeof obj == <span class="literal">"string"</span>) {
        <span class="reserved">if</span> (<span class="reserved">this</span>.isW3C) {
            theObj = document.getElementById(obj);
        } <span class="reserved">else</span> <span class="reserved">if</span> (<span class="reserved">this</span>.isIE4) {
            theObj = document.all(obj);
        } <span class="reserved">else</span> <span class="reserved">if</span> (<span class="reserved">this</span>.isNN4) {
            theObj = seekLayer(document, obj);
        }
    } <span class="reserved">else</span> {
        <span class="comment">// pass through object reference</span>
        theObj = obj;
    }
    <span class="reserved">return</span> theObj;
};

<span class="comment">// Convert object name string or object reference</span>
<span class="comment">// into a valid style (or NN4 layer) reference</span>
kaMap.<span class="reserved">prototype</span>.getObject = <span class="reserved">function</span>(obj) {
    var theObj = <span class="reserved">this</span>.getRawObject(obj);
    <span class="reserved">if</span> (theObj &amp;&amp; <span class="reserved">this</span>.isCSS) {
        theObj = theObj.style;
    }
    <span class="reserved">return</span> theObj;
};

<span class="comment">// Retrieve the rendered width of an element</span>
kaMap.<span class="reserved">prototype</span>.getObjectWidth = <span class="reserved">function</span>(obj)  {
    var elem = <span class="reserved">this</span>.getRawObject(obj);
    var result = 0;
    <span class="reserved">if</span> (elem.offsetWidth) {
        result = elem.offsetWidth;
    } <span class="reserved">else</span> <span class="reserved">if</span> (elem.clip &amp;&amp; elem.clip.width) {
        result = elem.clip.width;
    } <span class="reserved">else</span> <span class="reserved">if</span> (elem.style &amp;&amp; elem.style.pixelWidth) {
        result = elem.style.pixelWidth;
    }
    <span class="reserved">return</span> parseInt(result);
};

<span class="comment">// Retrieve the rendered height of an element</span>
kaMap.<span class="reserved">prototype</span>.getObjectHeight = <span class="reserved">function</span>(obj)  {
    var elem = <span class="reserved">this</span>.getRawObject(obj);
    var result = 0;
    <span class="reserved">if</span> (elem.offsetHeight) {
        result = elem.offsetHeight;
    } <span class="reserved">else</span> <span class="reserved">if</span> (elem.clip &amp;&amp; elem.clip.height) {
        result = elem.clip.height;
    } <span class="reserved">else</span> <span class="reserved">if</span> (elem.style &amp;&amp; elem.style.pixelHeight) {
        result = elem.style.pixelHeight;
    }
    <span class="reserved">return</span> parseInt(result);
};

<span class="comment">/**
 * kaMap.zoomTo( lon, lat [, scale] )
 *
 * zoom to some geographic point (in current projection) and optionally scale
 *
 * lon - the x coordinate to zoom to
 * lat - the y coordinate to zoom to
 * scale - optional. The scale to use
 */</span>
kaMap.<span class="reserved">prototype</span>.zoomTo = <span class="reserved">function</span>( cgX, cgY ) {
    var oMap = <span class="reserved">this</span>.getCurrentMap();
    var inchesPerUnit = new Array(1, 12, 63360.0, 39.3701, 39370.1, 4374754);
    var newScale;
    var bScaleChanged = false;
    <span class="reserved">if</span> (arguments.length == 3) {
        newScale = arguments[2];
        bScaleChanged = (newScale != <span class="reserved">this</span>.getCurrentScale())
    } <span class="reserved">else</span> {
        newScale = <span class="reserved">this</span>.getCurrentScale();
    }
    <span class="reserved">this</span>.cellSize = newScale/(oMap.resolution * inchesPerUnit[oMap.units]);
    var nFactor = oMap.zoomToScale( newScale );
    <span class="reserved">this</span>.setMapLayers();
    var cpX = cgX / <span class="reserved">this</span>.cellSize;
    var cpY = cgY / <span class="reserved">this</span>.cellSize;

    var vpLeft = Math.round(cpX - <span class="reserved">this</span>.viewportWidth/2);
    var vpTop = Math.round(cpY + <span class="reserved">this</span>.viewportHeight/2);


    <span class="comment">//figure out which tile the center point lies on</span>
    var cTileX = Math.floor(cpX/<span class="reserved">this</span>.tileWidth)*<span class="reserved">this</span>.tileWidth;
    var cTileY = Math.floor(cpY/<span class="reserved">this</span>.tileHeight)*<span class="reserved">this</span>.tileHeight;


    <span class="comment">//figure out how many tiles left and up we need to move to lay out from</span>
    <span class="comment">//the top left and have the top/left image off screen (or partially)</span>
    var nTilesLeft = Math.ceil(<span class="reserved">this</span>.viewportWidth/(2*<span class="reserved">this</span>.tileWidth))*<span class="reserved">this</span>.tileWidth;
    var nTilesUp = Math.ceil(<span class="reserved">this</span>.viewportHeight/(2*<span class="reserved">this</span>.tileHeight))*<span class="reserved">this</span>.tileHeight;

    <span class="reserved">this</span>.nCurrentLeft = cTileX - nTilesLeft;
    <span class="reserved">this</span>.nCurrentTop = -1*(cTileY + nTilesUp);

    <span class="reserved">this</span>.xOrigin = <span class="reserved">this</span>.nCurrentLeft;
    <span class="reserved">this</span>.yOrigin = <span class="reserved">this</span>.nCurrentTop;

    <span class="reserved">this</span>.theInsideLayer.style.left = -1*(vpLeft - <span class="reserved">this</span>.xOrigin) + <span class="literal">"px"</span>;
    <span class="reserved">this</span>.theInsideLayer.style.top = (vpTop + <span class="reserved">this</span>.yOrigin) + <span class="literal">"px"</span>;

    var layers = oMap.getLayers();
    <span class="reserved">for</span>( var k=0; k&lt;layers.length; k++) {
        var d = layers[k].domObj;
        <span class="reserved">for</span>(var j=0; j&lt;<span class="reserved">this</span>.nHigh; j++) {
            <span class="reserved">for</span>( var i=0; i&lt;<span class="reserved">this</span>.nWide; i++) {
                var img = d.childNodes[(j*<span class="reserved">this</span>.nWide)+i];
                img.src = <span class="reserved">this</span>.aPixel.src;
                img.style.top = (<span class="reserved">this</span>.nCurrentTop + j*<span class="reserved">this</span>.tileHeight - <span class="reserved">this</span>.yOrigin) + <span class="literal">"px"</span>;
                img.style.left = (<span class="reserved">this</span>.nCurrentLeft + i*<span class="reserved">this</span>.tileWidth - <span class="reserved">this</span>.xOrigin) + <span class="literal">"px"</span>;
                layers[k].setTile(img);
            }
        }
    }
    <span class="reserved">this</span>.checkWrap( );
    <span class="reserved">this</span>.updateObjects();
    <span class="reserved">if</span> (bScaleChanged) <span class="reserved">this</span>.triggerEvent( KAMAP_SCALE_CHANGED, <span class="reserved">this</span>.getCurrentScale() );
    <span class="reserved">this</span>.triggerEvent( KAMAP_EXTENTS_CHANGED, <span class="reserved">this</span>.getGeoExtents() );
};

<span class="comment">/**
 * kaMap.zoomToExtents( minx, miny, maxx, maxy )
 *
 * best fit zoom to extents.  Center of extents will be in the center of the
 * view and the extents will be contained within the view at the closest scale
 * available above the scale these extents represent
 *
 * minx, miny, maxx, maxy - extents in units of current projection.
 */</span>
kaMap.<span class="reserved">prototype</span>.zoomToExtents = <span class="reserved">function</span>(minx, miny, maxx, maxy) {
    <span class="comment">/* calculate new scale from extents and viewport, then find closest
     * scale and calculate new extents from centerpoint and scale.  Then
     * move theInsideLayer and all the images to show that centerpoint at
     * the center of the view at the given scale
     */</span>
    var inchesPerUnit = new Array(1, 12, 63360.0, 39.3701, 39370.1, 4374754);
    var oMap = <span class="reserved">this</span>.getCurrentMap();

    <span class="comment">//the geographic center - where we want to end up</span>
    var cgX = (maxx+minx)/2;
    var cgY = (maxy+miny)/2;

    var tmpCellSizeX = (maxx - minx)/<span class="reserved">this</span>.viewportWidth;
    var tmpCellSizeY = (maxy - miny)/<span class="reserved">this</span>.viewportHeight;
    var tmpCellSize = Math.max( tmpCellSizeX, tmpCellSizeY );

    var tmpScale = tmpCellSize * oMap.resolution * inchesPerUnit[oMap.units];
    var newScale = oMap.aScales[0];
    <span class="reserved">for</span> (var i=1; i&lt;oMap.aScales.length; i++) {
        <span class="reserved">if</span> (tmpScale &gt;= oMap.aScales[i]) {
            break;
        }
        newScale = oMap.aScales[i];
    }
    <span class="comment">//now newScale has our new scale size</span>
    <span class="reserved">this</span>.cellSize = newScale/(oMap.resolution * inchesPerUnit[oMap.units]);
    var nFactor = oMap.zoomToScale( newScale );
    <span class="reserved">this</span>.setMapLayers();
    var cpX = cgX / <span class="reserved">this</span>.cellSize;
    var cpY = cgY / <span class="reserved">this</span>.cellSize;

    var vpLeft = Math.round(cpX - <span class="reserved">this</span>.viewportWidth/2);
    var vpTop = Math.round(cpY + <span class="reserved">this</span>.viewportHeight/2);


    <span class="comment">//figure out which tile the center point lies on</span>
    var cTileX = Math.floor(cpX/<span class="reserved">this</span>.tileWidth)*<span class="reserved">this</span>.tileWidth;
    var cTileY = Math.floor(cpY/<span class="reserved">this</span>.tileHeight)*<span class="reserved">this</span>.tileHeight;


    <span class="comment">//figure out how many tiles left and up we need to move to lay out from</span>
    <span class="comment">//the top left and have the top/left image off screen (or partially)</span>
    var nTilesLeft = Math.ceil(<span class="reserved">this</span>.viewportWidth/(2*<span class="reserved">this</span>.tileWidth))*<span class="reserved">this</span>.tileWidth;
    var nTilesUp = Math.ceil(<span class="reserved">this</span>.viewportHeight/(2*<span class="reserved">this</span>.tileHeight))*<span class="reserved">this</span>.tileHeight;

    <span class="reserved">this</span>.nCurrentLeft = cTileX - nTilesLeft;
    <span class="reserved">this</span>.nCurrentTop = -1*(cTileY + nTilesUp);

    <span class="reserved">this</span>.xOrigin = <span class="reserved">this</span>.nCurrentLeft;
    <span class="reserved">this</span>.yOrigin = <span class="reserved">this</span>.nCurrentTop;

    <span class="reserved">this</span>.theInsideLayer.style.left = -1*(vpLeft - <span class="reserved">this</span>.xOrigin) + <span class="literal">"px"</span>;
    <span class="reserved">this</span>.theInsideLayer.style.top = (vpTop + <span class="reserved">this</span>.yOrigin) + <span class="literal">"px"</span>;

    var layers = oMap.getLayers();
    <span class="reserved">for</span>( var k=0; k&lt;layers.length; k++) {
        var d = layers[k].domObj;
        <span class="reserved">for</span>(var j=0; j&lt;<span class="reserved">this</span>.nHigh; j++) {
            <span class="reserved">for</span>( var i=0; i&lt;<span class="reserved">this</span>.nWide; i++) {
                var img = d.childNodes[(j*<span class="reserved">this</span>.nWide)+i];
                img.src = <span class="reserved">this</span>.aPixel.src;
                img.style.top = (<span class="reserved">this</span>.nCurrentTop + j*<span class="reserved">this</span>.tileHeight - <span class="reserved">this</span>.yOrigin) + <span class="literal">"px"</span>;
                img.style.left = (<span class="reserved">this</span>.nCurrentLeft + i*<span class="reserved">this</span>.tileWidth - <span class="reserved">this</span>.xOrigin) + <span class="literal">"px"</span>;
                layers[k].setTile(img);
            }
        }
    }
    <span class="reserved">this</span>.checkWrap( );
    <span class="reserved">this</span>.updateObjects();
    <span class="reserved">this</span>.triggerEvent( KAMAP_SCALE_CHANGED, <span class="reserved">this</span>.getCurrentScale() );
    <span class="reserved">this</span>.triggerEvent( KAMAP_EXTENTS_CHANGED, <span class="reserved">this</span>.getGeoExtents() );
};

<span class="comment">/**
 * kaMap.createDrawingCanvas( idx )
 *
 * create a layer on which objects can be drawn (such as point objects)
 *
 * idx - int, the z-index of the layer.  Should be &lt; 100 but above the map
 * layers.
 */</span>
kaMap.<span class="reserved">prototype</span>.createDrawingCanvas = <span class="reserved">function</span>( idx ) {
    var d = document.createElement( <span class="literal">'div'</span> );
    d.style.position = <span class="literal">'absolute'</span>;
    d.style.left = <span class="literal">'0px'</span>;
    d.style.top = <span class="literal">'0px'</span>;
    d.style.width= <span class="literal">'3000px'</span>;
    d.style.height = <span class="literal">'3000px'</span>;
    d.style.zIndex = idx;
    <span class="reserved">this</span>.theInsideLayer.appendChild( d );
    <span class="reserved">this</span>.aCanvases.push( d );
    d.kaMap = <span class="reserved">this</span>;
    <span class="reserved">return</span> d;
};

kaMap.<span class="reserved">prototype</span>.removeDrawingCanvas = <span class="reserved">function</span>( canvas ) {

    <span class="reserved">for</span> (var i=0; i&lt;<span class="reserved">this</span>.aCanvases.length;i++) {
        <span class="reserved">if</span> (<span class="reserved">this</span>.aCanvases[i] == canvas) {
            <span class="reserved">this</span>.aCanvases.splice( i, 1 );
        }
    }
    <span class="reserved">this</span>.theInsideLayer.removeChild(canvas);
    canvas.kaMap = null;
    <span class="reserved">return</span> true;
};

<span class="comment">/**
 * kaMap.addObjectGeo( canvas, lon, lat, obj )
 *
 * add an object to a drawing layer and position it at the given geographic
 * position.  This is defined as being in the projection of the map.
 *
 * TODO: possibly add ability to call a reprojection service (xhr request?) to
 * convert lon/lat into the current coordinate system if not lon/lat.
 *
 * canvas - object, the drawing canvas to add this object to
 * x - int, the x position in pixels
 * y - int, the y position in pixels
 * obj - object, the object to add (an img, div etc)
 *
 * returns true
 */</span>
kaMap.<span class="reserved">prototype</span>.addObjectGeo = <span class="reserved">function</span>( canvas, lon, lat, obj ) {
    obj.lon = lon;
    obj.lat = lat;
    var aPix = <span class="reserved">this</span>.geoToPix( lon, lat );
    <span class="reserved">return</span> <span class="reserved">this</span>.addObjectPix( canvas, aPix[0], aPix[1], obj );
};

<span class="comment">/**
 * kaMap.addObjectPix( canvas, x, y, obj )
 *
 * add an object to the map canvas and position it at the given pixel position.
 * The position should not include the xOrigin/yOrigin offsets
 *
 * canvas - object, the canvas to add this object to
 * x - int, the x position in pixels
 * y - int, the y position in pixels
 * obj - object, the object to add (an img, div etc)
 *
 * returns true;
 */</span>
kaMap.<span class="reserved">prototype</span>.addObjectPix = <span class="reserved">function</span>( canvas, x, y, obj ) {
    var xOffset = (obj.xOffset) ? obj.xOffset : 0;
    var yOffset = (obj.yOffset) ? obj.yOffset : 0;
    var top = (y - <span class="reserved">this</span>.yOrigin + yOffset);
    var left = (x - <span class="reserved">this</span>.xOrigin + xOffset);
    obj.style.position = <span class="literal">'absolute'</span>;
    obj.style.top = top + <span class="literal">"px"</span>;
    obj.style.left = left + <span class="literal">"px"</span>;
    obj.canvas = canvas;
    canvas.appendChild( obj );
    <span class="reserved">this</span>.aObjects.push( obj );

    <span class="reserved">return</span> true;
};

<span class="comment">/**
 * kaMap.shiftObject( x, y, obj )
 *
 * move an object by a pixel amount
 *
 * x - int, the number of pixels in the x direction to move the object
 * y - int, the number of pixels in the y direction to move the object
 * obj - object, the object to move
 *
 * returns true
 */</span>
kaMap.<span class="reserved">prototype</span>.shiftObject = <span class="reserved">function</span>( x, y, obj ) {
    var top = safeParseInt(obj.style.top);
    var left = safeParseInt(obj.style.left);

    obj.style.top = (top + y) + <span class="literal">"px"</span>;
    obj.style.left = (left + x) + <span class="literal">"px"</span>;

    <span class="reserved">return</span> true;
};

<span class="comment">/**
 * kaMap.removeObject( obj )
 *
 * removes an object previously added with one of the addObjectXxx calls
 *
 * obj - object, an object that has been previously added, or null to remove
 *       all objects
 *
 * returns true if the object was removed, false otherwise (i.e. if it was
 * never added).
 */</span>
kaMap.<span class="reserved">prototype</span>.removeObject = <span class="reserved">function</span>( obj ) {
    <span class="reserved">for</span> (var i=0; i&lt;<span class="reserved">this</span>.aObjects.length; i++) {
        <span class="reserved">if</span> (<span class="reserved">this</span>.aObjects[i] == obj || obj == null) {
            <span class="reserved">if</span> (!obj) {
                obj = <span class="reserved">this</span>.aObjects[i];
            }
            <span class="reserved">if</span> (obj.canvas) {
                obj.canvas.removeChild( obj );
                obj.canvas = null;
            }
            <span class="reserved">this</span>.aObjects.splice(i,1);
            <span class="reserved">return</span> true;
        }
    }
    <span class="reserved">return</span> false;
};

<span class="comment">/**
 * kaMap.centerObject( obj )
 *
 * slides the map to place the object at the center of the map
 *
 * obj - object, an object previously added to the map
 *
 * returns true
 */</span>
kaMap.<span class="reserved">prototype</span>.centerObject = <span class="reserved">function</span>(obj) {
    var vpX = -safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.left) + <span class="reserved">this</span>.viewportWidth/2;
    var vpY = -safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.top) + <span class="reserved">this</span>.viewportHeight/2;

    var xOffset = (obj.xOffset)?obj.xOffset:0;
    var yOffset = (obj.yOffset)?obj.yOffset:0;

    var dx = safeParseInt(obj.style.left) - xOffset- vpX;
    var dy = safeParseInt(obj.style.top) - yOffset - vpY;

    <span class="reserved">this</span>.slideBy(-dx, -dy);
    <span class="reserved">return</span> true;
};

<span class="comment">/**
 * kaMap.geoToPix( gX, gY )
 *
 * convert geographic coordinates into pixel coordinates.  Note this does not
 * adjust for the current origin offset that is used to adjust the actual
 * pixel location of the tiles and other images
 *
 * gX - float, the x coordinate in geographic units of the active projection
 * gY - float, the y coordinate in geographic units of the active projection
 *
 * returns an array of pixel coordinates with element 0 being the x and element
 * 1 being the y coordinate.
 */</span>
kaMap.<span class="reserved">prototype</span>.geoToPix = <span class="reserved">function</span>( gX, gY ) {
    var pX = gX / <span class="reserved">this</span>.cellSize;
    var pY = -1 * gY / <span class="reserved">this</span>.cellSize;
    <span class="reserved">return</span> [Math.floor(pX), Math.floor(pY)];
};

<span class="comment">/**
 * kaMap.pixToGeo( pX, pY [, bAdjust] )
 *
 * convert pixel coordinates into geographic coordinates.  This can optionally
 * adjust for the pixel offset by passing true as the third argument
 *
 * pX - int, the x coordinate in pixel units
 * pY - int, the y coordinate in pixel units
 *
 * returns an array of geographic coordinates with element 0 being the x
 * and element 1 being the y coordinate.
 */</span>
kaMap.<span class="reserved">prototype</span>.pixToGeo = <span class="reserved">function</span>( pX, pY ) {
    var bAdjust = (arguments.length == 3 &amp;&amp; arguments[2]) ? true : false;

    <span class="reserved">if</span> (bAdjust) {
        pX = pX + <span class="reserved">this</span>.xOrigin;
        pY = pY + <span class="reserved">this</span>.yOrigin;
    }
    var gX = -1 * pX * <span class="reserved">this</span>.cellSize;
    var gY = pY * <span class="reserved">this</span>.cellSize;
    <span class="reserved">return</span> [gX, gY];
};

<span class="comment">/**
 * kaMap.initialize( [szMap] )
 *
 * main initialization of kaMap.  This must be called after page load and
 * should only be called once (i.e. on page load).  It does not perform
 * intialization synchronously.  This means that the function will return
 * before initialization is complete.  To determine when initialization is
 * complete, the calling application must register for the KAMAP_INITIALIZED
 * event.
 *
 * szMap - string, optional, the name of a map to initialize by default.  If
 *         not set, use the default configuration map file.
 *
 * returns true
 */</span>
kaMap.<span class="reserved">prototype</span>.initialize = <span class="reserved">function</span>() {
    <span class="reserved">if</span> (<span class="reserved">this</span>.initializationState == 2) {
        <span class="reserved">this</span>.triggerEvent( KAMAP_ERROR, <span class="literal">'ERROR: ka-Map! is already initialized!'</span> );
        <span class="reserved">return</span> false;
    } <span class="reserved">else</span> <span class="reserved">if</span> (<span class="reserved">this</span>.intializationState == 1) {
        <span class="reserved">this</span>.triggerEvent( KAMAP_WARNING, <span class="literal">'WARNING: ka-Map! is currently initializing ... wait for the KAMAP_INITIALIZED event to be triggered.'</span> );
        <span class="reserved">return</span> false;
    }

    <span class="reserved">this</span>.initializationState = 1;
    <span class="comment">/* call initialization script on the server */</span>
    var szURL = <span class="reserved">this</span>.server+<span class="reserved">this</span>.init;

    var sep = (<span class="reserved">this</span>.init.indexOf(<span class="literal">"?"</span>) == -1) ? <span class="literal">"?"</span> : <span class="literal">"&amp;"</span>;

    <span class="reserved">if</span> (arguments.length &gt; 0 &amp;&amp; arguments[0] != <span class="literal">''</span>) {
        szURL = szURL + sep + <span class="literal">"map="</span>+ arguments[0];
        sep = <span class="literal">"&amp;"</span>;
    }
    <span class="reserved">if</span> (arguments.length &gt; 1 &amp;&amp; arguments[1] != <span class="literal">''</span>) {
        szURL = szURL + sep + <span class="literal">"extents="</span>+ arguments[1];
        sep = <span class="literal">"&amp;"</span>;
    }
    <span class="reserved">if</span> (arguments.length &gt; 2 &amp;&amp; arguments[2] != <span class="literal">''</span>) {
        szURL = szURL + sep + <span class="literal">"centerPoint="</span>+ arguments[2];
        sep = <span class="literal">"&amp;"</span>;
    }
    call(szURL, <span class="reserved">this</span>, <span class="reserved">this</span>.initializeCallback);
    <span class="reserved">return</span> true;
};

<span class="comment">/**
 * hidden function on callback from init.php
 */</span>
kaMap.<span class="reserved">prototype</span>.initializeCallback = <span class="reserved">function</span>( szInit ) {
    <span class="comment">// szInit contains /*init*/ if it worked, or some php error otherwise</span>
    <span class="reserved">if</span> (szInit.substr(0, 1) != <span class="literal">"/"</span>) {
        <span class="reserved">this</span>.triggerEvent( KAMAP_ERROR, <span class="literal">'ERROR: ka-Map! initialization '</span>+
                          <span class="literal">'failed on the server.  Message returned was:\n'</span> +
                          szInit);
        <span class="reserved">return</span> false;
    }

    eval(szInit);

    <span class="reserved">this</span>.triggerEvent( KAMAP_INITIALIZED );

    <span class="reserved">this</span>.initializationState = 2;
};

<span class="comment">/**
 * kaMap.setBackgroundColor( color )
 *
 * call this to set a background color for the inside layer.  This color
 * shows through any transparent areas of the map.  This is primarily
 * intended to be used by the initializeMap callback function to set the
 * background to the background color in the map file.
 *
 * color: string, a valid HTML color string
 *
 * returns true;
 */</span>
kaMap.<span class="reserved">prototype</span>.setBackgroundColor = <span class="reserved">function</span>( color ) {
    <span class="reserved">this</span>.domObj.style.backgroundColor = color;
    <span class="reserved">return</span> true;
};

<span class="comment">/**
 * hidden method of kaMap to initialize all the various layers needed by
 * kaMap to draw and move the map image.
 */</span>
kaMap.<span class="reserved">prototype</span>.createLayers = <span class="reserved">function</span>() {
    <span class="reserved">this</span>.theInsideLayer = document.createElement(<span class="literal">'div'</span>);
    <span class="reserved">this</span>.theInsideLayer.id = <span class="literal">'theInsideLayer'</span>;
    <span class="reserved">this</span>.theInsideLayer.style.position = <span class="literal">'absolute'</span>;
    <span class="reserved">this</span>.theInsideLayer.style.left = <span class="literal">'0px'</span>;
    <span class="reserved">this</span>.theInsideLayer.style.top = <span class="literal">'0px'</span>;
    <span class="reserved">this</span>.theInsideLayer.style.zIndex = <span class="literal">'1'</span>;
    <span class="reserved">this</span>.theInsideLayer.kaMap = <span class="reserved">this</span>;
    <span class="reserved">if</span> (<span class="reserved">this</span>.currentTool) {
        <span class="reserved">this</span>.theInsideLayer.style.cursor = <span class="reserved">this</span>.currentTool.cursor;
    }
    <span class="reserved">this</span>.domObj.appendChild(<span class="reserved">this</span>.theInsideLayer);

    <span class="reserved">this</span>.domObj.kaMap = <span class="reserved">this</span>;
    <span class="reserved">this</span>.theInsideLayer.onmousedown = kaMap_onmousedown;
    <span class="reserved">this</span>.theInsideLayer.onmouseup = kaMap_onmouseup;
    <span class="reserved">this</span>.theInsideLayer.onmousemove = kaMap_onmousemove;
    <span class="reserved">this</span>.theInsideLayer.onmouseover = kaMap_onmouseover;
    <span class="reserved">this</span>.domObj.onmouseout = kaMap_onmouseout;
    <span class="reserved">this</span>.theInsideLayer.onkeypress = kaMap_onkeypress;
    <span class="reserved">this</span>.theInsideLayer.ondblclick = kaMap_ondblclick;
    <span class="reserved">this</span>.theInsideLayer.oncontextmenu = kaMap_oncontextmenu;
    <span class="reserved">this</span>.theInsideLayer.onmousewheel = kaMap_onmousewheel;
    <span class="reserved">if</span> (window.addEventListener &amp;&amp;
        navigator.product &amp;&amp; navigator.product == <span class="literal">"Gecko"</span>) {
        <span class="reserved">this</span>.domObj.addEventListener( <span class="literal">"DOMMouseScroll"</span>, kaMap_onmousewheel, false );
    }

    <span class="comment">//this is to prevent problems in IE</span>
    <span class="reserved">this</span>.theInsideLayer.ondragstart = new Function([], <span class="literal">'var e=e?e:event;e.cancelBubble=true;e.returnValue=false;return false;'</span>);
};

<span class="comment">/**
 * internal function
 * update the layer URLs based on their current positions
 */</span>
kaMap.<span class="reserved">prototype</span>.initializeLayers = <span class="reserved">function</span>(nFactor) {
    var deltaMouseX = <span class="reserved">this</span>.nCurrentLeft + safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.left) - <span class="reserved">this</span>.xOrigin;
    var deltaMouseY = <span class="reserved">this</span>.nCurrentTop + safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.top) - <span class="reserved">this</span>.yOrigin;

    var vpTop = <span class="reserved">this</span>.nCurrentTop - deltaMouseY;
    var vpLeft = <span class="reserved">this</span>.nCurrentLeft - deltaMouseX;

    var vpCenterX = vpLeft + <span class="reserved">this</span>.viewportWidth/2;
    var vpCenterY = vpTop + <span class="reserved">this</span>.viewportHeight/2;

    var currentTileX = Math.floor(vpCenterX/<span class="reserved">this</span>.tileWidth)*<span class="reserved">this</span>.tileWidth;
    var currentTileY = Math.floor(vpCenterY/<span class="reserved">this</span>.tileHeight)*<span class="reserved">this</span>.tileHeight;

    var tileDeltaX = currentTileX - <span class="reserved">this</span>.nCurrentLeft;
    var tileDeltaY = currentTileY - <span class="reserved">this</span>.nCurrentTop;

    var newVpCenterX = vpCenterX * nFactor;
    var newVpCenterY = vpCenterY * nFactor;

    var newTileX = Math.floor(newVpCenterX/<span class="reserved">this</span>.tileWidth) * <span class="reserved">this</span>.tileWidth;
    var newTileY = Math.floor(newVpCenterY/<span class="reserved">this</span>.tileHeight) * <span class="reserved">this</span>.tileHeight;

    var newCurrentLeft = newTileX - tileDeltaX;
    var newCurrentTop = newTileY - tileDeltaY;

    <span class="reserved">this</span>.nCurrentLeft = newCurrentLeft;
    <span class="reserved">this</span>.nCurrentTop = newCurrentTop;

    var newTilLeft = -newVpCenterX + <span class="reserved">this</span>.viewportWidth/2;
    var newTilTop = -newVpCenterY + <span class="reserved">this</span>.viewportHeight/2;

    var xOldOrigin = <span class="reserved">this</span>.xOrigin;
    var yOldOrigin = <span class="reserved">this</span>.yOrigin;

    <span class="reserved">this</span>.xOrigin = <span class="reserved">this</span>.nCurrentLeft;
    <span class="reserved">this</span>.yOrigin = <span class="reserved">this</span>.nCurrentTop;

    <span class="reserved">this</span>.theInsideLayer.style.left = (newTilLeft + <span class="reserved">this</span>.xOrigin) + <span class="literal">"px"</span>;
    <span class="reserved">this</span>.theInsideLayer.style.top = (newTilTop + <span class="reserved">this</span>.yOrigin) + <span class="literal">"px"</span>;

    var layers = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayers();
    <span class="reserved">for</span>( var k=0; k&lt;layers.length; k++) {
        var d = layers[k].domObj;
        <span class="reserved">for</span>(var j=0; j&lt;<span class="reserved">this</span>.nHigh; j++) {
            <span class="reserved">for</span>( var i=0; i&lt;<span class="reserved">this</span>.nWide; i++) {
                var img = d.childNodes[(j*<span class="reserved">this</span>.nWide)+i];
                img.src = <span class="reserved">this</span>.aPixel.src;
                img.style.top = (<span class="reserved">this</span>.nCurrentTop + j*<span class="reserved">this</span>.tileHeight - <span class="reserved">this</span>.yOrigin) + <span class="literal">"px"</span>;
                img.style.left = (<span class="reserved">this</span>.nCurrentLeft + i*<span class="reserved">this</span>.tileWidth - <span class="reserved">this</span>.xOrigin) + <span class="literal">"px"</span>;
                layers[k].setTile(img);
            }
        }
    }
    <span class="reserved">this</span>.checkWrap();
    <span class="reserved">this</span>.updateObjects();
};

<span class="comment">/***************************************
 * internal function adedd by cappu
 * use to paint a layer calculating tile
 * position for current exten and scale
 * and calling the layer.seTile
 ***************************************/</span>
kaMap.<span class="reserved">prototype</span>.paintLayer = <span class="reserved">function</span>(l) {
     var d = l.domObj;
     <span class="reserved">for</span>(var j=0; j&lt;<span class="reserved">this</span>.nHigh; j++) {
         <span class="reserved">for</span>( var i=0; i&lt;<span class="reserved">this</span>.nWide; i++) {
             var img = d.childNodes[(j*<span class="reserved">this</span>.nWide)+i];
            <span class="comment">// img.src = this.aPixel.src;</span>
             img.style.top = (<span class="reserved">this</span>.nCurrentTop + j*<span class="reserved">this</span>.tileHeight - <span class="reserved">this</span>.yOrigin) + <span class="literal">"px"</span>;
             img.style.left = (<span class="reserved">this</span>.nCurrentLeft + i*<span class="reserved">this</span>.tileWidth - <span class="reserved">this</span>.xOrigin) + <span class="literal">"px"</span>;
             l.setTile(img);
         }
     }
     <span class="reserved">this</span>.checkWrap();
};

<span class="comment">/* kaMap.updateObjects
 * call this after any major change to the state of kaMap including after
 * a zoomTo, zoomToExtents, etc.
 */</span>
kaMap.<span class="reserved">prototype</span>.updateObjects = <span class="reserved">function</span>() {
    <span class="reserved">for</span> (var i=0; i&lt;<span class="reserved">this</span>.aObjects.length;i++) {
        var obj = <span class="reserved">this</span>.aObjects[i];
        var xOffset = (obj.xOffset) ? obj.xOffset : 0;
        var yOffset = (obj.yOffset) ? obj.yOffset : 0;
        var aPix = <span class="reserved">this</span>.geoToPix( obj.lon, obj.lat );
        var top = (aPix[1] - <span class="reserved">this</span>.yOrigin + yOffset);
        var left = (aPix[0] - <span class="reserved">this</span>.xOrigin + xOffset);
        obj.style.top = top + <span class="literal">"px"</span>;
        obj.style.left = left + <span class="literal">"px"</span>;
    }
};

<span class="comment">/**
 * kaMap.resize()
 *
 * called when the viewport layer changes size.  It is the responsibility
 * of the user of this API to track changes in viewport size and call this
 * function to update the map
 */</span>
kaMap.<span class="reserved">prototype</span>.resize = <span class="reserved">function</span>( ) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.initializationState != 2) {
        <span class="reserved">return</span> false;
    }
    var newViewportWidth = <span class="reserved">this</span>.getObjectWidth(<span class="reserved">this</span>.domObj);
    var newViewportHeight = <span class="reserved">this</span>.getObjectHeight(<span class="reserved">this</span>.domObj);

    <span class="reserved">if</span> (<span class="reserved">this</span>.viewportWidth == null) {
        <span class="reserved">this</span>.theInsideLayer.style.top = (-1*<span class="reserved">this</span>.nCurrentTop + <span class="reserved">this</span>.yOrigin) + <span class="literal">"px"</span>;
        <span class="reserved">this</span>.theInsideLayer.style.left = (-1*<span class="reserved">this</span>.nCurrentLeft + <span class="reserved">this</span>.xOrigin) + <span class="literal">"px"</span>;
        <span class="reserved">this</span>.viewportWidth = newViewportWidth;
        <span class="reserved">this</span>.viewportHeight = newViewportHeight;
    }
    var newWide = Math.ceil((newViewportWidth / <span class="reserved">this</span>.tileWidth) + 2*<span class="reserved">this</span>.nBuffer);
    var newHigh = Math.ceil((newViewportHeight / <span class="reserved">this</span>.tileHeight) + 2*<span class="reserved">this</span>.nBuffer);

    <span class="reserved">this</span>.viewportWidth = newViewportWidth;
    <span class="reserved">this</span>.viewportHeight = newViewportHeight;

    <span class="reserved">if</span> (<span class="reserved">this</span>.nHigh == 0 &amp;&amp; <span class="reserved">this</span>.nWide == 0) {
        <span class="reserved">this</span>.nWide = newWide;
    }

    <span class="reserved">while</span> (<span class="reserved">this</span>.nHigh &lt; newHigh) {

        <span class="reserved">this</span>.appendRow();
    }
    <span class="reserved">while</span> (<span class="reserved">this</span>.nHigh &gt; newHigh &amp;&amp; newHigh &gt; 3) {
        <span class="reserved">this</span>.removeRow();
    }
    <span class="reserved">while</span> (<span class="reserved">this</span>.nWide &lt; newWide) {
        <span class="reserved">this</span>.appendColumn();
    }
    <span class="reserved">while</span> (<span class="reserved">this</span>.nWide &gt; newWide &amp;&amp; newWide &gt; 3) {
        <span class="reserved">this</span>.removeColumn();
    }
    <span class="comment">//create image don't call layer.set tile so i need to do that!</span>
    var map = <span class="reserved">this</span>.getCurrentMap();
    var layers =map.getLayers();
    <span class="reserved">for</span>(i=0;i&lt;layers.length;i++) {
        layers[i].setTileLayer();
    }

    <span class="reserved">this</span>.triggerEvent( KAMAP_EXTENTS_CHANGED, <span class="reserved">this</span>.getGeoExtents() );
    <span class="reserved">this</span>.triggerEvent( KAMAP_EXTENTS_CHANGED, <span class="reserved">this</span>.getGeoExtents() );
};

<span class="comment">/**
 * internal function to create images for map tiles
 *
 * top - integer, the top of this image in pixels
 * left - integer, the left of this image in pixels
 * obj - object, the layer in which this image will reside
 */</span>
kaMap.<span class="reserved">prototype</span>.createImage = <span class="reserved">function</span>( top, left, obj ) {
    var img = document.createElement(<span class="literal">'img'</span>);
    img.src=<span class="reserved">this</span>.aPixel.src;
    img.width=<span class="reserved">this</span>.tileWidth;
    img.height=<span class="reserved">this</span>.tileHeight;
    <span class="comment">//first for firefox, rest for IE :(</span>
    img.setAttribute(<span class="literal">'style'</span>, <span class="literal">'position:absolute; top:'</span>+top+<span class="literal">'px; left:'</span>+left+<span class="literal">'px;'</span> );
    img.style.position = <span class="literal">'absolute'</span>;
    img.style.top = (top - <span class="reserved">this</span>.yOrigin)+<span class="literal">'px'</span>;
    img.style.left = (left - <span class="reserved">this</span>.xOrigin)+<span class="literal">'px'</span>;
    img.style.width = <span class="reserved">this</span>.tileWidth + <span class="literal">"px"</span>;
    img.style.height = <span class="reserved">this</span>.tileHeight + <span class="literal">"px"</span>;
    img.style.visibility = <span class="literal">'hidden'</span>;
    img.galleryimg = <span class="literal">"no"</span>; <span class="comment">//turn off image toolbar in IE</span>
    img.onerror = kaMap_imgOnError;
    img.onload = kaMap_imgOnLoad;
    img.errorCount = 0;
    img.id = <span class="literal">"i"</span> + <span class="reserved">this</span>.gImageID;
    img.layer = obj;
    img.kaMap = <span class="reserved">this</span>;
    <span class="reserved">this</span>.gImageID = <span class="reserved">this</span>.gImageID + 1;
    <span class="reserved">return</span> img;
};

kaMap.<span class="reserved">prototype</span>.resetTile = <span class="reserved">function</span>( id, bForce ) {
    var img = <span class="reserved">this</span>.DHTMLapi.getRawObject(id);
    <span class="reserved">if</span> (img.layer) {
        img.layer.setTile(<span class="reserved">this</span>, bForce);
    }
};

kaMap.<span class="reserved">prototype</span>.reloadImage = <span class="reserved">function</span>(id) {
};

kaMap.<span class="reserved">prototype</span>.resetImage = <span class="reserved">function</span>(id) {
};

<span class="comment">/**
 * internal function to handle images that fail to load
 */</span>
kaMap_imgOnError = <span class="reserved">function</span>(e) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.layer) {
        <span class="reserved">this</span>.layer.setTile(<span class="reserved">this</span>, true);
    }
};

<span class="comment">/**
 * internal function to track images as they finish loading.
 */</span>
kaMap_imgOnLoad = <span class="reserved">function</span>(e) {
    <span class="reserved">this</span>.style.visibility = <span class="literal">'visible'</span>;
};

<span class="comment">/**
 * internal function to append a row of images to each of the layers
 *
 * this function is used when the viewport is resized
 * modified by cappu can take a single layer as input
 */</span>
kaMap.<span class="reserved">prototype</span>.appendRow = <span class="reserved">function</span>(layer) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.nWide == 0) {
        <span class="reserved">return</span>;
    }
    var layers = null;
    <span class="reserved">if</span>(arguments.length==1) {
        layers = Array(layer);
    } <span class="reserved">else</span> {
        layers = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayers();
    }
    <span class="reserved">for</span>( var i=0; i&lt;layers.length; i++) {
        var obj = layers[i].domObj;
        <span class="reserved">for</span> (var j=0; j&lt;<span class="reserved">this</span>.nWide; j++) {
            var top = <span class="reserved">this</span>.nCurrentTop + (<span class="reserved">this</span>.nHigh * <span class="reserved">this</span>.tileHeight);
            var left = <span class="reserved">this</span>.nCurrentLeft + (j * <span class="reserved">this</span>.tileWidth);
            var img = <span class="reserved">this</span>.createImage( top, left, layers[i] );
            <span class="comment">//hack around IE problem with clipping layers when a filter is</span>
            <span class="comment">//active</span>
            <span class="reserved">if</span> (<span class="reserved">this</span>.isIE4) {
                img.style.filter = <span class="literal">"Alpha(opacity="</span>+layers[i].opacity+<span class="literal">")"</span>;
            }
            obj.appendChild( img );
        }
    }
    <span class="reserved">this</span>.nHigh = <span class="reserved">this</span>.nHigh + 1;
};

<span class="comment">/**
 * internal function to append a column of images to each of the layers
 *
 * this function is used when the viewport is resized
 * modified by cappu can take a single layer as input
 */</span>
kaMap.<span class="reserved">prototype</span>.appendColumn = <span class="reserved">function</span>(layer) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.nHigh == 0) {
        <span class="reserved">return</span>;
    }
    var layers = null;
    <span class="reserved">if</span>(arguments.length==1) {
        layers = Array(layer);
    } <span class="reserved">else</span> {
        layers = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayers();
    }
    <span class="reserved">for</span>( var i=0; i&lt;layers.length; i++) {
        var obj = layers[i].domObj;
        <span class="reserved">for</span>(var j=<span class="reserved">this</span>.nHigh-1; j&gt;=0; j--) {
            var top = <span class="reserved">this</span>.nCurrentTop + (j * <span class="reserved">this</span>.tileHeight);
            var left = <span class="reserved">this</span>.nCurrentLeft + (<span class="reserved">this</span>.nWide * <span class="reserved">this</span>.tileWidth);
            var img = <span class="reserved">this</span>.createImage( top, left, layers[i] );
            <span class="comment">//hack around IE problem with clipping layers when a filter is</span>
            <span class="comment">//active</span>
            <span class="reserved">if</span> (<span class="reserved">this</span>.isIE4) {
                img.style.filter = <span class="literal">"Alpha(opacity="</span>+layers[i].opacity+<span class="literal">")"</span>;
            }
            <span class="reserved">if</span> (j &lt; <span class="reserved">this</span>.nHigh-1) {
                obj.insertBefore(img, obj.childNodes[((j+1)*<span class="reserved">this</span>.nWide)]);
            } <span class="reserved">else</span> {
                obj.appendChild(img);
            }
         }
    }
    <span class="reserved">this</span>.nWide = <span class="reserved">this</span>.nWide + 1;
};

<span class="comment">/**
 * internal function to remove a column of images to each of the layers
 *
 * this function is used when the viewport is resized
 * modified by cappu can take a single layer as input
 */</span>
kaMap.<span class="reserved">prototype</span>.removeColumn = <span class="reserved">function</span>(layer) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.nWide &lt; 3) {
        <span class="reserved">return</span>;
    }
    var layers = null;
    <span class="reserved">if</span>(arguments.length==1) {
        layers = Array(layer);
    } <span class="reserved">else</span> {
        layers = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayers();
    }
    <span class="reserved">for</span>( var i=0; i&lt;layers.length; i++) {
        var d = layers[i].domObj;
        <span class="reserved">for</span>(var j=<span class="reserved">this</span>.nHigh - 1; j &gt;= 0; j--) {
            var img = d.childNodes[((j+1)*<span class="reserved">this</span>.nWide)-1];
            d.removeChild( img );
            <span class="comment">//attempt to prevent memory leaks</span>
            img.onload = null;
            img.onerror = null;
        }
    }
    <span class="reserved">this</span>.nWide = <span class="reserved">this</span>.nWide - 1;
};

<span class="comment">/**
 * internal function to remove a row of images to each of the layers
 *
 * this function is used when the viewport is resized
 * modified by cappu can take a single layer as input
 */</span>
kaMap.<span class="reserved">prototype</span>.removeRow = <span class="reserved">function</span>(layer) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.nHigh &lt; 3) {
        <span class="reserved">return</span>;
    }

    var layers = null;
    <span class="reserved">if</span>(arguments.length==1) {
        layers = Array(layer);
    } <span class="reserved">else</span> {
        layers = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayers();
    }

    <span class="reserved">for</span>( var i=0; i&lt;layers.length; i++) {
        var d = layers[i].domObj;
        <span class="reserved">for</span>(var j=<span class="reserved">this</span>.nWide - 1; j &gt;= 0; j--) {
            var img = d.childNodes[((<span class="reserved">this</span>.nHigh-1)*<span class="reserved">this</span>.nWide)+j];
            d.removeChild( img );
            <span class="comment">//attempt to prevent memory leaks</span>
            img.onload = null;
            img.onerror = null;
        }
    }
    <span class="reserved">this</span>.nHigh = <span class="reserved">this</span>.nHigh - 1;
};

kaMap.<span class="reserved">prototype</span>.hideLayers = <span class="reserved">function</span>() {
    <span class="reserved">if</span> (!<span class="reserved">this</span>.hideLayersOnMove) {
        <span class="reserved">return</span>;
    }

    <span class="reserved">if</span> (<span class="reserved">this</span>.layersHidden) {
        <span class="reserved">return</span>;
    }
    var layers = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayers();
    <span class="reserved">for</span>( var i=0; i&lt;layers.length; i++) {
        layers[i]._visible = layers[i].visible;
        <span class="reserved">if</span> (layers[i].name != <span class="literal">'__base__'</span>) {
            layers[i].setVisibility( false );
        }
    }
    <span class="reserved">for</span>( var i = 0; i &lt; <span class="reserved">this</span>.aCanvases.length; i++) {
        <span class="reserved">this</span>.aCanvases[i].style.visibility = <span class="literal">'hidden'</span>;
        <span class="reserved">this</span>.aCanvases[i].style.display = <span class="literal">'none'</span>;
    }
    <span class="reserved">this</span>.layersHidden = true;
};

kaMap.<span class="reserved">prototype</span>.showLayers = <span class="reserved">function</span>() {
    <span class="reserved">if</span> (!<span class="reserved">this</span>.hideLayersOnMove) {
        <span class="reserved">return</span>;
    }

    <span class="reserved">if</span> (!<span class="reserved">this</span>.layersHidden) {
        <span class="reserved">return</span>;
    }
    var layers = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayers();
    <span class="reserved">for</span>( var i=0; i&lt;layers.length; i++) {
        layers[i].setVisibility( layers[i]._visible );
    }
    <span class="reserved">for</span>( var i = 0; i &lt; <span class="reserved">this</span>.aCanvases.length; i++) {
        <span class="reserved">this</span>.aCanvases[i].style.visibility = <span class="literal">'visible'</span>;
        <span class="reserved">this</span>.aCanvases[i].style.display = <span class="literal">'block'</span>;
    }
    <span class="reserved">this</span>.layersHidden = false;
};

<span class="comment">/**
 * move the map by a certain amount
 */</span>
kaMap.<span class="reserved">prototype</span>.moveBy = <span class="reserved">function</span>( x, y ) {
    var til = <span class="reserved">this</span>.theInsideLayer;
    til.style.top = (safeParseInt(til.style.top)+y) + <span class="literal">'px'</span>;
    til.style.left = (safeParseInt(til.style.left)+x )+ <span class="literal">'px'</span>;
    <span class="reserved">this</span>.checkWrap();
};

<span class="comment">/**
 * slide the map by a certain amount
 */</span>
kaMap.<span class="reserved">prototype</span>.slideBy = <span class="reserved">function</span>(x,y) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.slideid!=null) {
        goQueueManager.dequeue( <span class="reserved">this</span>.slideid );
    }

    <span class="reserved">this</span>.as = [];

    var absX = Math.abs(x);
    var absY = Math.abs(y);

    var signX = x/absX;
    var signY = y/absY;

    var distance = absX&gt;absY?absX:absY;
    var steps = Math.floor(distance/<span class="reserved">this</span>.pixelsPerStep);

    var dx = dy = 0;
    <span class="reserved">if</span> (steps &gt; 0) {
        dx = (x)/(steps*<span class="reserved">this</span>.pixelsPerStep);
        dy = (y)/(steps*<span class="reserved">this</span>.pixelsPerStep);
    }

    var remainderX = x - dx*steps*<span class="reserved">this</span>.pixelsPerStep;
    var remainderY = y - dy*steps*<span class="reserved">this</span>.pixelsPerStep;

    var px=py=0;

    var curspeed=<span class="reserved">this</span>.accelerationFactor;
    var i=0;
    <span class="reserved">while</span>(i&lt;steps) {
        <span class="reserved">if</span> (i&gt;0) {
          px+=<span class="reserved">this</span>.as[i-1][0];
          py+=<span class="reserved">this</span>.as[i-1][1];
        }

        var cx = px+Math.round(dx*<span class="reserved">this</span>.pixelsPerStep);
        var cy = py+Math.round(dy*<span class="reserved">this</span>.pixelsPerStep);
        <span class="reserved">this</span>.as[i]=new Array(cx-px,cy-py);
        i++;
    }
    <span class="reserved">if</span> (remainderX != 0 || remainderY != 0) {
        <span class="reserved">this</span>.as[i] = [remainderX, remainderY];
    }
    <span class="reserved">this</span>.hideLayers();
    <span class="reserved">this</span>.slideid=goQueueManager.enqueue(<span class="reserved">this</span>.timePerStep,<span class="reserved">this</span>,<span class="reserved">this</span>.slide,[0]);
};

<span class="comment">/**
 * handle individual movement within a slide
 */</span>
kaMap.<span class="reserved">prototype</span>.slide = <span class="reserved">function</span>(pos) {
    <span class="reserved">if</span> (pos&gt;=<span class="reserved">this</span>.as.length) {
        <span class="reserved">this</span>.as=slideid=null;
        <span class="reserved">this</span>.showLayers();
        <span class="reserved">this</span>.triggerEvent( KAMAP_EXTENTS_CHANGED, <span class="reserved">this</span>.getGeoExtents() );
        <span class="reserved">return</span>;
    }

    <span class="reserved">this</span>.moveBy( <span class="reserved">this</span>.as[pos][0], <span class="reserved">this</span>.as[pos][1] );

    pos ++;
    <span class="reserved">this</span>.slideid=goQueueManager.enqueue(<span class="reserved">this</span>.timePerStep,<span class="reserved">this</span>,<span class="reserved">this</span>.slide,[ pos]);
};

<span class="comment">/**
 * internal function to handle various events that are passed to the
 * current tool
 */</span>
kaMap_onkeypress = <span class="reserved">function</span>( e ) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.kaMap.currentTool) {
        <span class="reserved">this</span>.kaMap.currentTool.onkeypress( e );
    }
};

kaMap_onmousemove = <span class="reserved">function</span>( e ) {
    e = (e)?e:((event)?event:null);
    <span class="reserved">if</span> (e.button==2) {
        <span class="reserved">this</span>.kaMap.triggerEvent( KAMAP_CONTEXT_MENU );
    }
    <span class="reserved">if</span> (<span class="reserved">this</span>.kaMap.currentTool) {
        <span class="reserved">this</span>.kaMap.currentTool.onmousemove( e );
    }
};

kaMap_onmousedown = <span class="reserved">function</span>( e ) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.kaMap.currentTool) {
        <span class="reserved">this</span>.kaMap.currentTool.onmousedown( e );
    }
};

kaMap_onmouseup = <span class="reserved">function</span>( e ) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.kaMap.currentTool) {
        <span class="reserved">this</span>.kaMap.currentTool.onmouseup( e );
    }
};

kaMap_onmouseover = <span class="reserved">function</span>( e ) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.kaMap.currentTool) {
        <span class="reserved">this</span>.kaMap.currentTool.onmouseover( e );
    }
};

kaMap_onmouseout = <span class="reserved">function</span>( e ) {
     <span class="reserved">if</span> (<span class="reserved">this</span>.kaMap.currentTool) {
        <span class="reserved">this</span>.kaMap.currentTool.onmouseout( e );
    }
};

kaMap_oncontextmenu = <span class="reserved">function</span>( e ) {
    e = e?e:event;
    <span class="reserved">if</span> (e.preventDefault) {
        e.preventDefault();
    }
    <span class="reserved">return</span> false;
};

kaMap_ondblclick = <span class="reserved">function</span>( e ) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.kaMap.currentTool) {
        <span class="reserved">this</span>.kaMap.currentTool.ondblclick( e );
    }
};

kaMap_onmousewheel = <span class="reserved">function</span>( e ) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.kaMap.currentTool) {
        <span class="reserved">this</span>.kaMap.currentTool.onmousewheel( e );
    }
};

kaMap.<span class="reserved">prototype</span>.cancelEvent = <span class="reserved">function</span>(e) {
    e = (e)?e:((event)?event:null);
    e.returnValue = false;
    <span class="reserved">if</span> (e.preventDefault) {
        e.preventDefault();
    }
    <span class="reserved">return</span> false;
};

kaMap.<span class="reserved">prototype</span>.registerTool = <span class="reserved">function</span>( toolObj ) {
    <span class="reserved">this</span>.aTools.push( toolObj );
};

kaMap.<span class="reserved">prototype</span>.activateTool = <span class="reserved">function</span>( toolObj ) {
    <span class="reserved">if</span> (<span class="reserved">this</span>.currentTool) {
        <span class="reserved">this</span>.currentTool.deactivate();
    }
    <span class="reserved">this</span>.currentTool = toolObj;
    <span class="reserved">if</span> (<span class="reserved">this</span>.theInsideLayer) {
        <span class="reserved">this</span>.setCursor(<span class="reserved">this</span>.currentTool.cursor);
    }
};

kaMap.<span class="reserved">prototype</span>.deactivateTool = <span class="reserved">function</span>( toolObj ) {

    <span class="reserved">if</span> (<span class="reserved">this</span>.currentTool == toolObj) {
        <span class="reserved">this</span>.currentTool = null;
    }
    <span class="reserved">if</span> (<span class="reserved">this</span>.theInsideLayer) {
        <span class="reserved">this</span>.theInsideLayer.style.cursor = <span class="literal">'auto'</span>;
    }
};

<span class="comment">/*
 * inspired by code in WindowManager.js
 * Copyright 2005 MetaCarta, Inc., released under the BSD License
 */</span>
kaMap.<span class="reserved">prototype</span>.setCursor = <span class="reserved">function</span>(cursor) {
    <span class="reserved">if</span> (cursor &amp;&amp; cursor.length &amp;&amp; typeof cursor == <span class="literal">'object'</span>) {
        <span class="reserved">for</span> (var i = 0; i &lt; cursor.length; i++) {
            <span class="reserved">this</span>.theInsideLayer.style.cursor = cursor[i];
            <span class="reserved">if</span> (<span class="reserved">this</span>.theInsideLayer.style.cursor == cursor[i]) {
                break;
            }
        }
    } <span class="reserved">else</span> <span class="reserved">if</span> (typeof cursor == <span class="literal">'string'</span>) {
        <span class="reserved">this</span>.theInsideLayer.style.cursor = cursor;
    } <span class="reserved">else</span> {
        <span class="reserved">this</span>.theInsideLayer.style.cursor = <span class="literal">'auto'</span>;
    }
};

<span class="comment">/**
 * internal function to check if images need to be wrapped
 */</span>
kaMap.<span class="reserved">prototype</span>.checkWrap = <span class="reserved">function</span>() {
    var bWrapped = false;
    <span class="comment">// adjust theInsideLayer so it doesn't show more than maxExtents (if set)</span>
    <span class="reserved">this</span>.checkMaxExtents();

    <span class="reserved">this</span>.xOffset = safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.left) + <span class="reserved">this</span>.nCurrentLeft - <span class="reserved">this</span>.xOrigin;
    <span class="reserved">this</span>.yOffset = safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.top) + <span class="reserved">this</span>.nCurrentTop - <span class="reserved">this</span>.yOrigin;

    <span class="reserved">while</span> (<span class="reserved">this</span>.xOffset &gt; 0) {
        <span class="reserved">this</span>.wrapR2L();
        bWrapped = true;
    }
    <span class="reserved">while</span> (<span class="reserved">this</span>.xOffset &lt; -(<span class="reserved">this</span>.nBuffer*<span class="reserved">this</span>.tileWidth)) {
        <span class="reserved">this</span>.wrapL2R();
        bWrapped = true;
    }
    <span class="reserved">while</span> (<span class="reserved">this</span>.yOffset &gt; -(<span class="reserved">this</span>.nBuffer*<span class="reserved">this</span>.tileHeight)) {
        <span class="reserved">this</span>.wrapB2T();
        bWrapped = true;
    }
    <span class="reserved">while</span> (<span class="reserved">this</span>.yOffset &lt; -(2*<span class="reserved">this</span>.nBuffer*<span class="reserved">this</span>.tileHeight)) {
        <span class="reserved">this</span>.wrapT2B();
        bWrapped = true;
    }

    var layer = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].aLayers[0].domObj;
    var img = layer.childNodes[0].style;
    <span class="reserved">this</span>.nCurrentTop = safeParseInt(img.top) + <span class="reserved">this</span>.yOrigin;
    <span class="reserved">this</span>.nCurrentLeft = safeParseInt(img.left) + <span class="reserved">this</span>.xOrigin;

    <span class="reserved">if</span> (bWrapped) {
        <span class="reserved">this</span>.triggerEvent( KAMAP_METAEXTENTS_CHANGED, <span class="reserved">this</span>.getMetaExtents() );
    }
};

<span class="comment">/**
 * kaMap.checkMaxExtents()
 *
 * For maps with maxExtent set, this function adjusts the position of
 * theInsideLayer so it never shows more than the maximum extent specified
 * in the mapfile.  Called from kaMap.checkWrap() since that is called
 * with all movement of theInsideLayer
 *
 * Added by tschaub
 */</span>
kaMap.<span class="reserved">prototype</span>.checkMaxExtents = <span class="reserved">function</span>() {
    var maxExtents = <span class="reserved">this</span>.getCurrentMap().maxExtents;
    <span class="reserved">if</span> (maxExtents.length == 4) {
		<span class="reserved">if</span> ((maxExtents[0] &gt;= maxExtents[2]) || (maxExtents[1] &gt;= maxExtents[3])) {
			<span class="comment">// fail silently</span>
			<span class="reserved">return</span> false;
		}
        var geoExtents = <span class="reserved">this</span>.getGeoExtents();
        var hPixelAdjustment = 0;
        var vPixelAdjustment = 0;
        <span class="comment">// check left and right</span>
        <span class="reserved">if</span> (geoExtents[0] &lt; maxExtents[0]) {
            <span class="comment">// extra on right</span>
            hPixelAdjustment = Math.round((maxExtents[0] - geoExtents[0]) / <span class="reserved">this</span>.cellSize);
        }
        <span class="reserved">if</span> (geoExtents[2] &gt; maxExtents[2]) {
            <span class="comment">// extra on left</span>
			<span class="reserved">if</span>(hPixelAdjustment != 0)
			{
				<span class="comment">// if both left and right are over, split the difference</span>
	            hPixelAdjustment += Math.round((maxExtents[2] - geoExtents[2]) / <span class="reserved">this</span>.cellSize);
				hPixelAdjustment /= 2;
			} <span class="reserved">else</span> {
				hPixelAdjustment += Math.round((maxExtents[2] - geoExtents[2]) / <span class="reserved">this</span>.cellSize);
			}
        }
		<span class="comment">// check if horizontal adjustment is needed</span>
		<span class="reserved">if</span>(hPixelAdjustment != 0) {
            <span class="reserved">this</span>.theInsideLayer.style.left = (safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.left) - hPixelAdjustment) + <span class="literal">'px'</span>;
        }
        <span class="comment">// check top and bottom - both can not be corrected</span>
        <span class="reserved">if</span>(geoExtents[1] &lt; maxExtents[1]) {
            <span class="comment">// extra on bottom</span>
            vPixelAdjustment = Math.round((maxExtents[1] - geoExtents[1]) / <span class="reserved">this</span>.cellSize);
        }
        <span class="reserved">if</span>(geoExtents[3] &gt; maxExtents[3]) {
            <span class="comment">// extra on top</span>
			<span class="reserved">if</span>(vPixelAdjustment != 0) {
				<span class="comment">// if both top and bottom are over, split the difference</span>
	            vPixelAdjustment += Math.round((maxExtents[3] - geoExtents[3]) / <span class="reserved">this</span>.cellSize);
				vPixelAdjustment /= 2;
			} <span class="reserved">else</span> {
	            vPixelAdjustment = Math.round((maxExtents[3] - geoExtents[3]) / <span class="reserved">this</span>.cellSize);
			}
        }
		<span class="reserved">if</span>(vPixelAdjustment != 0) {
            <span class="reserved">this</span>.theInsideLayer.style.top = (safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.top) + vPixelAdjustment) + <span class="literal">'px'</span>;
        }
    }
};

<span class="comment">/**
 * internal function to reuse extra images
 * take last image from each row and put it at the beginning
 */</span>
kaMap.<span class="reserved">prototype</span>.wrapR2L = <span class="reserved">function</span>() {
    <span class="reserved">this</span>.xOffset = <span class="reserved">this</span>.xOffset - (<span class="reserved">this</span>.nBuffer * <span class="reserved">this</span>.tileWidth);

    var layers = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayers();
    <span class="reserved">for</span>( var k=0; k&lt;layers.length; k++) {
        var d = layers[k].domObj;
        var refLeft = safeParseInt(d.childNodes[0].style.left);
        <span class="reserved">for</span> (var j=0; j&lt;<span class="reserved">this</span>.nHigh; j++) {
            var imgLast = d.childNodes[((j+1)*<span class="reserved">this</span>.nWide)-1];
            var imgNext = d.childNodes[j*<span class="reserved">this</span>.nWide];

            imgLast.style.left = (refLeft - <span class="reserved">this</span>.tileWidth) + <span class="literal">'px'</span>;
            imgLast.src = <span class="reserved">this</span>.aPixel.src;
            d.removeChild(imgLast);
            d.insertBefore(imgLast, imgNext);
            <span class="reserved">if</span> (layers[k].visible) {
                layers[k].setTile(imgLast);
            }
        }
    }
};

<span class="comment">/**
 * internal function to reuse extra image
 * take first image from each row and put it at the end
 */</span>
kaMap.<span class="reserved">prototype</span>.wrapL2R = <span class="reserved">function</span>() {
     <span class="reserved">this</span>.xOffset = <span class="reserved">this</span>.xOffset + (<span class="reserved">this</span>.nBuffer*<span class="reserved">this</span>.tileWidth);
    var layers = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayers();
    <span class="reserved">for</span>( var k=0; k&lt;layers.length; k++) {
        var d = layers[k].domObj;
        var refLeft = safeParseInt(d.childNodes[<span class="reserved">this</span>.nWide-1].style.left);
        <span class="reserved">for</span> (var j=0; j&lt;<span class="reserved">this</span>.nHigh; j++) {
            var imgFirst = d.childNodes[j*<span class="reserved">this</span>.nWide];
            var imgNext;
            <span class="comment">/* need to use insertBefore to get a node at the end of a 'row'
             * but this doesn't work for the very last row :(*/</span>
            <span class="reserved">if</span> (j &lt; <span class="reserved">this</span>.nHigh-1) {
                imgNext = d.childNodes[((j+1)*<span class="reserved">this</span>.nWide)];
            } <span class="reserved">else</span> {
                imgNext = null;
            }

            imgFirst.style.left = (refLeft + <span class="reserved">this</span>.tileWidth) + <span class="literal">'px'</span>;
            imgFirst.src = <span class="reserved">this</span>.aPixel.src;

            d.removeChild(imgFirst);
            <span class="reserved">if</span> (imgNext) {
                d.insertBefore(imgFirst, imgNext);
            } <span class="reserved">else</span> {
                d.appendChild(imgFirst);
            }
            <span class="reserved">if</span> (layers[k].visible) {
                layers[k].setTile(imgFirst);
            }
        }
    }
};

<span class="comment">/**
 * internal function to reuse extra images
 * take top image from each column and put it at the bottom
 */</span>
kaMap.<span class="reserved">prototype</span>.wrapT2B = <span class="reserved">function</span>() {
    <span class="reserved">this</span>.yOffset = <span class="reserved">this</span>.yOffset + (<span class="reserved">this</span>.nBuffer*<span class="reserved">this</span>.tileHeight);
    var layers = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayers();
    <span class="reserved">for</span>( var k=0; k&lt;layers.length; k++) {
        var d = layers[k].domObj;
        var refTop = safeParseInt(d.childNodes[(<span class="reserved">this</span>.nHigh*<span class="reserved">this</span>.nWide)-1].style.top);
        <span class="reserved">for</span> (var i=0; i&lt;<span class="reserved">this</span>.nWide; i++) {
            var imgBottom = d.childNodes[0];
            imgBottom.style.top = (refTop + <span class="reserved">this</span>.tileHeight) + <span class="literal">'px'</span>;
            imgBottom.src = <span class="reserved">this</span>.aPixel.src;
            d.removeChild(imgBottom);
            d.appendChild(imgBottom);
            <span class="reserved">if</span> (layers[k].visible) {
                layers[k].setTile(imgBottom);
            }
        }
    }
};

<span class="comment">/**
 * internal function to reuse extra images
 * take bottom image from each column and put it at the top
 */</span>
kaMap.<span class="reserved">prototype</span>.wrapB2T = <span class="reserved">function</span>() {
    <span class="reserved">this</span>.yOffset = <span class="reserved">this</span>.yOffset - (<span class="reserved">this</span>.nBuffer*<span class="reserved">this</span>.tileHeight);
    var layers = <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayers();
    <span class="reserved">for</span>( var k=0; k&lt;layers.length; k++) {
        var d = layers[k].domObj;
        var refTop = safeParseInt(d.childNodes[0].style.top);
        <span class="reserved">for</span> (var i=0; i&lt;<span class="reserved">this</span>.nWide; i++) {
            var imgTop = d.childNodes[(<span class="reserved">this</span>.nHigh*<span class="reserved">this</span>.nWide)-1];

            imgTop.style.top = (refTop - <span class="reserved">this</span>.tileHeight) + <span class="literal">'px'</span>;
            imgTop.src = <span class="reserved">this</span>.aPixel.src;

            d.removeChild(imgTop);
            d.insertBefore(imgTop, d.childNodes[0]);
            <span class="reserved">if</span> (layers[k].visible) {
                layers[k].setTile(imgTop);
            }

        }
    }
};

<span class="comment">/**
 * kaMap.addMap( oMap )
 *
 * add a new instance of _map to kaMap.  _map is an internal class that
 * represents a map file from the configuration file.  This function is
 * intended for internal use by the init.php script.
 *
 * oMap - object, an instance of _map
 */</span>
kaMap.<span class="reserved">prototype</span>.addMap = <span class="reserved">function</span>( oMap ) {
    oMap.kaMap = <span class="reserved">this</span>;
    <span class="reserved">this</span>.aMaps[oMap.name] = oMap;
};

<span class="comment">/**
 * kaMap.getMaps()
 *
 * return an array of all the _map objects that kaMap knows about.  These can
 * be used to generate controls to switch between maps and to get information
 * about the layers (groups) and scales available in a given map.
 */</span>
kaMap.<span class="reserved">prototype</span>.getMaps = <span class="reserved">function</span>() {
    <span class="reserved">return</span> <span class="reserved">this</span>.aMaps;
};

<span class="comment">/**
 * kaMap.getCurrentMap()
 *
 * returns the currently selected _map object.  This can be used to get
 * information about the layers (groups) and scales available in the current
 * map.
 */</span>
kaMap.<span class="reserved">prototype</span>.getCurrentMap = <span class="reserved">function</span>() {
    <span class="reserved">return</span> <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap];
};

<span class="comment">/**
 * kaMap.selectMap( name )
 *
 * select one of the maps that kaMap knows about and re-initialize kaMap with
 * this new map.  This function returns true if name is valid and false if the
 * map is invalid.  Note that a return of true does not imply that the map is
 * fully active.  You must register for the KAMAP_MAP_INITIALIZED event since
 * the map initialization happens asynchronously.
 *
 * name - string, the name of the map to select
 */</span>
kaMap.<span class="reserved">prototype</span>.selectMap = <span class="reserved">function</span>( name ) {
    <span class="reserved">if</span> (!<span class="reserved">this</span>.aMaps[name]) {
        <span class="reserved">return</span> false;
    } <span class="reserved">else</span> {
        <span class="reserved">this</span>.currentMap = name;
        var oMap = <span class="reserved">this</span>.getCurrentMap();
        <span class="reserved">this</span>.setBackgroundColor(oMap.backgroundColor);

        <span class="comment">//modified by cappu</span>
        <span class="reserved">this</span>.setMapLayers();
        <span class="reserved">if</span> (oMap.aZoomTo.length != 0) {
            <span class="reserved">this</span>.zoomTo(oMap.aZoomTo[0], oMap.aZoomTo[1], oMap.aZoomTo[2]);
            oMap.aZoomTo.length = 0;
        } <span class="reserved">else</span> {
            <span class="reserved">this</span>.zoomToExtents( oMap.currentExtents[0], oMap.currentExtents[1],
                               oMap.currentExtents[2], oMap.currentExtents[3] );
        }
        <span class="reserved">this</span>.triggerEvent( KAMAP_MAP_INITIALIZED, <span class="reserved">this</span>.currentMap );
        <span class="reserved">return</span> true;
    }
};

<span class="comment">/*
 * internal function added by cappu
 * check wich layers are visible and checked visible
 * in legend for current scale and map in InsideLayer
 * If needed create append or remove mapLayer!
 */</span>
kaMap.<span class="reserved">prototype</span>.setMapLayers = <span class="reserved">function</span>( ) {
    var oMap = <span class="reserved">this</span>.getCurrentMap();
    <span class="comment">//remove layers not to be drown at the selected scale this should be change to not remove the visible</span>
    <span class="reserved">for</span>(var i = <span class="reserved">this</span>.theInsideLayer.childNodes.length - 1; i&gt;=0; i-- ) {
        <span class="reserved">if</span> (<span class="reserved">this</span>.theInsideLayer.childNodes[i].className == <span class="literal">'mapLayer'</span>) {
            <span class="reserved">this</span>.theInsideLayer.childNodes[i].appended=false;
            <span class="reserved">this</span>.theInsideLayer.removeChild(<span class="reserved">this</span>.theInsideLayer.childNodes[i]);        }
    }
   <span class="comment">//now check layer and create or append</span>
    layers=oMap.getLayers(); <span class="comment">//get only visible and checked layers</span>
    <span class="reserved">for</span>( var i=0; i&lt;layers.length; i++) {
        <span class="reserved">if</span>(!layers[i].domObj) {
            var d = <span class="reserved">this</span>.createMapLayer( layers[i].name );
            <span class="reserved">this</span>.theInsideLayer.appendChild( d );
            d.appended=true;
            layers[i].domObj = d;
            layers[i].setOpacity( layers[i].opacity );
            layers[i].setZIndex( layers[i].zIndex );
            layers[i].setVisibility( layers[i].visible );
            <span class="reserved">this</span>.nWide = 0;
            <span class="reserved">this</span>.nHigh = 0;
            <span class="reserved">this</span>.drawGroup(layers[i]);
        } <span class="reserved">else</span> <span class="reserved">if</span> (!layers[i].domObj.appended) {
            <span class="reserved">this</span>.theInsideLayer.appendChild( layers[i].domObj );
            layers[i].domObj.appended=true;
            layers[i].setZIndex( layers[i].zIndex );
        }
    }
    <span class="reserved">return</span> true;
};

<span class="comment">/*
 * internal function added by cappu
 * this function force a layer create image
 */</span>
kaMap.<span class="reserved">prototype</span>.drawGroup = <span class="reserved">function</span>(group) {
    var newViewportWidth = <span class="reserved">this</span>.getObjectWidth(<span class="reserved">this</span>.domObj);
    var newViewportHeight = <span class="reserved">this</span>.getObjectHeight(<span class="reserved">this</span>.domObj);

    <span class="reserved">if</span> (<span class="reserved">this</span>.viewportWidth == null) {
        <span class="reserved">this</span>.theInsideLayer.style.top = (-1*<span class="reserved">this</span>.nCurrentTop + <span class="reserved">this</span>.yOrigin) + <span class="literal">"px"</span>;
        <span class="reserved">this</span>.theInsideLayer.style.left = (-1*<span class="reserved">this</span>.nCurrentLeft + <span class="reserved">this</span>.xOrigin) + <span class="literal">"px"</span>;
        <span class="reserved">this</span>.viewportWidth = newViewportWidth;
        <span class="reserved">this</span>.viewportHeight = newViewportHeight;
    }
    var newWide = Math.ceil((newViewportWidth / <span class="reserved">this</span>.tileWidth) + 2*<span class="reserved">this</span>.nBuffer);
    var newHigh = Math.ceil((newViewportHeight / <span class="reserved">this</span>.tileHeight) + 2*<span class="reserved">this</span>.nBuffer);

    <span class="reserved">this</span>.viewportWidth = newViewportWidth;
    <span class="reserved">this</span>.viewportHeight = newViewportHeight;

    <span class="reserved">if</span> (<span class="reserved">this</span>.nHigh == 0 &amp;&amp; <span class="reserved">this</span>.nWide == 0) {
        <span class="reserved">this</span>.nWide = newWide;
    }

    <span class="reserved">while</span> (<span class="reserved">this</span>.nHigh &lt; newHigh) {
        <span class="reserved">this</span>.appendRow(group);
    }
    <span class="reserved">while</span> (<span class="reserved">this</span>.nHigh &gt; newHigh) {
        <span class="reserved">this</span>.removeRow(group);
    }
    <span class="reserved">while</span> (<span class="reserved">this</span>.nWide &lt; newWide) {
        <span class="reserved">this</span>.appendColumn(group);
    }
    <span class="reserved">while</span> (<span class="reserved">this</span>.nWide &gt; newWide) {
        <span class="reserved">this</span>.removeColumn(group);
    }
    <span class="reserved">return</span> true;
};

kaMap.<span class="reserved">prototype</span>.createMapLayer = <span class="reserved">function</span>( id ) {
    var d = document.createElement( <span class="literal">'div'</span> );
    d.id = id;
    d.className = <span class="literal">'mapLayer'</span>;
    d.style.position = <span class="literal">'absolute'</span>;
    d.style.visibility = <span class="literal">'visible'</span>;
    d.style.left = <span class="literal">'0px'</span>;
    d.style.top = <span class="literal">'0px'</span>;
    d.style.width= <span class="literal">'3000px'</span>;
    d.style.height = <span class="literal">'3000px'</span>;
    d.appended= false;<span class="comment">//added by cappu</span>
    <span class="reserved">return</span> d;
};

<span class="comment">//modified by cappu</span>
kaMap.<span class="reserved">prototype</span>.addMapLayer = <span class="reserved">function</span>( l ) {
    var map = <span class="reserved">this</span>.getCurrentMap();
    map.addLayer(l);
    <span class="reserved">this</span>.setMapLayers();
    <span class="reserved">this</span>.paintLayer(l);
    <span class="reserved">this</span>.triggerEvent( KAMAP_LAYERS_CHANGED, <span class="reserved">this</span>.currentMap );
};

<span class="comment">//added by cappu</span>
kaMap.<span class="reserved">prototype</span>.removeMapLayer = <span class="reserved">function</span>( id ) {
    var map = <span class="reserved">this</span>.getCurrentMap();
    var layer = map.getLayer(id);
    <span class="reserved">if</span> (!layer) {
        <span class="reserved">return</span> false;
    }
    <span class="reserved">if</span> (map.removeLayer ( map.getLayer(id) )) {
        <span class="reserved">this</span>.setMapLayers();
        <span class="reserved">this</span>.triggerEvent( KAMAP_LAYERS_CHANGED, <span class="reserved">this</span>.currentMap );
    }
};

kaMap.<span class="reserved">prototype</span>.getCenter = <span class="reserved">function</span>() {
    var deltaMouseX = <span class="reserved">this</span>.nCurrentLeft - <span class="reserved">this</span>.xOrigin + safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.left);
    var deltaMouseY = <span class="reserved">this</span>.nCurrentTop - <span class="reserved">this</span>.yOrigin +  safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.top);

    var vpTop = <span class="reserved">this</span>.nCurrentTop - deltaMouseY;
    var vpLeft = <span class="reserved">this</span>.nCurrentLeft - deltaMouseX;

    var vpCenterX = vpLeft + <span class="reserved">this</span>.viewportWidth/2;
    var vpCenterY = vpTop + <span class="reserved">this</span>.viewportHeight/2;

    <span class="reserved">return</span> new Array( vpCenterX, vpCenterY );
};

<span class="comment">/**
 * kaMap.getGeoExtents()
 *
 * returns an array of geographic extents for the current view in the form
 * (inx, miny, maxx, maxy)
 */</span>
kaMap.<span class="reserved">prototype</span>.getGeoExtents = <span class="reserved">function</span>() {
    var minx = -1*(safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.left) - <span class="reserved">this</span>.xOrigin) * <span class="reserved">this</span>.cellSize;
    var maxx = minx + <span class="reserved">this</span>.viewportWidth * <span class="reserved">this</span>.cellSize;
    var maxy= (safeParseInt(<span class="reserved">this</span>.theInsideLayer.style.top) - <span class="reserved">this</span>.yOrigin) * <span class="reserved">this</span>.cellSize;
    var miny= maxy - <span class="reserved">this</span>.viewportHeight * <span class="reserved">this</span>.cellSize;
    <span class="reserved">return</span> [minx,miny,maxx,maxy];
};

<span class="comment">/**
 * kaMap.getMetaExtents()
 *
 * returns an array of geographic extents for the loaded tiles in the form
 * (minx, miny, maxx, maxy)
 */</span>
kaMap.<span class="reserved">prototype</span>.getMetaExtents = <span class="reserved">function</span>() {
    <span class="comment">//use current extents if no layers visible</span>
    var result = <span class="reserved">this</span>.getGeoExtents();
    var oMap = <span class="reserved">this</span>.getCurrentMap();
    layers=oMap.getLayers();
    <span class="reserved">for</span>( var i=0; i&lt;layers.length; i++) {
        <span class="comment">//find first layer with a domObj</span>
        <span class="reserved">if</span>(layers[i].domObj) {
            var d = layers[i].domObj;
            <span class="comment">//top left of first image should be top left of loaded tiles</span>
            var pl = safeParseInt(d.childNodes[0].style.left);
            var pt = safeParseInt(d.childNodes[0].style.top);
            <span class="comment">/*  I think the first child is always top left ...
            for (var j=0;j&lt;d.childNodes.length; j++) {
                if (pl == null) {
                    pl = safeParseInt(d.childNodes[j].style.left);
                    pt = safeParseInt(d.childNodes[j].style.top);
                } else {
                    pl = Math.min(pl,safeParseInt(d.childNodes[j].style.left));
                    pt = Math.min(pt,safeParseInt(d.childNodes[j].style.top));
                }
            }
            */</span>
            <span class="comment">//convert to geographic</span>
            var glt = <span class="reserved">this</span>.pixToGeo(pl,pt,true);
            var left = -1*glt[0];
            var top = -1*glt[1];
            <span class="comment">//bottom right is easy to calculate from this</span>
            var right = left + <span class="reserved">this</span>.nWide*<span class="reserved">this</span>.tileWidth*<span class="reserved">this</span>.cellSize;
            var bottom = top - <span class="reserved">this</span>.nHigh*<span class="reserved">this</span>.tileHeight*<span class="reserved">this</span>.cellSize;
            result = [left, bottom, right, top];
            break;
        }
    }
    <span class="reserved">return</span> result;
};

kaMap.<span class="reserved">prototype</span>.zoomIn = <span class="reserved">function</span>() {
    <span class="reserved">this</span>.zoomByFactor(<span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].zoomIn());
};

kaMap.<span class="reserved">prototype</span>.zoomOut = <span class="reserved">function</span>() {
    <span class="reserved">this</span>.zoomByFactor(<span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].zoomOut());
};

kaMap.<span class="reserved">prototype</span>.zoomToScale = <span class="reserved">function</span>( scale ) {
    <span class="reserved">this</span>.zoomByFactor(<span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].zoomToScale(scale));
};

kaMap.<span class="reserved">prototype</span>.zoomByFactor = <span class="reserved">function</span>( nZoomFactor ) {
    <span class="reserved">if</span> (nZoomFactor == 1) {
        <span class="reserved">this</span>.triggerEvent( KAMAP_NOTICE, <span class="literal">"NOTICE: changing to current scale aborted"</span>);
        <span class="reserved">return</span>;
    }

    <span class="reserved">this</span>.cellSize = <span class="reserved">this</span>.cellSize/nZoomFactor;
    <span class="reserved">this</span>.setMapLayers();
    <span class="reserved">this</span>.initializeLayers(nZoomFactor);

    <span class="reserved">this</span>.triggerEvent( KAMAP_SCALE_CHANGED, <span class="reserved">this</span>.getCurrentScale() );
    <span class="reserved">this</span>.triggerEvent( KAMAP_EXTENTS_CHANGED, <span class="reserved">this</span>.getGeoExtents() );
};

kaMap.<span class="reserved">prototype</span>.getCurrentScale = <span class="reserved">function</span>() {
    <span class="reserved">return</span> <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].aScales[<span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].currentScale];
};

kaMap.<span class="reserved">prototype</span>.setLayerQueryable = <span class="reserved">function</span>( name, bQueryable ) {
    <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].setLayerQueryable( name, bQueryable );
};

kaMap.<span class="reserved">prototype</span>.setLayerVisibility = <span class="reserved">function</span>( name, bVisible ) {
    <span class="reserved">if</span>(!<span class="reserved">this</span>.loadUnchecked &amp;&amp; bVisible) {
        layer=<span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].getLayer(name);
        layer.visible=true;
        <span class="reserved">this</span>.setMapLayers();
        <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].setLayerVisibility( name, bVisible );
        <span class="reserved">this</span>.paintLayer(layer);
    } <span class="reserved">else</span> {
        <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].setLayerVisibility( name, bVisible );
    }
};

kaMap.<span class="reserved">prototype</span>.setLayerOpacity = <span class="reserved">function</span>( name, opacity ) {
    <span class="reserved">this</span>.aMaps[<span class="reserved">this</span>.currentMap].setLayerOpacity( name, opacity );
};

kaMap.<span class="reserved">prototype</span>.registerEventID = <span class="reserved">function</span>( eventID ) {
    <span class="reserved">return</span> <span class="reserved">this</span>.eventManager.registerEventID(eventID);
};

kaMap.<span class="reserved">prototype</span>.registerForEvent = <span class="reserved">function</span>( eventID, obj, func ) {
    <span class="reserved">return</span> <span class="reserved">this</span>.eventManager.registerForEvent(eventID, obj, func);
};

kaMap.<span class="reserved">prototype</span>.deregisterForEvent = <span class="reserved">function</span>( eventID, obj, func ) {
    <span class="reserved">return</span> <span class="reserved">this</span>.eventManager.deregisterForEvent(eventID, obj, func);
};

kaMap.<span class="reserved">prototype</span>.triggerEvent = <span class="reserved">function</span>( eventID <span class="comment">/*pass additional arguments*/</span> ) {
    <span class="reserved">return</span> <span class="reserved">this</span>.eventManager.triggerEvent.apply( <span class="reserved">this</span>.eventManager, arguments );
};

<span class="comment">/**
 * special helper function to parse an integer value safely in case
 * it is represented in IEEE format (scientific notation).
 */</span>
<span class="reserved">function</span> safeParseInt( val ) {
    <span class="reserved">return</span> Math.round(parseFloat(val));
};

<span class="comment">/******************************************************************************
 * _map
 *
 * internal class used to store map objects coming from the init script
 *
 * szName - string, the layer name (or group name, in this case ;))
 *
 * szTitle - string, the human-readable title of the map
 *
 * nCurrentScale - integer, the current scale as an index into aszScales;
 *
 * aszScales - array, an array of scale values for zooming.  The first scale is
 *             assumed to be the default scale of the map
 *
 * aszLayers - array, an array of layer names and statuses.  The array is indexed by
 *             the layer name and the value is true or false for the status.
 *
 *****************************************************************************/</span>
<span class="reserved">function</span> _map(o) {
    <span class="reserved">this</span>.aLayers = [];
    <span class="reserved">this</span>.aZoomTo = [];
    <span class="reserved">this</span>.kaMap = null;
    <span class="reserved">this</span>.name = (typeof(o.name) != <span class="literal">'undefined'</span>) ? o.name : <span class="literal">'noname'</span>;
    <span class="reserved">this</span>.title = (typeof(o.title) != <span class="literal">'undefined'</span>) ? o.title : <span class="literal">'no title'</span>;
    <span class="reserved">this</span>.aScales = (typeof(o.scales) != <span class="literal">'undefined'</span>) ? o.scales : [1];
    <span class="reserved">this</span>.currentScale = (typeof(o.currentScale) != <span class="literal">'undefined'</span>) ? parseFloat(o.currentScale) : 0;
    <span class="reserved">this</span>.units = (typeof(o.units) != <span class="literal">'undefined'</span>) ? o.units : 5;
    <span class="reserved">this</span>.resolution = (typeof(o.resolution) != <span class="literal">'undefined'</span>) ? o.resolution:72; <span class="comment">//used in scale calculations</span>
    <span class="reserved">this</span>.defaultExtents = (typeof(o.defaultExtents) != <span class="literal">'undefined'</span>) ? o.defaultExtents:[];
    <span class="reserved">this</span>.currentExtents = (typeof(o.currentExtents) != <span class="literal">'undefined'</span>) ? o.currentExtents:[];
    <span class="reserved">this</span>.maxExtents = (typeof(o.maxExtents) != <span class="literal">'undefined'</span>) ? o.maxExtents : [];
    <span class="reserved">this</span>.backgroundColor = (typeof(o.backgroundColor) != <span class="literal">'undefined'</span>) ? o.backgroundColor : <span class="literal">'#ffffff'</span>;
    <span class="comment">//to be used for versioning the map file ...</span>
    <span class="reserved">this</span>.version = (typeof(o.version) != <span class="literal">'undefined'</span>) ? o.version : <span class="literal">"0"</span>;
};

_map.<span class="reserved">prototype</span>.addLayer = <span class="reserved">function</span>( layer ) {
    layer._map = <span class="reserved">this</span>;
    layer.zIndex = <span class="reserved">this</span>.aLayers.length;
    <span class="reserved">this</span>.aLayers.push( layer );
};

<span class="comment">//added by cappu</span>
_map.<span class="reserved">prototype</span>.removeLayer = <span class="reserved">function</span>( l ) {
  var alayer=Array();
  <span class="reserved">for</span>(i=0,a=0;i&lt;<span class="reserved">this</span>.aLayers.length;i++) {
      <span class="reserved">if</span>(<span class="reserved">this</span>.aLayers[i]!=l) {
          alayer[a]=<span class="reserved">this</span>.aLayers[i];
          a++;
      }
  }
  <span class="reserved">this</span>.aLayers=alayer;
  <span class="reserved">return</span> true;
};

<span class="comment">//modified by cappu return only layer querable and visible for current scale</span>
_map.<span class="reserved">prototype</span>.getQueryableLayers = <span class="reserved">function</span>() {
    var r = [];
    var l = <span class="reserved">this</span>.getLayers();
    <span class="reserved">for</span>( var i=0; i&lt;l.length; i++) {
        <span class="reserved">if</span> (l[i].isQueryable()) {
            r.push(l[i]);
        }
    }
    <span class="reserved">return</span> r;
};

<span class="comment">//modified by cappu, return only layer visible and checked for current scale !!</span>
_map.<span class="reserved">prototype</span>.getLayers = <span class="reserved">function</span>() {
    var r = [];
    <span class="reserved">for</span>( var i=0; i&lt;<span class="reserved">this</span>.aLayers.length; i++) {
        <span class="reserved">if</span> (<span class="reserved">this</span>.aLayers[i].isVisible() &amp;&amp;
            (<span class="reserved">this</span>.aLayers[i].visible || <span class="reserved">this</span>.kaMap.loadUnchecked) ) {
            r.push(<span class="reserved">this</span>.aLayers[i]);
        }
    }
    <span class="reserved">return</span> r;
};

<span class="comment">//added by cappu replace old getQueryableLayers</span>
_map.<span class="reserved">prototype</span>.getAllQueryableLayers = <span class="reserved">function</span>() {
    var r = [];
    <span class="reserved">for</span>( var i=0; i&lt;<span class="reserved">this</span>.aLayers.length; i++) {
        <span class="reserved">if</span> (<span class="reserved">this</span>.aLayers[i].isQueryable()) {
            r.push(<span class=<