/
map2.tpl
2481 lines (2134 loc) · 86 KB
/
map2.tpl
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
{***************************************************************************
* You can find the license in the docs directory
*
* Unicode Reminder メモ
*
* TODO (old, may be outdated):
* - monitor and improve DB cleanup
* - review/rewrite mapsubmit_click
* - rewrite function names
* - use resultid in each map.php query
* - check if slave db connection works as expected (especially sys_repl_exclude / master connection)
* - save and load search config from different profiles that the user can modify
* - show labels inside the map
* - switch current options/view to search result page
*
* KNOWN PROBLEMS:
* - InfoWindow sizing problems, solved by workaround, see adjust_infowindow()
* - not all marker tootltips are displayed in Firefox, therefore disabled
* - strange GM zoom control jumping while panning or resizing the map
* - memory leak on MSIE, closing the map page then awfully slow due to garbage collection?
* - searchlist scrollpos is not reset on new search in Firefox
*
***************************************************************************}
{* OCSTYLE *}
{if $old_msie}
<script type="text/javascript">
{literal}<!--
function mapLoad()
{
document.getElementById('googlemap').innerHTML =
"<div style='position:relative; top:180px; left:10px'><p>{t escape=js}Your Internet Explorer is too old to display the map. Please upgrade at least to version 7, better 8.{/t}</p></div>";
}
-->{/literal}
</script>
{else}
<script type="text/javascript" src="resource2/{$opt.template.style}/js/wz_tooltip.js"></script>
<script type="text/javascript" src="resource2/{$opt.template.style}/js/tip_balloon.js"></script>
<script type="text/javascript" src="resource2/{$opt.template.style}/js/tip_centerwindow.js"></script>
{* <script type="text/javascript" src="resource2/{$opt.template.style}/js/debug.js"></script> *}
{literal}
<script type="text/javascript">
<!--
function trim(s)
{
while (s.substring(0, 1) == ' ')
s = s.substring(1, s.length);
while (s.substring(s.length-1, s.length) == ' ')
s = s.substring(0, s.length-1);
return s;
}
function getTimeDiff(dTime1, dTime2)
{
return ((dTime2-dTime1)/1000).toFixed(1);
}
/*=========================================================================
Initialization and Configuration
==========================================================================*/
var bFullscreen = {/literal}{$bFullscreen}{literal};
var nDefaultZoom = 13;
var mnInitLat = {/literal}{$nGMInitLat}{literal};
var mnInitLon = {/literal}{$nGMInitLon}{literal};
var mnInitZoom = {/literal}({$nGMInitZoom} < 0 ? nDefaultZoom : {$nGMInitZoom}){literal};
var mbInitCookiePos = {/literal}{$bGMInitCookiePos}{literal};
var msInitWaypoint = "{/literal}{$sGMInitWaypoint}{literal}";
var msInitType = 'roadmap';
var msInitSiderbarDisplay = 'none';
var msInitAttribSelection = false;
/* home coordinates */
var mnUserLat = {/literal}{$nUserLat}{literal};
var mnUserLon = {/literal}{$nUserLon}{literal};
var msSearchHint = "{/literal}{t escape=js}city, cachename or waypoint{/t}{literal}";
var mbResetSearchTextOnFocus = false;
var msInitCookieLastPosName = 'ocgmlastpos';
var msInitCookieConfigName = 'ocgmconfig';
var msInitCookieFilterName = 'ocgmfilter';
if (!navigator.cookieEnabled)
{
msInitCookieLastPosName = '';
msInitCookieConfigName = '';
msInitCookieFilterName = '';
}
var moGeocoder = new google.maps.Geocoder();
var moSearchList = null;
var maSearchListCoords = new Array();
var moPermalinkBox = null;
var moMapSearch = null;
var moMap = null;
var moInfoWindow = null;
var moMarkerList = new Array();
var msPopupMarkerWP = '';
var mhInfoWindowHackTimer = null;
var mhInfoWindowHackTries = 0;
var moWpInfoWindow = null;
var maWpWaypoints;
var moWaypointList = new Array();
var mhPictureTimer = null;
var mnMapWidth = 770;
var mnMapHeight = 600;
// id of search.php result
var msURLSearchPHP = 'search.php';
var msURLMapPHP = 'map2.php';
var mnResultId = 0;
var mbDataDownloadHaveSecondChance = false;
var mbDataDownloadStartTime;
var moDataLoadTimer = null;
var copyrightDiv = null;
var mnMaxDownloadCount = 500;
var mbDownloadEnabled = false;
var bFilterChanged = false;
var sFilterSaveText;
var oFilterSaveColor;
var bAllAttribs = true;
{/literal}
var nCacheTypeCount = {count array=$aCacheType};
var nCacheSizeCount = {count array=$aCacheSize};
var nMaxAttributeId = {$maxAttributeId};
{literal}
function cookieLoad()
{
if (msInitCookieConfigName == '')
return;
var sCookieContent = document.cookie.split(";");
for (var nIndex = 0; nIndex < sCookieContent.length; nIndex++)
{
var sCookieValue = trim(sCookieContent[nIndex]).split("=");
if (sCookieValue[0] == msInitCookieLastPosName)
{
if (mbInitCookiePos == 1)
{
var sValues = sCookieValue[1].split(":");
mnInitZoom = parseInt(sValues[0]);
mnInitLon = parseFloat(sValues[1]);
mnInitLat = parseFloat(sValues[2]);
}
}
else if (sCookieValue[0] == msInitCookieConfigName)
{
var sValues = sCookieValue[1].split(":");
msInitType = sValues[0];
if (sValues.length > 1)
msInitSiderbarDisplay = sValues[1];
if (sValues.length > 2)
msInitAttribSelection = (sValues[2] > 0);
}
else if (sCookieValue[0] == msInitCookieFilterName)
eval_filtercookies(sCookieValue[1].split('/'));
}
}
function eval_filtercookies(aValues)
{
for (var iValue=0; iValue<aValues.length; iValue++)
{
fs = aValues[iValue].split(':');
if (fs[0] == 'types')
{
ftypes = ',' + fs[1] + ',';
{/literal}
{foreach from=$aCacheType item=cachetype}
document.getElementById('cachetype' + {$cachetype.id}).checked = ftypes.indexOf(',' + {$cachetype.id} + ',') >= 0;
{/foreach}
{literal}
cachetype_all_set();
}
else if (fs[0] == 'sizes')
{
fsizes = ',' + fs[1] + ',';
{/literal}
{foreach from=$aCacheSize item=cachesize}
document.getElementById('cachesize' + {$cachesize.id}).checked = fsizes.indexOf(',' + {$cachesize.id} + ',') >= 0;
{/foreach}
{literal}
cachesize_all_set();
}
else if (fs[0] == 'hide')
{
document.getElementById('f_userowner').checked = fs[1].indexOf('0') >= 0;
document.getElementById('f_userfound').checked = fs[1].indexOf('F') >= 0;
document.getElementById('f_ignored').checked = fs[1].indexOf('I') >= 0;
document.getElementById('f_inactive').checked = fs[1].indexOf('D') >= 0;
document.getElementById('f_otherPlatforms').checked = fs[1].indexOf('M') >= 0;
}
else if (fs[0] == 'rated')
{
fr = fs[1].split(',');
document.getElementById('terrainmin').value = fr[0];
document.getElementById('terrainmax').value = fr[1];
document.getElementById('difficultymin').value = fr[2];
document.getElementById('difficultymax').value = fr[3];
document.getElementById('recommendationmin').value = fr[4];
}
else if (fs[0] == 'attr')
{
fa = ',' + fs[1] + ',';
{/literal}{strip}
{foreach from=$aAttributes item=attribGroupItem}
{foreach from=$attribGroupItem.attr item=attribItem}
eva(fa,{$attribItem.id},'{$attribItem.icon}');
{/foreach}
{/foreach}
{/strip}{literal}
}
}
}
function eva(fa,id,icon)
{
if (fa.indexOf(',' + id + '-1,') >= 0)
{
document.getElementById('attribute' + id).value = 1;
document.getElementById('imgattribute' + id).src = 'resource2/{/literal}{$opt.template.style}{literal}/images/attributes/' + icon + '.png';
}
else if (fa.indexOf(',' + id + '-2,') >= 0)
{
document.getElementById('attribute' + id).value = 2;
document.getElementById('imgattribute' + id).src = 'resource2/{/literal}{$opt.template.style}{literal}/images/attributes/' + icon + '-no.png';
}
}
function cookieSave()
{
if (msInitCookieConfigName == '')
return;
var dCookieExp = new Date(2049, 12, 31);
// map type and sidebar state
document.cookie = msInitCookieConfigName + "=" + moMap.getMapTypeId() + ":" + msInitSiderbarDisplay + ":" + (bAllAttribs ? "1" : "0") + ";expires=" + dCookieExp.toUTCString();
// map position and zoom level
var oCenterPos = moMap.getCenter();
document.cookie = msInitCookieLastPosName + "=" + moMap.getZoom() + ":" + oCenterPos.lng() + ":" + oCenterPos.lat() + ";expires=" + dCookieExp.toUTCString();
// filter settings
var sFilter = '';
if (!document.getElementById('all_cachetypes').checked)
{
var sCtFilter = '';
{/literal}
{foreach from=$aCacheType item=cachetype}
if (document.getElementById('cachetype' + {$cachetype.id}).checked) sCtFilter += ',' + {$cachetype.id};
{/foreach}
{literal}
sFilter += '/types:' + sCtFilter.substring(1);
}
if (!document.getElementById('all_cachesizes').checked)
{
var sCsFilter = '';
{/literal}
{foreach from=$aCacheSize item=cachesize}
if (document.getElementById('cachesize' + {$cachesize.id}).checked) sCsFilter += ',' + {$cachesize.id};
{/foreach}
{literal}
sFilter += '/sizes:' + sCsFilter.substring(1);
}
sFilter += '/hide:';
if (document.getElementById('f_userowner').checked) sFilter += 'O';
if (document.getElementById('f_userfound').checked) sFilter += 'F';
if (document.getElementById('f_ignored').checked) sFilter += 'I';
if (document.getElementById('f_inactive').checked) sFilter += 'D';
if (document.getElementById('f_otherPlatforms').checked) sFilter += 'M';
sFilter += '/rated:' +
document.getElementById('terrainmin').value + ',' +
document.getElementById('terrainmax').value + ',' +
document.getElementById('difficultymin').value + ',' +
document.getElementById('difficultymax').value + ',' +
document.getElementById('recommendationmin').value;
var sAttrFilter = '';
for (nAttribId=1; nAttribId<=nMaxAttributeId; nAttribId++)
{
var ao = document.getElementById('attribute' + nAttribId);
if (ao)
if (ao.value != 3)
sAttrFilter += ',' + nAttribId + '-' + ao.value;
}
if (sAttrFilter != "")
sFilter += '/attr:' + sAttrFilter.substring(1);
document.cookie = msInitCookieFilterName + "=" + sFilter.substring(1);
// "expires" not set, so that the cookie will expire when browser is closed,
// because the user can easily forget or overlook that filtering is acive.
}
function mapLoad()
{
cookieLoad();
showcoords(mnInitLat, mnInitLon);
if (!msInitAttribSelection)
toggle_attribselection(false);
if (bFullscreen && msInitSiderbarDisplay == "block")
toggle_sidebar(false);
var maptypes = ['OSM', 'MQ', 'OCM',
google.maps.MapTypeId.ROADMAP, google.maps.MapTypeId.SATELLITE,
google.maps.MapTypeId.HYBRID, google.maps.MapTypeId.TERRAIN ];
var initType = google.maps.MapTypeId.ROADMAP;
for (var i=0; i<maptypes.length; i++)
if (msInitType == maptypes[i])
initType = msInitType;
var myOptions = {
zoom: mnInitZoom,
center: new google.maps.LatLng(mnInitLat, mnInitLon),
mapTypeId: initType,
backgroundColor: "#d0dccc",
mapTypeControl: true,
mapTypeControlOptions: { mapTypeIds: maptypes },
panControl: false,
zoomControl: true,
scaleControl: true,
streetViewControl: false,
overviewMapControl: true, {/literal}
{if $opt_overview==1}
overviewMapControlOptions: {literal}{ opened: true }{/literal},
{/if} {literal}
styles:
[ { featureType:"poi.business", elementType:"labels", stylers: [{ visibility:"off" }] },
{ featureType:"poi.government", elementType:"labels", stylers: [{ visibility:"off" }] } ]
// poi types: https://developers.google.com/maps/documentation/javascript/reference#MapTypeStyleFeatureType
};
moMap = new google.maps.Map(document.getElementById("googlemap"), myOptions);
moMap.enableKeyDragZoom();
setMapType("OSM", "OpenStreetMap", "http://tile.openstreetmap.org/", 18);
setMapType("MQ"," MapQuest", "http://otile1.mqcdn.com/tiles/1.0.0/osm/", 19);
setMapType("OCM", "OpenCycleMap", "http://tile.opencyclemap.org/cycle/", 18);
moInfoWindow = new google.maps.InfoWindow();
moWpInfoWindow = new google.maps.InfoWindow();
moSearchList = document.getElementById('mapselectlist');
moMapSearch = document.getElementById('mapsearch');
moPermalinkBox = document.getElementById('permalink_box');
// Create div for showing copyrights.
copyrightDiv = document.createElement("div");
copyrightDiv.id = "map-copyright";
copyrightDiv.style.fontSize = "11px";
copyrightDiv.style.fontFamily = "Arial, sans-serif";
copyrightDiv.style.padding = "0 2px 0 2px";
copyrightDiv.style.whiteSpace = "nowrap";
copyrightDiv.style.background = "#FFFFFF";
copyrightDiv.style.opacity = "0.7";
//copyrightDiv.class = "mapattribution";
moMap.controls[google.maps.ControlPosition.BOTTOM_RIGHT].push(copyrightDiv);
google.maps.event.addListener(moMap, "dragstart", function(){map_movestart()});
google.maps.event.addListener(moMap, "dragend", function(){map_moveend()});
google.maps.event.addListener(moMap, "bounds_changed", function(){map_moveend()});
// google.maps.event.addListener(moMap, "zoom_changed", function(){map_moveend()});
// is included in bounds_changed
google.maps.event.addListener(moMap, "maptypeid_changed", function(){map_maptypechanged()});
google.maps.event.addListener(moMap, "mousemove", function(event){map_mousemove(event)});
google.maps.event.addListener(moMap, "click", function(){map_clicked()});
// google.maps.event.addListener(moMap, "rightclick", function(){toggle_sidebar(false)});
if (msInitWaypoint != "")
show_cachepopup_wp(msInitWaypoint, true);
if (moMapSearch)
moMapSearch.value = msSearchHint;
updateCopyrights();
cookieSave();
queue_dataload(500);
}
function setMapType(shortname,longname,url,max_zoom)
{
moMap.mapTypes.set(shortname, new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
return url + zoom + "/" + coord.x + "/" + coord.y + ".png";
},
tileSize: new google.maps.Size(256, 256),
name: shortname,
alt: longname,
maxZoom: max_zoom
}));
}
function mapUnload()
{
cookieSave();
}
/*=========================================================================
GM hooks and custom controls
=========================================================================*/
function map_movestart()
{
window.clearTimeout(moDataLoadTimer);
moDataLoadTimer = null;
}
function map_moveend()
{
cookieSave();
queue_dataload(400);
}
function map_maptypechanged()
{
updateCopyrights();
cookieSave();
}
function map_mousemove(event)
{
showcoords(event.latLng.lat(), event.latLng.lng());
}
function map_clicked()
{
if (bFullscreen)
{
if (document.getElementById("sidebar").style.display != 'none')
toggle_sidebar();
}
else
dataload_on_filterchange();
mapselectlist_hide(); // firefox needs this
moWpInfoWindow.close();
close_infowindow(false);
permalinkbox_hide();
}
function updateCopyrights()
{
if (copyrightDiv == null )
return;
var newMapType = moMap.getMapTypeId();
if (newMapType == "OSM" || newMapType == "MQ" || newMapType == "OCM")
{
{/literal}
if (newMapType == "OCM")
copyrightDiv.innerHTML = '{t escape=js}Map data © <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> and <a href="http://www.thunderforest.com/opencyclemap/" target="_blank">OpenCycleMap</a> contributors{/t}';
else
copyrightDiv.innerHTML = '{t escape=js}Map data © <a href="http://www.openstreetmap.org/copyright" target="_blank">OpenStreetMap</a> contributors{/t}';
if (newMapType == "MQ")
copyrightDiv.innerHTML += ', ' + '{t escape=js}tiles provided by <a href="http://www.mapquest.com/" target="_blank">MapQuest</a>{/t}' + ' <img src="http://developer.mapquest.com/content/osm/mq_logo.png">';
{literal}
}
else
copyrightDiv.innerHTML = "";
}
/*=========================================================================
XML cache data download
=========================================================================*/
function ajaxLoad( url, callback, postData )
{
var http_request = false;
if (window.XMLHttpRequest)
{ // Mozilla, Safari, ...
http_request = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{ // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request)
{
alert('Giving up: Cannot create an XMLHTTP instance');
return false;
}
http_request.onreadystatechange = function() {
if (http_request.readyState == 4)
{
if (http_request.status == 200)
{
callback(http_request.responseText, http_request.status);
}
else if (http_request.status != 0) // avoid dummy messages when aborting transfer
{
alert('Request Failed: ' + http_request.status);
}
}
};
if (postData)
{ // POST
http_request.open('POST', url, true);
http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
http_request.send(postData);
}
else
{
http_request.open('GET', url, true);
http_request.send(null);
}
}
/**
* This functions wraps XMLHttpRequest open/send function.
* It lets you specify a URL and will call the callback if
* it gets a status code of 200.
* @param {String} url The URL to retrieve
* @param {Function} callback The function to call once retrieved.
*/
function downloadUrl( url, callback, postbody )
{
ajaxLoad( url, callback, postbody );
//GDownloadUrl( url, callback );
}
function downloadUrl2(url, callback, postbody) {
ajaxLoad( url, callback, postbody );
//GDownloadUrl( url, callback, postbody );
}
/**
* Parses the given XML string and returns the parsed document in a
* DOM data structure. This function will return an empty DOM node if
* XML parsing is not supported in this browser.
* @param {string} str XML string.
* @return {Element|Document} DOM.
*/
function xmlParse( str )
{
if (typeof ActiveXObject != 'undefined' && typeof GetObject != 'undefined')
{
var doc = new ActiveXObject('Microsoft.XMLDOM');
doc.loadXML(str);
return doc;
}
if (typeof DOMParser != 'undefined')
{
return (new DOMParser()).parseFromString(str, 'text/xml');
}
return createElement('div', null);
}
function queue_dataload(nMs)
{
if (moDataLoadTimer != null)
window.clearTimeout(moDataLoadTimer);
moDataLoadTimer = window.setTimeout('data_load()', nMs);
}
function dataload_on_filterchange()
{
if (bFilterChanged)
queue_dataload(100);
}
function data_load()
{
if (bFilterChanged)
{
close_infowindow(true);
clear_waypoints();
}
bResetFilterHeading = bFilterChanged;
bFilterChanged = false;
window.clearTimeout(moDataLoadTimer);
moDataLoadTimer = null;
mbDataDownloadStartTime = new Date();
if (mnResultId != 0)
{
tmd_hide();
mbDataDownloadHaveSecondChance = true;
ajaxLoad(msURLMapPHP, data_mapreceive, get_mapfilter_params());
}
else
{
gpx_download_enabled(false);
ajaxLoad(msURLSearchPHP, data_searchreceive, get_searchfilter_params('map2', true, false));
}
}
function data_mapreceive(data, responseCode)
{
if (bResetFilterHeading)
reset_filter_heading();
if (responseCode != 200)
{
var sMessage = '{t escape=js}Error: Unable to download the search result (HTTP error code %1){/t}';
sMessage = sMessage.replace(/%1/, responseCode);
alert(sMessage);
return;
}
var oXML = xmlParse(data);
if (oXML.documentElement.getAttribute("available") +0 == 0)
{
if (mbDataDownloadHaveSecondChance == true)
{
ajaxLoad(msURLSearchPHP, data_searchreceive, get_searchfilter_params('map2', true, false));
}
else
{
// alert('{t escape=js}Error: Unable to download the search result. The data was not available on the server.{/t}');
error_no_data(true);
}
return;
}
else
error_no_data(false);
var record_count = oXML.documentElement.getAttribute("count");
gpx_download_enabled((record_count<=mnMaxDownloadCount) && (record_count>0));
/* nee too many markers -> clear all and display message */
if (oXML.documentElement.getAttribute("maxrecordreached") == 1)
{
data_clear();
tmd_show(record_count);
return;
}
/* compute set of markers to keep */
var wpset = {};
var oCachesList = oXML.documentElement.getElementsByTagName("c");
for (var nIndex=0; nIndex<oCachesList.length; nIndex++)
{
var sCacheData = oCachesList[nIndex].getAttribute("d");
var sWaypoint = sCacheData.substring(0,sCacheData.indexOf('/'));
wpset[sWaypoint] = true;
}
/* delete unneeded markers */
var alreadythere = data_clear_except( wpset );
/* add new markers (skip existing) */
for (var nIndex=0; nIndex<oCachesList.length; nIndex++)
{
var aCacheData = oCachesList[nIndex].getAttribute("d").split('/');
var sWaypoint = aCacheData[0];
if (!(sWaypoint in alreadythere))
{
var nLon = aCacheData[1];
var nLat = aCacheData[2];
var nType = aCacheData[3];
var nFlags = aCacheData[4];
addCacheToMap(sWaypoint, nLon, nLat, nType, nFlags,
oCachesList[nIndex].getAttribute("n"),
sWaypoint == msPopupMarkerWP ? 999999 : nIndex);
}
}
document.getElementById('statCachesCount').innerHTML = oCachesList.length;
document.getElementById('statLoadTime').innerHTML = getTimeDiff(mbDataDownloadStartTime, new Date());
}
// receives the result of map2.php (if result is not available, search.php has to be invoked)
function data_searchreceive(data, responseCode)
{
// TODO: check
if (responseCode == 200)
{
// TODO: make sure that data must is a numeric ID
mnResultId = data;
}
// continue with data download
tmd_hide();
mbDataDownloadHaveSecondChance = false;
ajaxLoad(msURLMapPHP, data_mapreceive, get_mapfilter_params());
}
function error_no_data(errorstate)
{
var msgo = document.getElementById('mapstat_caches');
msgo.style.color = (errorstate ? 'red' : 'black');
msgo.style.fontWeight = (errorstate ? 'bold' : 'normal');
}
function xmlentities(str)
{
str = str.replace(/&/, '&');
str = str.replace(/</, '<');
str = str.replace(/>/, '>');
str = str.replace(/"/, '"');
// hack for phpDesigner syntax HL problem: "
return str;
}
/*=========================================================================
Markers
=========================================================================*/
function NewCacheMarker(nLat, nLon, sWaypoint, nType, nFlags, sName, nZindex)
{
var image, anchor;
{/literal}
{if $opt_cacheicons == 1}
image = 'resource2/ocstyle/images/map/caches1/24x24-';
anchor = new google.maps.Point(12,12);
{else}
image = 'resource2/ocstyle/images/map/caches2/';
anchor = new google.maps.Point(13,24);
{/if}
{literal}
if (nFlags & 1) image += 'owned';
else if (nFlags & 2) image += 'found';
else if (nFlags & 4) image += 'notfound';
else image += 'cachetype-' + nType;
if (nFlags & 8) image += '-inactive';
else if (nFlags & 16) image += '-oconly';
var mi = new google.maps.MarkerImage(image + '.png');
mi.anchor = anchor;
marker = new google.maps.Marker(
{ position: new google.maps.LatLng(nLat, nLon),
map: moMap,
title: sName,
icon: mi,
zIndex: nZindex });
marker.waypoint = sWaypoint;
return marker;
}
function addCacheToMap(sWaypoint, nLon, nLat, nType, nFlags, sName, nZindex)
{
var oMarker = NewCacheMarker(nLat, nLon, sWaypoint, nType, nFlags, sName, nZindex);
google.maps.event.addListener(oMarker, "click", function(){show_cachepopup_wp(sWaypoint,false);});
moMarkerList[moMarkerList.length] = oMarker;
}
function data_clear()
{
document.getElementById('statCachesCount').innerHTML = '0';
for (var nIndex=0; nIndex<moMarkerList.length; nIndex++)
moMarkerList[nIndex].setMap(null);
moMarkerList = new Array();
clear_waypoints();
}
/* delete all markers, except those specified in "wpset". return the set of remaining markers */
function data_clear_except(wpset)
{
var existing = {};
document.getElementById('statCachesCount').innerHTML = '0';
var newList = new Array();
for (var nIndex=0; nIndex<moMarkerList.length; nIndex++)
{
var oMarker = moMarkerList[nIndex];
var wp = oMarker.waypoint;
if (wp != msPopupMarkerWP && !(wp in wpset))
{
oMarker.setMap(null);
}
else
{
existing[wp] = true;
newList[newList.length] = oMarker;
}
}
moMarkerList = newList;
return existing;
}
/*=========================================================================
InfoWindows (popups)
=========================================================================*/
function show_cachepopup_wp(sWaypoint, bAllowZoomChange)
{
show_cachepopup_url(msURLMapPHP + "?mode=wpsearch&wp=" + sWaypoint, sWaypoint, bAllowZoomChange);
}
function show_cachepopup_latlon(nLat, nLon, bAllowZoomChange)
{
show_cachepopup_url(msURLMapPHP + "?mode=locate&lat=" + nLat + "&lon=" + nLon, "", bAllowZoomChange);
}
{/literal}
{* In some browers and zoom levels (especially Chrome and MSIE at small zoom), a wrong
* size is calculated by GM for some infowindow contents. If the caluclated size is too
* small, the containing div will show a scrollbar:
*
* http://stackoverflow.com/questions/1554893/google-maps-api-v3-infowindow-not-sizing-correctly
*
* The only solution working under all conditions seems to be changing the container
* div's properties - either letting it overflow or increasing it's size size.
* This will neither affect the size of our 'mapinfowindow' div nor of the infowindow, but
* only give our content more space.
*
* The 'overflow solution' also prevents scrollbars if the browser zoom is changed with
* open infowindow. It also may work better with dynamic window content (not tested yet).
* It has the disatvantage that text will temporarily flow out at the bottom of the
* window then zoom is increased with open infowindow in Firefox. Also, it will flow out
* at the *right* with Firefox if the contained data is formatted with
* max-width + white-space:nobr (which wee currently need not to do).
*
* Also, there is another MSIE issue regading a second inner pair of scrollbars. We get
* rid of them by settings overflow:hidden on mapinfowindow (see style_screen.css).
*}
{literal}
function adjust_infowindow()
{
if (mhInfoWindowHackTries > 0)
try
{
var iw_frame = document.getElementById('mapinfowindow').parentNode;
iw_frame.parentNode.style.overflow = "visible";
iw_frame.style.overflow = "visible";
// BOTH divs overflow must be set so that it works right in all browsers!
mhInfoWindowHackTries = 0;
{/literal}
{* old code version, which did it by increasing the outer container div's size:
var iw_frame = document.getElementById('mapinfowindow').parentNode.parentNode;
var iw_width = parseInt(iw_frame.style.width.substr(0, iw_frame.style.width.indexOf('px')));
var iw_height = parseInt(iw_frame.style.height.substr(0, iw_frame.style.height.indexOf('px')));
if (iw_width > 0 && iw_height > 0)
{
mhInfoWindowHackTries = 0;
// alert("Before: " + iw_frame.style.width + " / " + iw_frame.style.height);
iw_frame.style.width = String(iw_width + 2) + "px";
// making it too wide would let additional wp text flow into the margin at MSIE
iw_frame.style.height = String(iw_height + 10) + "px";
// alert("After: " + iw_frame.style.width + " / " + iw_frame.style.height);
}
else
mhInfoWindowHackTries -= 1;
*} {literal}
}
catch (e)
{
// we were too fast and will try again
mhInfoWindowHackTries -= 1;
}
if (mhInfoWindowHackTries <= 0)
clearInterval(mhInfoWindowHackTimer);
}
function hack_infowindow()
{
mhInfoWindowHackTries = 150;
mhInfoWindowHackTimer = window.setInterval("adjust_infowindow()",10);
}
function show_infowindow(oCoords, sText)
{
close_infowindow(true);
clear_waypoints();
moInfoWindow = new google.maps.InfoWindow({ position: oCoords, content: sText });
moInfoWindow.open( moMap, null, true );
wid = document.getElementById('mapinfowindow');
hack_infowindow();
}
function init_waypoint_markers(aWaypoints)
{
maWpWaypoints = aWaypoints;
for (var nWp=0; nWp<aWaypoints.length; nWp++)
{
var imgparams = get_wp_imgparams(aWaypoints[nWp]);
var image = imgparams[0];
var anchorx = imgparams[3];
var anchory = imgparams[4];
var latitude = aWaypoints[nWp].getAttribute('latitude');
var longitude = aWaypoints[nWp].getAttribute('longitude');
var mi = new google.maps.MarkerImage(image);
mi.anchor = new google.maps.Point(anchorx, anchory);
var coords = new google.maps.LatLng(latitude, longitude);
marker = new google.maps.Marker(
{ position: coords,
map: moMap,
icon: mi,
zIndex: 99998 });
{/literal}
{*
* We cannot use the show_infowindow() loop variables in the event handler
* function - they would all use variable values after end of loop, i.e. sho
* all the last waypoint's infowindow. To solve this, the handler finds the
* clicked waypoint's data by the coordinates. GM passes the marker's
* coordinates here (with rounding differences), but to be sure we just look
* for the nearest marker.
*}
{literal}
google.maps.event.addListener(marker, "click",
function (event)
{
var distance = 360;
var reflat = event.latLng.lat();
var reflon = event.latLng.lng();
var nearestwp;
for (nWp=0; nWp<maWpWaypoints.length; nWp++)
{
var lat = maWpWaypoints[nWp].getAttribute('latitude');
var lon = maWpWaypoints[nWp].getAttribute('longitude');
var d = Math.sqrt((lat-reflat) * (lat-reflat) + (lon-reflon) * (lon-reflon));
if (d < distance)
{
nearestwp = nWp;
nearestlon = lon;
nearestlat = lat;
distance = d;
}
}
// if a picture is shown, it is from the same cache, so we keep it open
// by the 'false' param here
close_infowindow(false);
moWpInfoWindow.close();
var imgparams = get_wp_imgparams(aWaypoints[nearestwp]);
var image = aWaypoints[nearestwp].getAttribute('image');
var imagewidth = aWaypoints[nearestwp].getAttribute('imagewidth');
var imageheight = aWaypoints[nearestwp].getAttribute('imageheight');
var wptype = maWpWaypoints[nearestwp].getAttribute('typeid');
var typename = maWpWaypoints[nearestwp].getAttribute('typename');
var preposition = maWpWaypoints[nearestwp].getAttribute('typepreposition');
var description = maWpWaypoints[nearestwp].getAttribute('description');
var maxwidth;
if (description.length < 512)
maxwidth = "320px";
else
maxwidth = "480px";