/*** ajax-client.js ***/ function checkPositiveInt(val){ var result = val.match(/^\d+$/); return (result != null && result != 0); } function createRequestObject() { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer"){ ro = new ActiveXObject("Microsoft.XMLHTTP"); }else{ ro = new XMLHttpRequest(); } return ro; } function handleResponse(myhttp, overlay) { if(myhttp.readyState == 4){ var response = myhttp.responseText; var update = new Array(); if(response.indexOf("?xml") == 1 ) { // not use the less-than bracket to avoid PHP problem // parse the XML var xmlresponse = myhttp.responseXML.documentElement; if ( xmlresponse.getElementsByTagName('searchresult') ) { var param = xmlresponse.getElementsByTagName('param'); var request=param[0].getAttribute("request"); var imgid=param[0].getAttribute("imgid"); var dispimg=param[0].getAttribute("dispimg"); var zoom=param[0].getAttribute("zoom"); var resultname=param[0].getAttribute("resultname"); var resultname_en=param[0].getAttribute("resultname_en"); var bookmark=parseInt(param[0].getAttribute("bookmark")); var hasmore=param[0].getAttribute("hasmore"); var forcezoom=param[0].getAttribute("forcezoom"); var search_key=param[0].getAttribute("search"); var pois = xmlresponse.getElementsByTagName('searchobject'); var servicesearch = param[0].getAttribute('service'); var servicelongdosearch = (typeof servicesearch == 'undefined' || servicesearch == '' || servicesearch == null || servicesearch == 'longdo'); var next_token = param[0].getAttribute('nexttoken'); var gg_html_attribute = servicesearch=='google' ? param[0].getAttribute('gghtmlattribute') : ''; var searchdiv = param[0].getAttribute('searchdiv'); var searchform = searchdiv == 'routing-result' ? 'routing' : 'location'; var prefixdiv = searchdiv == 'routing-result' ? 'routing-' : ''; var title_hilight_location = (mylang == 'th' ? 'คลิกเพื่อดูสถานที่นี้' : 'Click to hi-light this location'); var title_zoom_location = (mylang == 'th' ? 'คลิกเพื่อซูมไปยังสถานที่นี้' : 'Click to hi-light and ZOOM to this location'); var title_image_location = (mylang == 'th' ? 'คลิกเพื่อดูภาพของสถานที่นี้' : 'Click to view this location\'s images'); var title_event_location = (mylang == 'th' ? 'คลิกเพื่อดูเหตุการณ์ของสถานที่นี้' : 'Click to view this location\'s events'); var title_add_destination = (mylang == 'th' ? 'คลิกเพื่อเลือกเป็นจุดหมายการเดินทาง' : 'Click to add destination'); var title_view_road = (mylang == 'th' ? 'คลิกเพื่อดูสายทาง' : 'Click to hi-light this alley/road'); var title_see_more_result = (mylang == 'th' ? 'คลิกเพื่อดูผลลัพธ์การค้นหาเพิ่มเติม' : 'Click to see more search results'); var type_road_text = (mylang == "en" ? 'Alley/Road' : 'ถนน/ซอย'); var type_khet_text = (mylang == "en" ? 'Boundary of Administrator' : 'ขอบเขตการปกครอง'); var type_place_text = (mylang == "en" ? 'Place' : 'สถานที่'); var type_water_text = (mylang == "en" ? 'River/Canal' : 'แม่น้ำ/คลอง'); var type_layer_text = (mylang == "en" ? 'Layer' : 'เลเยอร์แผนที่'); //var type_panorama_text = (mylang == "en" ? 'Panorama' : 'ภาพพาโนรามา'); var txt_no_search_result = (mylang == "en" ? 'Sorry, no result found.' : 'ไม่พบผลลัพธ์การค้นหา'); var txt_enter_more_info = (mylang == "en" ? 'Please enter at least %d characters' : 'โปรดระบุอย่างน้อย %d ตัวอักษร'); var txt_search_other_services = (mylang == "en" ? 'Other search services' : 'ค้นหาจากบริการอื่น'); var txt_search_google_service = (mylang == "en" ? 'Search by' : 'ค้นหาจาก') + ' Google'; var txt_more = (mylang == "en" ? 'more' : 'เพิ่มเติม'); var location = getCenterLocation(); var google_search_link = 'https://www.google.com/maps/search/'+encodeURI(search_key)+'/@'+location.lat+','+location.lon; if(servicelongdosearch) servicesearch = 'longdo'; var search_by = mylang == 'en' ? ' by ' : 'จาก '; switch(servicesearch) { case 'osm': search_by += 'Open Street Map'; break; case 'google': search_by += 'Google'; break; case 'foursquare': search_by += 'Foursquare'; break; case 'longdo': search_by += 'Longdo Map'; break; default: search_by += servicesearch; break; } var points = xmlresponse.getElementsByTagName('pointobject'); // for showobject n_points = points ? points.length : 0; var n_pois=0; if (pois) n_pois = pois.length; if (request == "getpois") { poi_saved[zoom][imgid] = new Array(); poi_num[zoom][imgid] = n_pois; for (var i = 0 ; i < n_pois; i++) { var item = pois[i]; var id=item.getAttribute("id"); var name=item.getAttribute("name"); var lat=item.getAttribute("lat"); var mylong=item.getAttribute("long"); var type=item.getAttribute("type"); var status=item.getAttribute("status"); var showlevel=item.getAttribute("showlevel"); var name_en=item.getAttribute("name_en"); var contributor=item.getAttribute("contributor"); var imagefile=item.getAttribute("imagefile"); var iconlabel=item.getAttribute("iconlabel"); var iconlabel_en=item.getAttribute("iconlabel_en"); var iconlabel_en=item.getAttribute("iconlabel_en"); // save to poi array poi_saved[zoom][imgid][i] = new Array(); var usename = name; if (mylang == "en") { usename = name_en; if (name_en == "") { usename = "(Thai) " + name; } } var useiconlabel = iconlabel; if (mylang == "en") { useiconlabel = iconlabel_en; } poi_saved[zoom][imgid][i][0] = id; poi_saved[zoom][imgid][i][1] = usename; poi_saved[zoom][imgid][i][2] = lat; poi_saved[zoom][imgid][i][3] = mylong; poi_saved[zoom][imgid][i][4] = status; poi_saved[zoom][imgid][i][5] = contributor; poi_saved[zoom][imgid][i][6] = imagefile; poi_saved[zoom][imgid][i][7] = useiconlabel; //drawPOI(id,name,lat,mylong,status,zoom,dispimg,i); } drawPOIFromArray(zoom,imgid,dispimg); // hide the unused image var oldnum = poi_images_num[dispimg]; if (n_pois < oldnum ) { for (var i = n_pois ; i < oldnum ; i++) { //poi_images[dispimg][i].style.visibility = "hidden"; mymap.removeChild(poi_images[dispimg][i]); // remove and recreate seems to be faster! //poi_images_label[dispimg][i].style.visibility = "hidden"; //poi_images_label[dispimg][i].style.width = "0px"; //poi_images_label[dispimg][i].innerHTML = ""; mymap.removeChild(poi_images_label[dispimg][i]); } } poi_images_num[dispimg] = n_pois; } else if ( request == "searchresultsxml") { search_results_poi = new Array(); var shortdesc_limit = mylang == 'th' ? 60 : 70; var searchresultshtml = ''; var rs_table_id = prefixdiv+'search-result-list'+(servicesearch ? '-'+servicesearch : ''); //if (!servicelongdosearch && n_pois == 0) { //return; //} if(bookmark == 0) { if(!servicelongdosearch) { var changed_to_btn = n_pois == 0; var prefix_div = changed_to_btn ? '' : ''; var suffix_div = changed_to_btn ? '' : ''; var servicesearch_title = (changed_to_btn ? (mylang=='en' ? 'Search' : 'ค้นหา') : (mylang=='en' ? 'Search results' : 'ผลลัพธ์'))+search_by; searchresultshtml += prefix_div+'
'+suffix_div; } searchresultshtml += '"; // countlabel searchresultshtml += ' | ';
var zoom = mapZoom();
var zoomimg = "";
if(searchdiv != 'routing-result') {
zoomimg = (browser=='IE' && version<=6) ? "" : "";
}
var viewimg = "";
if(searchdiv != 'routing-result' && num_location_image>0) {
viewimg += (browser=='IE' && version<=6) ? "" : " ";
}
var eventimg = "";
if(searchdiv != 'routing-result' && num_location_event>0) {
eventimg += (browser=='IE' && version<=6) ? "" : " ";
}
var routeimg = false;
if(searchdiv == 'routing-result') {
routeimg = true;
}
if (type == "poi" || type == "osmp" || type == "foursquare-poi" || type == "google-poi" || type == "osm-poi") {
var name_padded = id;
var markpoijs = 'selectMapTab();';
var markpoiandzoomjs = 'selectMapTab();';
if(type == "poi" || type == "osmp") {
while (name_padded.length < 8) name_padded = "0" + name_padded;
if (n_pois == 1) {
markpoijs += 'markPOIandZoom(' + '\''+id+'\'' + ",'" + usename + "'," + lat +',' + mylong + ", 17 , '', 1);";
} else {
markpoijs += 'markPOI(' + '\''+id+'\'' + ",'" + usename + "'," + lat +',' + mylong + ", " + zoom + " , '');";
}
markpoiandzoomjs += 'markPOIandZoom(' + '\''+id+'\'' + ",'" + usename + "'," + lat +',' + mylong + "," + showlevel + ", '', 1);";
} else { //if(type == "foursquare-poi") {
if (n_pois == 1) {
markpoijs += 'markPOIandZoom(' + '\''+id+'\'' + ",'" + usename + "'," + lat +',' + mylong + ", 17 , '', 1);";
} else {
markpoijs += 'markOtherServiceSearchPOI(' + '\''+id+'\'' + ",'" + usename + "'," + lat +',' + mylong + ", " + zoom + ");";
}
markpoiandzoomjs += 'markOtherServiceSearchPOI(' + '\''+id+'\'' + ",'" + usename + "'," + lat +',' + mylong + "," + showlevel + ", 1);";
}
searchresultshtml += '' + usename_org + "" + (type == "osmp" ? " " : '');
if(zoomimg!="") {
search_result_icon += ' ' + zoomimg + "";
}
if(viewimg!="") {
search_result_icon += ' ' + viewimg + '';
}
if(eventimg!="") {
search_result_icon += ' ' + eventimg + '';
}
if(routeimg) {
search_result_icon += ' ';
}
} else if (type == "road") {
searchresultshtml += '' + usename_org + ""; // '+type_road_text+':
if(zoomimg!="") {
search_result_icon += ' ' + zoomimg + "";
}
if(routeimg) {
search_result_icon += ' ';
}
} else if (type == "khet") {
var js_func = '';
var zoom_js_func = '';
if(geocode) {
js_func = 'focusLongdoPOI('+lat+', '+mylong+', '+geocode+', false, \'IG\');';
zoom_js_func = 'focusLongdoPOI('+lat+', '+mylong+', '+geocode+', true, \'IG\');';
} else {
js_func = 'markPOI(-1 ,\'' + usename + '\',' + lat +',' + mylong + ', ' + zoom + ', \' '+usedesc+'\');'; zoom_js_func = 'markPOIandZoom(-1 ,\'' + usename + '\',' + lat +',' + mylong + ', ' + zoom + ', \' '+usedesc+'\');'; } if (lat && mylong) { searchresultshtml += '' + usename_org + ""; } else { // probably only KWANG here searchresultshtml += '' + usename_org + ""; } if(zoomimg!="") { search_result_icon += ' ' + zoomimg + ""; } if(routeimg) { search_result_icon += ' '; } } else if (type == "tag") { var tagname = name.replace(/^tag: /, ""); searchresultshtml += '' + name + ""; } else if (type == "geom") { var name_padded = id; while (name_padded.length < 8) name_padded = "0" + name_padded; searchresultshtml += '' + name + ""; if(viewimg!="") { search_result_icon += ' ' + viewimg + ''; } if(eventimg!="") { search_result_icon += ' ' + eventimg + ''; } if(routeimg) { search_result_icon += ' '; } } else if (type == "map" || type == "layer") { var name_padded = id; var ooi_prefix = (type == "map") ? 'M' : 'Y'; while (name_padded.length < 8) name_padded = "0" + name_padded; searchresultshtml += '' + name + ""; if(viewimg!="") { search_result_icon += ' ' + viewimg + ''; } if(eventimg!="") { search_result_icon += ' ' + eventimg + ''; } // } else if (type == "Panorama") { // var name_padded = id; // var ooi_prefix = 'P'; // while (name_padded.length < 8) name_padded = "0" + name_padded; // searchresultshtml += '' + name + ""; } else { var name_padded = id; var ds_type = ""; if (type == "water-line") { ooi_prefix = 'X'; ds_type = ooi_prefix + "ID"; } else if(type == "water-area") { ooi_prefix = 'W'; ds_type = ooi_prefix + "ID"; } else if(type == "building") { ooi_prefix = 'B'; ds_type = ooi_prefix + "ID"; } else if(type == "bus") { ooi_prefix = 'S'; ds_type = ooi_prefix + "ID"; } if (ds_type != '') { while (name_padded.length < 8) name_padded = "0" + name_padded; searchresultshtml += '' + name + ""; if(zoomimg!="") { search_result_icon += ' ' + zoomimg + ""; } } } if(search_result_icon != '') { search_result_icon = ' '; searchresultshtml += search_result_icon; } if(typeof(usedesc) != "undefined" && usedesc != "") { searchresultshtml += " "+ usedesc.substr(0,shortdesc_limit) + (usedesc.length > shortdesc_limit ? "..." : "") + ""; } searchresultshtml += " | |
";
var nextbookmark = bookmark + n_pois;
var more_result_func = 'setBookmark('+ nextbookmark + ', false, \''+searchform+'\'); doPreviousSearch(\''+search_key+'\', \''+searchform+'\');';
if(typeof(servicesearch) == 'string' && servicesearch == 'google')
more_result_func = 'setBookmark('+ nextbookmark + ', \''+servicesearch+'\', \''+searchform+'\'); searchOtherService(\''+search_key+'\', \'google\', \''+next_token+'\', \''+searchform+'\');';
else if(typeof(servicesearch) == 'string' && servicesearch == 'foursquare')
more_result_func = 'setBookmark('+ nextbookmark + ', \''+servicesearch+'\', \''+searchform+'\'); searchOtherService(\''+search_key+'\', \'foursquare\', \''+next_token+'\', \''+searchform+'\');';
else if(typeof(servicesearch) == 'string' && servicesearch == 'osm')
more_result_func = 'setBookmark('+ nextbookmark + ', \''+servicesearch+'\', \''+searchform+'\'); searchOtherService(\''+search_key+'\', \'osm\', \''+next_token+'\', \''+searchform+'\');';
searchresultshtml += ' '+txt_more+' ';
searchresultshtml += " | "+gg_html_attribute+" | "; } } else { // no result if(bookmark == 0) { var at_least_characters = 2; if(search_key.length >= at_least_characters) { if(servicesearch == 'longdo') { searchresultshtml += "|
"+txt_no_search_result+" | ||
"+txt_enter_more_info.replace('%d', at_least_characters)+" |