var isBlueTheme=true;var themecolor="#0055b8";var bmmodeline="#0055b8";var v_slide_d="v-slide-d-0623.png";var v_slide="v-slide-0623.png";var stop_marker="busstop_marker_purple.png";var shareauto=0;
var mouseonfeature = null;
var acode=1;
var lsearchday="";
var rsortmode=1;
var sn=0;
var sys_nearby=0;
var sys_nearby_radius=250;
var lastlat=0.0;
var lastlon=0.0;
var bmlat=0.0;
var bmlon=0.0;
var sysseq=0;
var errorcnt=0;
var v_ustatus="";
var hadjust=0;
var ppresult='';
var ppresult2='';
var ppresult3='';
var kmblink='';
var nwfblink='';
var map;
var view;
var layerLines;
var trafficSource = new ol.source.Vector({});
var ptSource = new ol.source.Vector({});
var vectorSource = new ol.source.Vector({});
var stopSource = new ol.source.Vector({});
var circleSource = new ol.source.Vector({});
var walkSource = new ol.source.Vector({style: styleFunction});
var lineSource = new ol.source.Vector({});
var popup;
var markerpopup;
var mappopupelement;
var hotspotpopup;
var hotspotpopupelement;
var popupposition=null;
var startname="";
var startlat=0.0;
var startlon=0.0;
var endname="";
var endlat=0.0;
var endlon=0.0;
var lastname="";
var lastlat=0.0;
var lastlon=0.0;
var markers = new Array(1000);
var markercodes = new Array(1000);
var markerlat = new Array(1000);
var markercount=0;
var stopNearbyMarkers = new Array(1000); // nearby markers for route detail's selected stop
var stopNearbyMarkercodes = new Array(1000);
var stopNearbyMarkerlat = new Array(1000);
var stopNearbyMarkercount=0;
var circle = new ol.geom.Circle(ol.proj.transform([114.173, 22.3], 'EPSG:4326', 'EPSG:3857'), 1000);
var CircleFeature = new ol.Feature(circle);
var circleC = new ol.geom.Point(ol.proj.transform([114.173, 22.3], 'EPSG:4326', 'EPSG:3857'));
var CircleFeatureC = new ol.Feature(circleC);
var CircleLayer
var linecount = 0;
var maxlinecount = 0;
var mapLayerPtStr = "";
var mapLayerPtLat = 0.0;
var mapLayerPtLon = 0.0;
var mapLayerRadius = 0.0;
var layerCenterMap2 = "";
var layermark1 = [0,0,0,0,0,0,0,0,0,0];
var layermark2 = [0,0,0,0,0,0,0,0,0,0];
var layerpt = [1,2,81,7,4,5,80];
var bookmarkmode=0;
var bookmarkno=0;
var skipmapclick=0;
var sys_audio=0;
var lastP2PResultListScrollY = 0;
var lastP2PResultListPopUpScrollY = 0;
var lastP2PResultListViewMode = 0; //0=normal list, 1=popup list
var autoRouteSearch_info = "";
var autoRouteSearch_rdv = "";
var autoRouteSearch_r = "";
var autoRouteSearch_d = "";
var autoRouteSearch_v = "";
var autoRouteSearch_bound = "";
var autoRouteSearch_stopid = "";
var hihi = "hihi 2";
var recaptcha_rendered = false;
var recaptchaId = "";
var recaptcha_type = "";
var recaptcha_value = "";
var recaptcha_check_called = false;
var recaptcha_key = "";
function gosearchclick(){
lastP2PResultListScrollY = 0;
lastP2PResultListPopUpScrollY = 0;
lastP2PResultListViewMode = 0; //0=normal list, 1=popup list
lsearchday=document.getElementById('search_day').innerHTML;
ppsearch_p3(document.ppsearch.slat.value,document.ppsearch.slon.value,document.ppsearch.elat.value,document.ppsearch.elon.value ,document.getElementById('walkingspeed').value,document.getElementById('leg').value, getselectloc(), getselectdate());
goresize();
}
function initmap(){
}
var trafficInfoObject = {
init : true,
drawjourney :false,
drawspeedmap : false,
drawcctv : false,
drawsmp : false,
timer : null,
journey : [],
journeydata : [],
speedmap : [],
cctv : [],
smp : [],
cctvCallbackCloseMarkers : false,
drawSpeedMap : function drawSpeedMap(){ godrawspeedmap(); },
drawCCTVMarker : function drawCCTVMarker(){ godrawcctvmarker(); },
drawJourneyMarker : function drawJourneyMarker(){ godrawjourneymarker(); },
drawSMPMarker : function drawSMPMarker(){ godrawsmpmarker();}
}
var styleFunction = function(feature) {
var geometry = feature.getGeometry();
var styles = [
// linestring
new ol.style.Style({
stroke: new ol.style.Stroke({
color: '#ffcc33',
width: 2
})
})
];
geometry.forEachSegment(function(start, end) {
var dx = end[0] - start[0];
var dy = end[1] - start[1];
var rotation = Math.atan2(dy, dx);
// arrows
styles.push(new ol.style.Style({
geometry: new ol.geom.Point(end),
image: new ol.style.Icon({
src: 'icons/barrow.png',
anchor: [0.75, 0.5],
rotateWithView: true,
rotation: -rotation
})
}));
});
return styles;
};
function setdiv(dname,str){
document.getElementById(dname).innerHTML=str;
}
function initsystem(){
}
function sortclick(no){
var glist = "s_clock.png|s_price.png|s_work.png";
var aaa = glist.split("|");
for(var i=1; i<=3; i++){
var tobj = document.getElementById("rsort"+i);
var iobj = document.getElementById("rsortimg"+i);
if(tobj){
if(i==no){
tobj.style.backgroundColor=themecolor;
iobj.src="w_"+aaa[i-1];
tobj.style.color="#FFFFFF";
}else{
tobj.style.backgroundColor="";
iobj.src="b_"+aaa[i-1];
tobj.style.color="#444444";
}
}
}
rsortmode=no;
}
function getlatlon_td(key, route, stopid, appcall){
makeRequest('getlatlon_td.php?key='+key+'&route='+route+'&stopid='+stopid+'&appcall='+appcall+'&l='+lang,'dummydiv');
}
function geteta_td(route, stopid, lon, lat, key, appcall){
if(lon=="" || lat==""){
alert("Invalid TD ETA Call!");
return;
}
tlon = parseFloat(lon);
tlat = parseFloat(lat);
var coord = ol.proj.transform([tlon, tlat], 'EPSG:4326', 'EPSG:3857');
markerpopup.setPosition(coord);
//showmarkerpopupinfo(undefined)
var z = Math.floor(map.getView().getZoom());
if(z>=10 && z<=18){
var coord2 = ol.proj.transform([tlon+difflon[z], tlat-difflat[z]], 'EPSG:4326', 'EPSG:3857');
mappantoxy(coord2);
}
ajaxindex++;
makeRequestref('getrouteinstop_o.php?callfrom=td&route='+route+'&stopid='+stopid+'&lat='+lat+'&lon='+lon+'&key='+key+'&appcall='+appcall+'&l='+lang,'popupcontent',ajaxindex);
document.getElementById('redcross').style.visibility='hidden';
currentlist=0;
}
function showtraffic(){
cleartraffic();
if(layermark1[0]==1) makeRequest('loadsmp.php','*jscode*');
if(layermark1[1]==1) makeRequest('loadjtime.php','*jscode*');
if(layermark1[2]==1) makeRequest('loadspeedmap.php','*jscode*');
if(layermark1[3]==1) makeRequest('loadcctv.php','*jscode*');
loadptstop();
}
function loadptstop(){
var plist="";
for(var i=0; i<7; i++){
if(layermark2[i]==1) plist +=","+layerpt[i];
}
if(plist!=""){
plist = plist.substring(1);
var coord = ol.proj.transform(map.getView().getCenter(), 'EPSG:3857', 'EPSG:4326');
var lon = coord[0]+alon;
var lat = coord[1]+alat;
calldummy('loadptstop.php?type='+plist+'&lat='+lat+'&lon='+lon);
}
}
function cleartraffic(){
lineSource.clear();
trafficSource.clear();
ptSource.clear();
}
function removeMarkersByType(type,layer){
ptSource.clear();
}
function buildPtMarker(){
var aaa = mapLayerPtStr.split("|*|");
for(var i=0; i10){
var bbb = rec.split("||");
var lon = parseFloat(bbb[0]);
var lat = parseFloat(bbb[1]);
var type = parseInt(bbb[3]);
var name = bbb[2];
var link = bbb[5];
var code='b';
if(type==1) code='b';
if(type==2) code='g';
if(type==3) code='m';
if(type==4) code='t';
if(type==5) code='p';
if(type==6) code='l';
if(type==7) code='f';
if(type==13) code='m';
if(type==15) code='a';
if(type==20) code='r';
if(type==80) code='a';
if(type==81) code='m';
trafficmarker(code, lat, lon, name, link);
}
}
}
function removeline() {
linecount=0;
cleartraffic();
}
function godrawsmpmarker(){
$.each( trafficInfoObject.smp, function( key, value ) {
trafficmarker('S', value.lat, value.lon, value.name, value.link);
});
}
function godrawjourneymarker(){
$.each( trafficInfoObject.journey, function( key, value ) {
var name = value.tc_name;
if(lang==1) name = value.en_name;
if(lang==2) name = value.sc_name;
trafficmarker('J', value.lat, value.lon, value.loc_id+": "+name, "");
});
}
function godrawcctvmarker(){
$.each( trafficInfoObject.cctv, function( key, value ) {
trafficmarker('C', value.lat, value.lon, value.id+": "+value.name, value.url);
});
}
function godrawspeedmap(){
lineSource.clear();
var lineStyle = [];
for(var i=0; i<3; i++){
if(i==0) color='#00FF00';
if(i==1) color='#FF0000';
if(i==2) color='#FFFF00';
lineStyle[i] = new ol.style.Style({
stroke: new ol.style.Stroke(({
color: color,
width: 3
}))
});
}
var pointsgreen = [];
var pointsred = [];
var pointsblue = [];
$.each( trafficInfoObject.speedmap, function( key, value ) {
var i=0;
if(value.color=='G') i=0;
if(value.color=='R') i=1;
if(value.color=='Y') i=2;
var segment = [];
$.each( this.lines, function( key2, value2 ) {
segment.push(ol.proj.transform( [value2.lon+alon, value2.lat+alat], 'EPSG:4326', 'EPSG:3857'));
});
if(i==0) pointsgreen.push(segment);
if(i==1) pointsred.push(segment);
if(i==2) pointsblue.push(segment);
});
var greenline = new ol.Feature({
geometry: new ol.geom.MultiLineString(pointsgreen),
name: "Line"
});
greenline.setStyle(lineStyle[0]);
var redline = new ol.Feature({
geometry: new ol.geom.MultiLineString(pointsred),
name: "Line"
});
redline.setStyle(lineStyle[1]);
var blueline = new ol.Feature({
geometry: new ol.geom.MultiLineString(pointsblue),
name: "Line"
});
blueline.setStyle(lineStyle[2]);
lineSource.addFeature(greenline);
lineSource.addFeature(redline);
lineSource.addFeature(blueline);
}
function clearwalkline(){
walkSource.clear();
}
function drawwalkline(slat,slon,elat,elon){
var dist = getDistanceFromLatLonInKm(slat,slon,elat,elon);
var step = Math.ceil(dist/0.1);
var lineStyle = new ol.style.Style({
stroke: new ol.style.Stroke(({
color: '#0000FF',
lineDash: [.1, 5],
width: 3
}))
});
var dx = slon - elon;
var dy = slat - elat;
var rotation = Math.atan2(dy, dx);
for(var i=0; i1 && info.substring(0,1)=="*") info=info.substring(1);
overlay.setPosition(evt.coordinate);
var aaa = info.split("{");
if(info.indexOf("|*")>0){
aaa = info.split("|*");
}
if(aaa.length==1) aaa = info.split("||");
tooltip.innerHTML = aaa[0];
debug(tooltip.innerHTML);
}else{
overlay.setPosition(undefined);
}
}
map = new ol.Map({
interactions: interactions, //Block Rotation
controls : ol.control.defaults({
attribution : false,
zoom : true,
}).extend([
scaleLineControl
]),
target: "map",
layers: [
new ol.layer.Tile({
source: new ol.source.XYZ({
tilePixelRatio: 2,
url: 'https://map.citybus.com.hk/map/HJP/TC{z}/{x}-{y}.jpg?v=202401',
//url: 'https://map.nwstbus.com.hk/map/SJP/TC{z}/{x}-{y}.jpg',
//url: 'http://mobile.nwstbus.com.hk/map/HJP/TC13/6690-3572.jpg',
wrapX: false
})
}),
CircleLayer,
new ol.layer.Vector({
source: lineSource
}),
new ol.layer.Vector({
source: walkSource
}),
new ol.layer.Vector({
source: trafficSource
}),
new ol.layer.Vector({
source: ptSource
}),
new ol.layer.Vector({
source: stopSource
}),
new ol.layer.Vector({
source: vectorSource
}),
new ol.layer.Vector({
source: tramRailSource
}),
new ol.layer.Vector({
source: csNearByStopSource
})
],
view: view
});
//applyInitialUIState();
//applyMargins();
mappopupelement = document.getElementById('markerpopup');
hotspotpopupelement = document.getElementById('hotspotpopup');
var overlay = new ol.Overlay({
element: tooltip,
offset: [10, 0],
positioning: 'bottom-left'
});
map.addOverlay(overlay);
popup = new ol.Overlay({
element: document.getElementById('popup'),
autoPan: true,
autoPanAnimation: {
duration: 250
}
});
map.addOverlay(popup);
markerpopup = new ol.Overlay({
element: mappopupelement,
positioning: 'bottom-center',
stopEvent: true
});
map.addOverlay(markerpopup);
hotspotpopup = new ol.Overlay({
element: hotspotpopupelement,
positioning: 'bottom-center',
stopEvent: true
});
map.addOverlay(hotspotpopup);
map.getViewport().addEventListener('contextmenu', function (evt) {
closeautocom();
mapstandclick(evt);
downmark=0;
});
map.getViewport().addEventListener('click', function (evt) {
closeautocom();
if(downmark==2 && mouseonfeature==null){
}else{
mapstandclick(evt);
}
downmark=0;
});
var downmark=0;
var mousex=0;
var mousey=0;
map.getViewport().addEventListener('mousedown', function (evt) {
downmark=1;
mousex=evt.layerX;
mousey=evt.layerY;
});
map.getViewport().addEventListener('mousemove', function (evt) {
if( (Math.abs(mousex-evt.layerX)>3 || Math.abs(mousey-evt.layerY)>3) && downmark==1) downmark=2;
});
function mapstandclick(evt){
redrawMarkerIcon();
mouseonfeature = null;
evt.preventDefault();
var location = map.getCoordinateFromPixel([evt.layerX, evt.layerY]);
var coord = ol.proj.transform(location, 'EPSG:3857', 'EPSG:4326');
var lon = coord[0];
var lat = coord[1];
for(var i=markercount-1; i>=0; i--){
var tempfeature = markers[i];
var geometry = tempfeature.getGeometry();
var flocation = geometry.getCoordinates();
var pix = map.getPixelFromCoordinate(flocation);
var pix = map.getPixelFromCoordinate(flocation);
var sizex = markersize[i][0]/2;
var sizey = markersize[i][1]/2;
var offx = markersize[i][2]/2;
var offy = markersize[i][3]/2;
if(markersize[i][1]<70 && Math.abs(evt.layerX-pix[0]-offx)=0; i--){
var tempfeature = stopNearbyMarkers[i];
var geometry = tempfeature.getGeometry();
var flocation = geometry.getCoordinates();
var pix = map.getPixelFromCoordinate(flocation);
var pix = map.getPixelFromCoordinate(flocation);
var sizex = stopNearbyMarkersize[i][0]/2;
var sizey = stopNearbyMarkersize[i][1]/2;
var offx = stopNearbyMarkersize[i][2]/2;
var offy = stopNearbyMarkersize[i][3]/2;
if(stopNearbyMarkersize[i][1]<70 && Math.abs(evt.layerX-pix[0]-offx)0){
nnn1 = s.split("[");
nnn2 = nnn1[1].split("]");
var temp = '||0||0||0';
var etainfo = nnn2.concat(temp);
makeRequest('auto_baa57ea2dd804339a399dfc61c962d42.php?info='+etainfo,'dummydiv');
/* ??? */
var infos = s.split("||");
var newImg = infos[4];
if (infos[4] == "stop3.png")
newImg = "stop3b.png";
offx = infos[7];
offy = infos[8];
amode='pixels';
ax=(-offx)*2;
ay=(-offy);
if(sizex==15){
ax=0.5;
ay=0.5;
amode='fraction';
}
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(({
scale: 1,
anchor: [ax,ay],
anchorXUnits: amode,
anchorYUnits: amode,
opacity: 1,
src: newImg
}))
});
mouseonfeature.setStyle(iconStyle);
}
if(s.length>1 && s.indexOf("|*|")>0)
nearbyclickpopup(feature);
else if(s.length>1 && s.substring(0,1)=="*")
hotspotclickpopup(feature)
else
markerclickpopup(feature)
return;
}
}else{
if(hotspotpopup.getPosition()!=undefined)
hotspotpopup.setPosition(undefined);
else if(markerpopup.getPosition()!=undefined)
markerpopup.setPosition(undefined);
else if (CircleLayer.getVisible()){
// do nothing
}
else
maparepopup(location,lat,lon);
}
}
//map.on('singleclick', function(evt) {
// mapclickaction(evt,evt.coordinate);
//});
function mapclickaction(evt,location){
if(skipmapclick==1){
skipmapclick=0;
return;
}
var coord = ol.proj.transform(location, 'EPSG:3857', 'EPSG:4326');
var lon = coord[0];
var lat = coord[1];
var feature = map.forEachFeatureAtPixel(evt.pixel,
function(feature, layer) {
return feature;
});
if (feature && !(feature==CircleFeature || feature==CircleFeatureC)) {
popup.setPosition(undefined);
var s = feature.get('name');
if(s.indexOf("[")>0){
nnn1 = s.split("[");
nnn2 = nnn1[1].split("]");
var temp = '||0||0||0';
var etainfo = nnn2.concat(temp);
makeRequest('auto_baa57ea2dd804339a399dfc61c962d42.php?info='+etainfo,'dummydiv');
}
if(s.length>1 && s.indexOf("|*|")>0)
nearbyclickpopup(feature);
else if(s.length>1 && s.substring(0,1)=="*")
hotspotclickpopup(feature)
else
markerclickpopup(feature)
return;
}
lastlat = (lat-alat);
lastlon = (lon-alon);
debug("ll="+lastlat+","+lastlon);
if(markerpopup.getPosition()==undefined ){
/*
mappanto(lon,lat);
markerpopup.setPosition(evt.coordinate);
showmarkerpopupinfo(undefined);
//makeRequest("getPoiByLoc.php?lng="+lastlon+"&lat="+lastlat+"&lang="+lcode+"&mode=2","*popup*");
lastname = "--";
*/
}else{
//hidemappop();
}
/*
if(document.getElementById("sloc") && linecount==0 && markerpopup.getPosition()==undefined && hotspotpopup.getPosition()==undefined){
maparepopup(evt.coordinate,lat,lon);
}
*/
maparepopup(evt.coordinate,lat,lon);
/*
if(markerpopup.getPosition()==undefined)
maparepopup(evt.coordinate,lat,lon);
markerpopup.setPosition(undefined);
*/
//Show popup
}
map.on('pointermove', displayTooltip);
map.on('moveend', onMoveEnd);
map.panTo = function(ll) {
mappanto(ll[0],ll[1]);
}
map.zoomTo = function(z){
mapzoom(z);
}
map.zoomIn= function(){
var z = map.getView().getZoom();
if(z<18) mapzoom(z+1);
}
map.zoomOut = function(){
var z = map.getView().getZoom();
if(z>10) mapzoom(z-1);
}
map.getZoom = function(){
return map.getView().getZoom();
}
});
function redrawMarkerIcon()
{
//alert('in redrawMarkerIcon() ' + markercount);
for(var i=markercount-1; i>=0; i--){
redrawMarkerIconProcess(markers[i]);
}
if (stopNearbyMarkercount > 0)
{
for(var i=stopNearbyMarkercount-1; i>=0; i--){
//alert(stopNearbyMarkers[i].get('name'));
redrawMarkerIconProcess(stopNearbyMarkers[i]);
//i = 0;
}
}
}
function redrawMarkerIconProcess(feature)
{
var s = feature.get('name');
//alert(s);
if(s.indexOf("[")>0){
var infosCat = s.split("|*|");
/* ??? */
var infos = infosCat[3].split("||");
//alert(infos[4]);
offx = infos[7];
offy = infos[8];
if(infos[5]==15){
ax=0.5;
ay=0.5;
amode='fraction';
}
ax = 4;
ay = 40;
amode = "pixels";
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(({
scale: 1,
anchor: [ax,ay],
anchorXUnits: amode,
anchorYUnits: amode,
opacity: 1,
src: infos[4]
}))
});
feature.setStyle(iconStyle);
}
}
function hidemappop(){
markerpopup.setPosition(undefined);
hotspotpopup.setPosition(undefined);
redrawMarkerIcon();
}
function onMoveEnd(evt){
onMoveEndAction('');
}
function onMoveEndAction(fromQr)
{
if(markerpopup.getPosition()!=undefined && fromQr!='') return;
var coord = ol.proj.transform( map.getView().getCenter(), 'EPSG:3857', 'EPSG:4326');
var tlon = coord[0];
var tlat = coord[1];
if(CircleLayer.getVisible()){
setcirclecenter(tlat,tlon);
ajaxindex++;
makeRequestref('getnearbyroute.php?lat='+tlat+'&lon='+tlon+'&l='+lang,'sysitembox',ajaxindex);
setTimeout(function(){ makeRequestref('getnearbystop.php?lat='+tlat+'&lon='+tlon+'&l='+lang,'dummydiv',ajaxindex);}, 200);
}
loadptstop();
}
function calldummy(url){
makeRequest(url,'dummydiv');
}
function hotspotclickpopup(feature){
var info = feature.get('name');
var aaa = info.split("{");
if(aaa.length==1) return;
var geometry = feature.getGeometry();
var coord = geometry.getCoordinates();
hotspotpopup.setPosition(coord);
var bbb = aaa[1].split("}");
var ccc = bbb[0].split("^");
var id = ccc[0];
var lat = parseFloat(ccc[1]);
var lon = parseFloat(ccc[2]);
makeRequest('gethotspotresult.php?id='+id+'&lat='+lat+'&lon='+lon+'&l='+lang,'hpopupcontent');
var z = Math.floor(map.getView().getZoom());
if(z>=10 && z<=18){
var coord2 = ol.proj.transform([lon, lat-difflat[z]], 'EPSG:4326', 'EPSG:3857');
mappantoxy(coord2);
}
}
function nearbyclickpopup(feature){
//alert('in nearbyclickpopup');
var info = feature.get('name');
var aaa = info.split("|*|");
if(aaa.length==1) return;
var bbb = aaa[1].split("||");
var altXY = aaa[2].split("||");
var geometry = feature.getGeometry();
var coord = geometry.getCoordinates();
markerpopup.setPosition(coord);
var nnn1 = bbb[0].split("[");
var nnn2 = nnn1[1].split("]");
makeRequest('getrouteinstop_nearby.php?id='+nnn2[0]+'&lat='+bbb[2]+'&lon='+bbb[3]+'&l='+lang+'&altLon='+altXY[0]+'&altLat='+altXY[1],'popupcontent');
var coord2 = ol.proj.transform(coord, 'EPSG:3857', 'EPSG:4326');
var tlon = coord2[0];
var tlat = coord2[1];
var z = Math.floor(map.getView().getZoom());
if(z>=10 && z<=18){
var coord2 = ol.proj.transform([tlon+difflon[z], tlat-difflat[z]], 'EPSG:4326', 'EPSG:3857');
mappantoxy(coord2);
}
}
function markerclickpopup(feature){
var info = feature.get('name');
var aaa = info.split("{");
if(aaa.length==1) return;
var geometry = feature.getGeometry();
var coord = geometry.getCoordinates();
markerpopup.setPosition(coord);
showmarkerpopupinfo(feature);
}
var lsetstart = '設為起點';
var lsetend = '設為終點';
var lnewbookmark = '加至我的書籤';
var lclose = '關閉';
function maparepopup(coord,lat,lon){
var element = popup.getElement();
var coordinate = coord;
var hdms = ol.coordinate.toStringHDMS(ol.proj.transform(coordinate, 'EPSG:3857', 'EPSG:4326'));
$(element).popover('destroy');
popupposition=coordinate;
popup.setPosition(coordinate);
mappantoxy(coordinate);
var tlat = lat-alat;
var tlon = lon-alon;
makeRequest("get_rgeocode.php?lon="+tlon+"&lat="+tlat+"&l="+lcode+"","*popup*");
var name=". . .";
lastname = name;
lastlat = tlat;
lastlon = tlon;
name = '';
var popupcontent = '
'+
'
'+name+'
'+
'
'+lsetstart+'
'+
'
'+lsetend+'
'+
'
'+lnewbookmark+'
';
$(element).popover({
'placement': 'top',
'animation': false,
'html': true,
'content': popupcontent
});
$(element).popover('show');
}
function screensize(mode){
if (self.innerHeight){
x = self.innerWidth;
y = self.innerHeight;
}else if (document.documentElement && document.documentElement.clientHeight){
x = document.documentElement.clientWidth;
y = document.documentElement.clientHeight;
}else if (document.body){
x = document.body.clientWidth;
y = document.body.clientHeight;
}
if(mode=="W")
return x;
else
return x;
}
function goresize(){
var x = screensize("W");
var adjust=0;
var logobar = document.getElementById('fb_logo');
var dmap = document.getElementById('map');
if(x<768){
adjust=44;
dmap.style.marginLeft="0px";
logobar.align="left";
}else{
dmap.style.marginLeft="380px";
logobar.align="center";
showleftpanel();
}
adjust+=0;
var dmenu1box = document.getElementById('menu1box');
if(dmenu1box){
dmenu1box.style.height="calc(100% - "+(255-adjust)+"px)";
}
var dgocatbox = document.getElementById('gocatbox');
if(dgocatbox){
dgocatbox.style.height="calc(100% - "+(113-adjust)+"px)";
}
var dgocatitembox = document.getElementById('gocatitembox');
if(dgocatitembox){
dgocatitembox.style.height="calc(100% - "+(113-adjust)+"px)";
}
var dstoplistbox = document.getElementById('stoplistbox');
if(dstoplistbox){
dstoplistbox.style.height="calc(100% - "+(85-adjust)+"px)";
}
var dfullbox = document.getElementById('fullbox');
if(dfullbox){
dfullbox.style.height="calc(100% - "+(43-adjust)+"px)";
}
var dferrylist = document.getElementById('ferrylistbox');
if(dferrylist){
dferrylist.style.height="calc(100% - "+(288-adjust)+"px)";
}
var dtranlistbox = document.getElementById('tranlistbox');
if(dtranlistbox){
dtranlistbox.style.height="calc(100% - "+(175-adjust)+"px)";
}
var dppresultlist = document.getElementById('ppresultlist');
if(dppresultlist){
dppresultlist.style.height="calc(100% - "+(115-adjust)+"px)";
}
var dnearbylist = document.getElementById('nearbylist');
if(dnearbylist){
dnearbylist.style.height="calc(100% - "+(133-adjust)+"px)";
}
var droutelist2 = document.getElementById('routelist2');
if(droutelist2){
droutelist2.style.height="calc(100% - "+(133-adjust)+"px)";
}
goresizex();
}
function ppbookmark(no){
}
var lpath = '途徑路線';
var laddbm = '添加書籤';
var lstreetview = '街景';
var lmin = '分鐘';
function showmarkerpopupinfo(feature){
var obj = document.getElementById('popupcontent');
if(obj){
if(feature!=undefined){
var data = feature.get('name');
var aaa = data.split("{");
if(aaa.length==2){
var bbb = aaa[1].split("}");
var ccc = bbb[0].split("^");
stopclick1(ccc[0],ccc[1],ccc[2],ccc[3],ccc[4],ccc[5],ccc[6],ccc[7],ccc[8]);
}
}
}
}
function elastic(t) {
return Math.pow(2, -10 * t) * Math.sin((t - 0.075) * (2 * Math.PI) / 0.3) + 1;
}
function closepopup(){
popup.setPosition(undefined);
}
function gosetstartend(mode,name,lat,lon){
if(mode<0){
if(startname==""){
mode=0;
}else{
mode=1;
}
}
lastname = name;
//lastlat = parseFloat(lat)-(2*alat);
//lastlon = parseFloat(lon)-(2*alon);
lastlat = parseFloat(lat)-(alat);
lastlon = parseFloat(lon)-(alon);
setstartend(mode,name,lastlat,lastlon);
//panto(lastlon,lastlat);
}
function setstartend(mode,name,lat,lon){
if(mode==0){
startname = lastname;
startlat = lastlat;
startlon = lastlon;
}else{
endname = lastname;
endlat = lastlat;
endlon = lastlon;
}
gomenu(2,1);
closepopup();
//addhistory("LOCATIONHISTORY",lastname+'~'+lastlat+'~'+lastlon);
}
function setstart(){
setstartend(0,lastname,lastlat,lastlon);
hidepopup();
panto(lastlon,lastlat);
}
function setend(){
setstartend(1,lastname,lastlat,lastlon);
hidepopup();
panto(lastlon,lastlat);
}
function disabledEventPropagation(event)
{
if (event.stopPropagation){
event.stopPropagation();
}
else if(window.event){
window.event.cancelBubble=true;
}
}
function clearmarkers(){
clearmaproute();
}
function clearmaproute(){
clearwalkline();
clearallstop();
clearallmarker();
//showstartendmarker();
showstartendpoints();
}
function clearallstop(){
stopSource.clear();
}
function trafficmarker(code,lat,lng,name,extra){
var info = name+"||"+code+"||"+lat+"||"+lng+"||"+extra;
var traffic = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([lng+alon,lat+alat],'EPSG:4326', 'EPSG:3857')),
name: info
});
var png = 'icons/cctvdot.png';
var xoff=0.5;
var yoff=1;
if(code=='C'){
png = 'icons/cctvdot.png';
yoff=0.5;
xoff=0.5
}
if(code=='J'){
png = 'icons/jtime.png';
yoff=1.0;
xoff=0.24
}
if(code=='S'){
png = 'icons/smpanel.png';
yoff=1.0;
xoff=0.24
}
if(code=='b'){
png = 'icons/m_bus.png';
}
if(code=='t'){
png = 'icons/m_tram.png';
}
if(code=='p'){
png = 'icons/m_ptram.png';
}
if(code=='a'){
png = 'icons/m_taxi.png';
}
if(code=='f'){
png = 'icons/m_ferry.png';
}
if(code=='m'){
png = 'icons/m_mtr.png';
}
if(code=='l'){
png = 'icons/m_lrt.png';
}
if(code=='g'){
png = 'icons/m_gvan.png';
}
if(code=='r'){
png = 'icons/m_rvan.png';
}
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(({
scale: 0.5,
anchor: [xoff,yoff],
anchorXUnits: 'fraction',
anchorYUnits: 'fraction',
opacity: 0.8,
src: png
}))
});
traffic.setStyle(iconStyle);
if(code=='C' || code=='S' || code=='J'){
trafficSource.addFeature(traffic);
}else{
ptSource.addFeature(traffic);
}
}
function stopmarker(leg,lat,lng,name){
var info = name+"||"+leg+"||"+lat+"||"+lng;
var stop = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([lng+alon,lat+alat],'EPSG:4326', 'EPSG:3857')),
name: info
});
var png = 'icons/gdot.png';
if(leg==1) png = 'icons/rdot.png';
if(leg==2) png = 'icons/bdot.png';
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(({
scale: 0.5,
anchor: [0.5,0.5],
anchorXUnits: 'fraction',
anchorYUnits: 'fraction',
opacity: 0.8,
src: png
}))
});
stop.setStyle(iconStyle);
stopSource.addFeature(stop);
}
function clearallmarker(){
for(var i=0; i<1000; i++){
markers[i]=null;
markercodes[i]='';
markerlat[i]=0.0;
}
markercount=0;
}
var mstart = '起點';
var mend = '終點';
var mupcar = '上車';
var mdowncar = '落車';
var mupboat = '上船';
var mdownboat = '落船';
var mchange = '轉乘';
function etmarker(code,lat,lng,name){
if(true) return;
var increment = 1;
var lastpoint = -1;
var info = name+"||"+(code=="S"?"O":code)+"||"+lat+"||"+lng;
if(code=="S" || code=="E"){
for(i=0;imarkerlat[tempindex[i+1]]){
var t = tempindex[i+1];
tempindex[i+1] = tempindex[i];
tempindex[i] = t;
needsort = 1;
}
}
}
stopSource.clear;
vectorSource.clear();
for(var i=0; i5){
var aaa = linepoint[i].split(",");
var lon = parseFloat(aaa[2]);
var lat = parseFloat(aaa[1]);
segment.push(ol.proj.transform( [lon, lat], 'EPSG:4326', 'EPSG:3857'));
}
}
if(col==0)
pointsred.push(segment);
else if(col==1)
pointsgreen.push(segment);
else if(col==2)
pointsblue.push(segment);
var greenline = new ol.Feature({
geometry: new ol.geom.MultiLineString(pointsgreen),
name: "Line"
});
greenline.setStyle(lineStyle[0]);
var redline = new ol.Feature({
geometry: new ol.geom.MultiLineString(pointsred),
name: "Line"
});
redline.setStyle(lineStyle[1]);
var blueline = new ol.Feature({
geometry: new ol.geom.MultiLineString(pointsblue),
name: "Line"
});
blueline.setStyle(lineStyle[2]);
lineSource.addFeature(greenline);
lineSource.addFeature(redline);
lineSource.addFeature(blueline);
}
function showhidemenu(){
var left = $('#sidebar').offset().left;
if(left>-100)
$("#sidebar").css({left:left}).animate({"left":"-340px"}, "fast");
else
$("#sidebar").css({left:left}).animate({"left":"0px"}, "fast");
}
function checkshowlayer(){
var obj = document.getElementById('tranlayer');
if(obj && (obj.style.display=="" || obj.style.display=="none")){
obj.style.right="-300px";
obj.style.display="block";
}
}
function checkhidelayer(){
var obj = document.getElementById('tranlayer');
if(obj){
obj.style.right="0px";
obj.style.display="none";
}
}
function showhidelayer(){
checkshowlayer();
var right = parseInt($('#tranlayer').css('right'));
if(right==0){
$("#tranlayer").css({right:right}).animate({"right":"-300px"}, "fast");
setTimeout("checkhidelayer();",500);
}else{
makeRequest('layer.php','tranlayer')
$("#tranlayer").css({right:right}).animate({"right":"0px"}, "fast");
}
}
function showhidelegend(){
checkshowlayer();
var right = parseInt($('#tranlayer').css('right'));
debug(right);
if(right==0){
$("#tranlayer").css({right:right}).animate({"right":"-300px"}, "fast");
setTimeout("checkhidelayer();",500);
}else{
makeRequest('legend.php','tranlayer')
$("#tranlayer").css({right:right}).animate({"right":"0px"}, "fast");
}
}
function smenu(mno){
showhidemenu();
}
function infoboxloadaction(){
hideppoption();
}
/*
function makeRequest(urlx,id) {
if(id=="infobox"){
infoboxloadaction();
}
sn++;
var url="";
if(urlx.indexOf("?")>0)
url=urlx+'&sysid='+sn;
else
url=urlx+'?sysid='+sn;
var http_request = false;
var ts1 = "";
var ts2 = "";
var p=0;
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() {
alertContents(http_request,id); };
http_request.open('GET', url, true);
http_request.send(null);
}
function alertContents(http_request,id) {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
var mesg = http_request.responseText;
if(id=="*popup*"){
popup_request(mesg);
}else if(id=="*jscode*"){
eval(mesg);
}else if(id=="v_ustatus"){
v_ustatus=mesg;
}else{
if(id.substring(0,4)=='txt_'){
document.getElementById(id).value=mesg;
}else{
var checkcnt=0;
while(document.getElementById(id) && checkcnt<5){
setTimeout('',500);
checkcnt=checkcnt+1;
}
document.getElementById(id).innerHTML=mesg;
if(id=="infobox") goresize();
if(id=="autocom" || id=="autocom2"){
if(mesg.length<10){
document.getElementById(id).style.display ="none";
}
}
}
window.scrollTo(0,0);
}
}else{
errorcnt++;
}
}
}
*/
var unknownname = '不知名位置';
function popup_request(s){
var aaa = s.split("||");
var name = aaa[0];
if(name==undefined) name = unknownname;
lastname = name;
document.getElementById("popupname").innerHTML = name;
}
function showinfobox(url){
makeRequest(url,"infobox");
}
function showmenu(no){
if(sys_nearby==1) togglenearby();
showleftpanel();
showinfobox("menu"+no+".php");
}
function callweb(weburl){
var url = weburl;
var result = "";
$.ajax({
url: url,
type: 'GET',
async: false,
cache: false,
timeout: 30000,
error: function(){
debug("Error to connect server!");
},
success: function(msg){
result = msg;
}
});
return result;
}
function debug(s){
var obj=document.getElementById("debug");
if(obj) obj.innerHTML=s;
}
function swapppinfo(){
lastname="";
lastlat=0.0;
lastlon=0.0;
var tstr = startname;
startname = endname
endname = tstr;
var tlat = startlat;
var tlon = startlon;
startlat = endlat;
startlon = endlon;
endlat = tlat;
endlon = tlon;
showppinfo();
}
function clearppinfo(){
startname="";
endname="";
startlat=startlon=0.0;
endlat=endlon=0.0;
document.getElementById("fstartpo").value = "";
document.getElementById("fendpo").value = "";
vectorSource.clear();
}
var lstartpo = '起點';
var lendpo = '終點';
function showppinfo(){
var lcnt=0;
if(startname!=""){
document.getElementById("fstartpo").value = startname;
etmarker("S",startlat,startlon,lstartpo+": "+startname);
lcnt++;
}
if(endname!=""){
document.getElementById("fendpo").value = endname;
etmarker("E",endlat,endlon,lendpo+": "+endname);
lcnt++;
}
if(lcnt==2){
//clearwalkline();
//drawwalkline(startlat,startlon,endlat,endlon);
}
showmarker();
}
function showstartendmarker(){
etmarker("S",startlat,startlon,lstartpo+": "+startname);
etmarker("E",endlat,endlon,lendpo+": "+endname);
showmarker();
}
var timeint;
var newpoint = new Array(2);
var newzoom=0;
function goanimate(zoom,point){
newzoom = zoom;
newpoint = point;
timeint = setInterval(function(){ mapTimer() }, 100);
}
function mapTimer(){
var z = map.getView().getZoom();
var p = map.getView().getCenter();
var zdiff=1;
var pdiff=1;
if(newzoom==undefined || Math.abs(z-newzoom)<0.1){
view.setZoom(newzoom);
z=newzoom;
zdiff=0;
}
if(Math.abs(p[0]-newpoint[0])<3 && Math.abs(p[1]-newpoint[1])<3){
view.setCenter(newpoint);
p=newpoint;
pdiff=0;
}
console.log(p[0]+" "+newpoint[0]+" "+Math.abs(p[0]-newpoint[0])+" "+Math.abs(p[1]-newpoint[1])+" : "+z+" "+newzoom);
if(zdiff==0 && pdiff==0){
clearInterval(timeint);
}else{
var tempp = new Array(2);
var tempz = (z+newzoom)/2;
tempp[0] = (p[0]+newpoint[0])/2;
tempp[1] = (p[1]+newpoint[1])/2;
view.setCenter(tempp);
view.setZoom(tempz);
}
}
function mappanto(lon,lat){
if(lon>0 && lat>0){
var tpoint = ol.proj.fromLonLat([lon+alon, lat+alat]);
var z = map.getView().getZoom();
//goanimate(z,tpoint);
//view.setCenter(tpoint);
//view.animate({ center: tpoint, duration: 500});
gopanTo(tpoint);
}
}
function mappantoxy(tpoint){
//view.setCenter(tpoint);
//var z = map.getView().getZoom();
//goanimate(z,tpoint);
//view.animate({ center: tpoint, duration: 500});
gopanTo(tpoint);
}
function mapzoom(z){
gozoom(z);
//var tpoint = map.getView().getCenter();
//goanimate(z,tpoint);
//view.setZoom(z);
//view.animate({ zoom: z, duration: 500});
}
function gozoom(zoom_level) {
if(acode==1){
var zoom = ol.animation.zoom({
resolution: view.getResolution(),
duration: 300
});
map.beforeRender(zoom);
}
view.setZoom(zoom_level);
}
function gopanTo(location){
if(acode==1){
var pan = ol.animation.pan({
source: map.getView().getCenter(),
duration: 300
});
map.beforeRender(pan);
}
view.setCenter(location);
}
function keysearch(mode){
showinfobox("keysearch.php?m="+mode);
}
function goback(){
showmenu(1);
}
function gofocus(dname){
var obj = document.getElementById(dname);
if(obj) obj.focus();
}
function timestr(expires_seconds){
var d = new Date();
d = new Date(d.getTime() + 1000 * expires_seconds);
//return d.toGMTString();
return moment().format("YYYY-MM-DD HH:mm:ss");
}
function showlocation(dname){
var hdata='';
var oldlist = getCookie("LOCATIONHISTORY");
var aaa = oldlist.split("||");
for(var i=0; i';
hdata+='';
hdata+=speechbut("H"+i,bbb[0])+'';
}
}
hdata+='
'+bbb[0]+'
';
hdata+='';
var obj = document.getElementById(dname);
if(obj) obj.innerHTML=hdata;
}
function showhistory(mode,dname){
var hdata='';
var oldlist = getCookie("SEARCH_A");
var aaa = oldlist.split("||");
for(var i=0; i';
hdata+='';
}
}
hdata+='
'+aaa[i]+'
';
hdata+='';
var obj = document.getElementById(dname);
if(obj) obj.innerHTML=hdata;
}
function gokeysearch(mode,dname){
ppresult = document.getElementById("infobox").innerHTML;
if(dname.length>0 && dname.substring(0,1)=="*"){
showinfobox("gosearch.php?m="+mode+"&k="+dname.substring(1));
}else{
var obj = document.getElementById(dname);
if(obj.value=="") return;
addhistory("SEARCH_A",obj.value);
showinfobox("gosearch.php?m="+mode+"&k="+obj.value);
}
}
function addhistory(code,kword){
addrecord(code,kword,10);
}
function addrecord(code,kword,limit){
var oldlist = getCookie(code);
var aaa = oldlist.split("||");
var newlist = kword+"||";
var cnt=0;
var ss1 = kword.split("~");
for(var i=0; ilimit) break;
}
}
}
setCookie(code,newlist,1000000000);
}
function setCookie(variable, value, expires_seconds) {
document.cookie = variable + '=' + value + '; expires=' + timestr(expires_seconds) + ';';
callweb("setcookie.php?c="+variable+"&v="+encodeURI(value));
}
function getCookie(cname) {
return callweb("getcookie.php?c="+cname);
}
function deleterecord(code,kword){
var oldlist = getCookie(code);
var aaa = oldlist.split("||");
var newlist = "";
var cnt=0;
var ss1 = kword.split("~");
for(var i=0; i
" +lsearching+'
';
}
function goppsearch(){
if(startname!="" && endname!=""){
showloading();
showinfobox("goppsearch.php?slat="+startlat+"&slon="+startlon+"&elat="+endlat+"&elon="+endlon+"&sname="+startname+"&ename="+endname);
}
}
function backtoppresult(){
document.getElementById("infobox").innerHTML = ppresult;
}
function goppresult(i,m){
if(m=='S'){
ppresult = document.getElementById("infobox").innerHTML;
showloading();
}
showinfobox("goppresult.php?i="+i+"&m="+m);
}
function showstartendname(sdiv,ediv){
document.getElementById(sdiv).innerHTML=startname;
document.getElementById(ediv).innerHTML=endname;
}
function pantostartend(code){
if(code=="S")
panto(startlon,startlat);
else
panto(endlon,endlat);
}
function setcolor(c){
callweb("setcolor.php?c="+c);
document.location.href = "index.php";
}
var startlab='起點';
var endlab='終點';
var laddbookmark='加入書籤';
var markmarkname='書籤名稱';
var selectas='選擇此地點為';
var select='請選擇';
var lsave='儲存';
var ldelete='刪除';
var lkmb='九巴';
var lnwst='新巴城巴';
function setpopupcontent(mode){
var c1=''+
''+
''+
''+
'
';
var c2=''+
''+
''+
''+
'
';
var c3=''+
''+
''+
'
';
var c4=''+
''+
''+
'
';
var c5=''+
''+
''+
''+
''+
'
';
if(mode==2){
setpopupcontentstr(laddbookmark+" :",c2);
document.getElementById("fbookmark").value=lastname;
}else if(mode==3){
setpopupcontentstr(selectas+" :",c3);
}else if(mode==4){
setpopupcontentstr(select+" :",c4);
}else if(mode==5){
setpopupcontentstr(markmarkname+" :",c5);
document.getElementById("fbookmark").value=lastname;
}else{
setpopupcontentstr(selectas+" :",c1);
}
}
function tdalert(title,content){
setpopupcontentstr(title,content);
showpopup();
}
function setpopupcontentstr(title,content){
document.getElementById("popupcontent").innerHTML=content;
document.getElementById("popuptitle").innerHTML=title;
}
function newbookmark(tname,tlat,tlon){
var aaa = tname.split(": ");
if(aaa.length>0) tname=aaa[1];
bookmarkmode=0;
bmlat=tlat;
bmlon=tlon;
lastname=tname;
setpopupcontent(2);
showpopup();
}
function savebookmark(){
var bmname = document.getElementById("fbookmark").value;
if(bmname=="") return;
if(bookmarkmode==0){
savebookmarkwithinfo(bmname,bmlat,bmlon);
}else if(bookmarkmode==1){
calldummy("routebookmark.php?no="+bookmarkno+"&name="+encodeURI(bmname));
hidepopup();
}else if(bookmarkmode==2){
calldummy("ppbookmark.php?no="+bookmarkno+"&name="+encodeURI(bmname));
hidepopup();
}
}
function savebookmarkwithinfo(tname,tlat,tlon){
var newbm = tname+"~"+tlat+"~"+tlon+"~"+timestr(0);
addrecord("BOOKMARK",newbm,500);
hidepopup();
deleterecord("LOCATIONHISTORY",newbm);
showmenu(1)
}
function hideoverlay(){
$('#fulloverlay').modal('hide');
}
function hideoverlay_p2p_result_detailed_list(){
$('#fulloverlay_p2p_result_detailed_list').modal('hide');
}
function showpopup(){
$('#tddailog').modal('show');
}
function hidepopup(){
$('#tddailog').modal('hide');
}
function promptstartend_bm(name,lat,lon){
lastname=name;
lastlat=lat;
lastlon=lon;
setpopupcontent(3);
showpopup();
}
function promptstartend(name,lat,lon){
lastname=name;
lastlat=lat;
lastlon=lon;
bmlat=lat;
bmlon=lon;
setpopupcontent(1);
showpopup();
}
function setbookmark(){
bookmarkmode=0;
setpopupcontent(2);
showpopup();
}
function speechbut($code,$text){
if(sys_audio==0)
return '';
else
return '';
}
function showbookmark(dname){
var hdata='';
var oldlist = getCookie("BOOKMARK");
var aaa = oldlist.split("||");
for(var i=0; i';
hdata+='';
hdata+=speechbut("H"+i,bbb[0])+'';
}
}
hdata+='
'+bbb[0]+'
';
hdata+='';
var obj = document.getElementById(dname);
if(obj) obj.innerHTML=hdata;
}
function streetview(lat,lon){
var url = 'http://maps.google.com/maps?q=&layer=c&cbll='+lat+','+lon;
// Fixes dual-screen position Most browsers Firefox
var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : window.screenX;
var dualScreenTop = window.screenTop != undefined ? window.screenTop : window.screenY;
var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
var w = width * 0.6;
var h = height * 0.7;
var left = ((width / 2) - (w / 2)) + dualScreenLeft;
var top = ((height / 2) - (h / 2)) + dualScreenTop;
var newWindow = window.open(url, '_blank', 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
// Puts focus on the newWindow
if (window.focus) {
newWindow.focus();
}
//window.open(url, '_blank', 'width=400,height=400');
/*$('#fulloverlay').modal('show');
$('#fulloverlay_title').html('街景');
googlemap_initialize(lat,lon);
//showoverlay('街景','http://app1.hketransport.td.gov.hk/et/streetview_iphone.php?lat='+lat+'&lon='+lon+'&lang=TC&p=iphone');
*/
}
function showfulloverlay(title, content){
$('#fulloverlay').modal('show');
$('#fulloverlay_title').html(title);
var d = content.split("---").join('"');
d = d.split("===").join(' ');
$('#streetLayer').html(d);
//document.getElementById('streetLayer').innerHtml = content;
}
function showfulloverlay_p2p_result_detailed_list(content){
$('#fulloverlay_p2p_result_detailed_list').modal('show');
var d = content.split("---").join('"');
d = d.split("===").join(' ');
$('#fulloverlay_p2p_result_detailed_list_content').html(d);
//document.getElementById('streetLayer').innerHtml = content;
}
function showoverlay(title,url){
return;
//document.getElementById("overlayframe").innerHTML="";
//document.getElementById("overlaytitle").innerHTML=title;
//document.getElementById("overlayframe").src=url;
//$('#fulloverlay').modal('show');
}
function showweb(link){
window.open(link,'_blank');
}
function showlink(b){
if(b==0)
window.open(kmblink,'_blank');
else
window.open(nwfblink,'_blank');
hidepopup();
}
function showheadway(i){
url=callweb("getheadway.php?i="+i);
var aaa = url.split("|");
debug(url);
if(aaa.length>1){
kmblink=aaa[0];
nwfblink=aaa[1];
setpopupcontent(4);
showpopup();
}else{
window.open(url,'_blank');
}
}
function showppcctv(){
ppresult3 = document.getElementById("infobox").innerHTML;
showinfobox("ppcctv.php");
}
function backtoppresult3(){
document.getElementById("infobox").innerHTML = ppresult3;
}
function backtoppresult2(){
document.getElementById("infobox").innerHTML = ppresult2;
}
function googlemap_initialize(lat, lon) {
var latlng = new google.maps.LatLng(lat, lon);
var objRequest = {
travelMode: google.maps.TravelMode.DRIVING,
origin: latlng,
destination: latlng,
unitSystem: google.maps.UnitSystem.METRIC
};
var objDS = new google.maps.DirectionsService();
objDS.route(objRequest, function (objResult, intStatus) {
if (intStatus == google.maps.DirectionsStatus.OK) {
if (google.maps.geometry.spherical.computeDistanceBetween(latlng, objResult.routes[0].legs[0].steps[0].path[0]) <= 100){
gsm_core(objResult.routes[0].legs[0].steps[0].path[0], latlng);
}else{
gsm_core(latlng, latlng);
}
}
});
}
function gsm_core(latlng, targetPovLatlon) {
var streetViewService = new google.maps.StreetViewService();
var STREETVIEW_MAX_DISTANCE = 100;
streetViewService.getPanoramaByLocation(latlng, STREETVIEW_MAX_DISTANCE, function (streetViewPanoramaData, status) {
if (status === google.maps.StreetViewStatus.ZERO_RESULTS) {
if (lang==0){
alert("對不起,選取的地點100米範圍內無街景資料。");
}else if(lang==1){
alert("Sorry, the chosen location does not contains any street view data within proximity of 100 meters.");
}else{
alert("对不起,选取的地点100米范围内无街景资料。");
}
return -1;
}
if (status === google.maps.StreetViewStatus.OK) {
var myOptions = {
zoom: 8,
center: streetViewPanoramaData.location.latLng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var gmap = new google.maps.Map(document.getElementById("streetLayer"),
myOptions);
var panoramaOptions = {
position: latlng,
imageDateControl: true,
pov: {
heading: google.maps.geometry.spherical.computeHeading(latlng, targetPovLatlon), pitch: 0, zoom: 1
}
};
var panorama = new google.maps.StreetViewPanorama(document.getElementById("streetLayer"), panoramaOptions);
gmap.setStreetView(panorama);
var svlayer = document.getElementById('streetLayer');
svlayer.style.visibility = "visible";
//svlayer.style.width = "80%";
$.ajax({
url: "increment-street-view-counter.php",
contentType: "application/x-www-form-urlencoded;charset=ISO-8859-15",
tryCount : 0,
retryLimit : 3,
error : function(xhr, textStatus, errorThrown ) {
this.tryCount++;
if (this.tryCount <= this.retryLimit) {
$.ajax(this);
return;
} else {
if (errorThrown.indexOf("data-error") > -1) {
if (console)
showlog("Something wrong with SQL");
}
}
},
success: function( data , textStatus, xhr) {
if (data.indexOf("success") == -1) {
this.error(xhr, textStatus, "data-error");
}
}
});
}else{
alert('Google Street View not available');
}
});
}
function layerclick(layer,item,event){
disabledEventPropagation(event);
var id = "layer"+layer+"_"+item;
var obj = document.getElementById(id);
if(obj){
var info = obj.innerHTML;
if(info==''){
obj.innerHTML='';
if(layer==1)
layermark1[item]=1;
else
layermark2[item]=1;
}else{
obj.innerHTML='';
if(layer==1)
layermark1[item]=0;
else
layermark2[item]=0; }
}
showtraffic();
}
function getrafficinfo(mode){
makeRequest("loadtrafficinfo.php?mode="+mode+"&lang=TC&color="+colorcode,'gocatbox');
}
function play(link1,link2){
var twoMinuteMessage = "為了讓更多使用者能使用此項網上直播服務,每名使用者進入本頁兩分鐘後,交通直播便會自動停止。此時,使用者可再次選擇所需的網上直播。";
if (PluginDetect.getVersion("Flash") != null){
$( "#player" ).html('');
var flash=link2;
var params='src='+flash+'&streamType=live&loop=false&autoPlay=true&playButtonOverlay=false&controlBarAutoHide=true&poster=images/play.png&clipEndTime=60';
$( "#player" ).append(' ');
setTimeout(function(){ $( "#player" ).html(twoMinuteMessage); }, 120000);
}else{
$( "#player" ).html('');
var video = document.getElementById('videolink');
video.addEventListener('click',function() {
video.play();
setTimeout(function(){ $( "#player" ).html(twoMinuteMessage); }, 120000);
},false);
}
}
function traninfo(no){
if(no==1){
showinfobox("tranmtr.php");
}else if(no==2){
showroutelistsearch('BALL');
}else if(no==3){
showinfobox("tranlrt.php");
}else if(no==4){
showroutelistsearch('GBUS');
}else if(no==5){
showinfobox("tranferry.php");
}else if(no==6){
showtranweb("TRAM");
}else if(no==7){
showinfobox("trantaxi.php");
}else if(no==8){
showinfobox("tranrmb.php");
}
}
function showtranweb(code){
var s = callweb("trandata.txt");
var aaa = s.split("\n");
for(var i=0; i768) return;
var obj=document.getElementById("leftpanel");
var tbut=document.getElementById("showmapbuttotton");
if(obj.style.display=="none"){
tbut.innerHTML=lmap;
obj.style.display="block";
}else{
tbut.innerHTML=lback;
obj.style.display="none";
}
goresizex();
}
function hideleftpanel(){
var obj=document.getElementById("leftpanel");
var x = screensize("W");
if(x<768){
obj.style.display="none";
var tbut=document.getElementById("showmapbuttotton");
tbut.innerHTML=lback;
}
}
function showleftpanel(){
var obj=document.getElementById("leftpanel");
obj.style.display="block";
var tbut=document.getElementById("showmapbuttotton");
tbut.innerHTML=lmap;
}
function fitmap(){
var extent = stopSource.getExtent();
//map.getView().fit(extent, { duration: 1000 });
map.getView().fit(extent, map.getSize(), { duration: 250 });
}
function fitmapSE(){
var extent = vectorSource.getExtent();
//map.getView().fit(extent, { duration: 1000 });
map.getView().fit(extent, map.getSize(), { duration: 250});
}
var pplist = [];
function showoption(no){
var obj = document.getElementById("ppoption"+no);
var box = document.getElementById("optionbox");
box.innerHTML = "..";
debug(jQuery(obj).offset().left);
var pos=jQuery(obj).offset().left;
box.style.left=(pos+2)+"px";
box.style.display="block";
if(pplist[no]==undefined){
pplist[no] = callweb("ppoption.php?n="+no);
}
box.innerHTML = pplist[no];
}
function hideppoption(){
var box = document.getElementById("optionbox");
box.style.display="none";
}
function ppitemselect(no,option,str){
hideppoption();
var obj = document.getElementById("ppoption"+(no+1));
obj.innerHTML = str+'
';
if(no==0) setCookie("PPDIST",option);
if(no==1) setCookie("PPSERV",option);
if(no==2) setCookie("PPFARE",option);
if(no==3){
setCookie("PPTRAN",option);
showinfobox("goppsearch.php?sort=0")
}
}
function getDistanceFromLatLonInKm(lat1,lon1,lat2,lon2) {
var R = 6371; // Radius of the earth in km
var dLat = deg2rad(lat2-lat1); // deg2rad below
var dLon = deg2rad(lon2-lon1);
var a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2)
;
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c; // Distance in km
return d;
}
function deg2rad(deg) {
return deg * (Math.PI/180)
}
function showaudiobardirect(str,event){
var url="getmp3.php?s="+encodeURI(str)+"&r"+sysseq;
playaudio("D",event,url);
sysseq++;
}
function showaudiobar(code,event){
var url="getmp3.php?c="+code+"&r"+sysseq;
playaudio(code,event,url);
sysseq++;
}
function playaudio(code,event,url){
var obj = document.getElementById('audiobar');
obj.style.display="block";
var audioEl = document.getElementById("audioTag");
var src = document.getElementById("audiosrc");
audioEl.controls=false;
audioEl.addEventListener('ended', hideaudiobar);
src.src=url;
audioEl.load();
audioEl.play();
disabledEventPropagation(event);
}
function audioctrl(code,event){
var audioEl = document.getElementById("audioTag");
if(code=='P')
audioEl.pause();
if(code=='S'){
hideaudiobar();
audioEl.pause();
}
if(code=='A'){
audioEl.play();
}
}
function hideaudiobar(){
document.getElementById('audiobar').style.display="none";
}
function dummygosetting(code,option){
}
function gosetting(code,option){
if(code.substring(0,1)=="*"){
if(code=="*FONT"){
document.location.href="index.php?fsize="+option;
}
if(code=="*LANG"){
if(option==0) document.location.href="index.php?golang=EN";
if(option==1) document.location.href="index.php?golang=TC";
if(option==2) document.location.href="index.php?golang=SC";
}
}else{
setCookie(code,option);
if(code=="PPSERV" && option==1) setCookie("PPTRAN",0);
showmenu(5);
}
}
function startnearby(fromQr){
cleartraffic();
sys_nearby=1;
if (fromQr!='Y'){
CircleLayer.setVisible(true);
onMoveEnd(null);
}
}
function stopnearby(){
sys_nearby=0;
CircleLayer.setVisible(false);
}
function togglenearby(){
var obj = document.getElementById('nearbybut');
if(sys_nearby==0){
startnearby('');
}else{
stopnearby();
}
}
function gonearby(dist){
sys_nearby_radius=dist;
onMoveEnd(null);
}
var bmcode="";
function editbookmark(code,str,event){
bmcode=code;
lastname=str;
setpopupcontent(5);
showpopup();
disabledEventPropagation(event);
}
function deletebookmark(){
makeRequest("godeletebookmark.php?c="+bmcode,"dummydiv");
}
function updatebookmark(){
var bmname = document.getElementById("fbookmark").value;
if(bmname=="") return;
makeRequest("goupdatebookmark.php?c="+bmcode+"&n="+encodeURI(bmname),"dummydiv");
}
//old js
var actioncode = ' ';
var p2pbookmark_info = ' ';
var searchcount=0;
var stack = new Array(); //record search result
var tmpsmaker="";
var tmpemaker="";
var mapstartlat=0.0;
var mapstartlon=0.0;
var mapendlat=0.0;
var mapendlon=0.0;
var mapstartname = "";
var mapendname = "";
var inforoutenumber1 = "";
var inforoutenumber2 = "";
var tmpstr1="";
var tmpstr2="";
var abl=false;
var abl2=false;
var abl3=false;
var abl6=false;
var tabfromfield=false;
var lasttab=0;
var bookmode=0;
var hotspottype = [];
var refreshIntervalId = null;
var topboxheight = 0;
var currentlist=0;
var ssmar="startpoint-f.png";
var eemar="endpoint-f.png";
var oldpdf="";
var selectdate="";
var selectdatelab="";
var selectdateindex=0;
var processingnearby=0;
var nearbystop="";
var stopselect="";
var tstopselect="";
var shareinfo="";
var variantcount=0;
var pdfid=0;
var pdfroute="";
var locbookmark = "";
var nearbymode=true;
var currentloc="";
var currentloc_mode="";
var selectedcell="";
var currentmenu=2;
var pdfname='';
var pdfnamex='';
function showpoi(){
if(true) return;
clearmarkerswithttl('xxxxxx');
var s="";
if(hotspottype[1]==1)
s=s+"Leisure";
if(hotspottype[2]==1)
s=s+"Shopping";
if(hotspottype[3]==1)
s=s+"Exhibitions";
makeRequest('gethotspotmap.php?t='+s+'&c=1','dummydiv');
}
function googlemap_initialize(lat, lon){
var latlng = new google.maps.LatLng(lat, lon);
//alert(lat + ', ' + lon);
var streetViewService = new google.maps.StreetViewService();
var STREETVIEW_MAX_DISTANCE = 100;
streetViewService.getPanorama({location: latlng, radius: STREETVIEW_MAX_DISTANCE, source: google.maps.StreetViewSource.OUTDOOR}, function (streetViewPanoramaData,status) {
if (status === google.maps.StreetViewStatus.OK)
{
// ok
//alert('existed');
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var gmap = new google.maps.Map(document.getElementById("streetLayer"),
myOptions);
var panoramaOptions = {
position: latlng,
pov: {
heading: 34,
pitch: 10,
zoom: 1
}
};
var panorama = new google.maps.StreetViewPanorama(document.getElementById("streetLayer"), panoramaOptions);
panorama.setPano(streetViewPanoramaData.location.pano);
gmap.setStreetView(panorama);
document.getElementById('streetLayerBackground').style.visibility = "visible";
var svlayer = document.getElementById('streetLayer');
svlayer.style.visibility = "visible";
svlayer.style.width = "80%";
document.getElementById('streetLayerClose').style.visibility = "visible";
}
else
{
alert('Google Street View not available');
}
});
}
function showGoogleStreeView(){
//document.getElementById('streetFrame').reload(true);
document.getElementById('streetLayerBackground').style.visibility = "visible";
document.getElementById('streetLayer').style.visibility = "visible";
}
function closeGoogleStreeView(){
//document.getElementById('streetFrame').reload(true);
document.getElementById('streetLayerBackground').style.visibility = "hidden";
var svlayer = document.getElementById('streetLayer');
svlayer.style.visibility = "hidden";
svlayer.style.width = "0%";
document.getElementById('streetLayerClose').style.visibility = "hidden";
}
var geteta_ref = 0;
function showeta_bak(stopid, rdv, seq, bound){
ajaxindex++;
makeRequestref('auto_a03391056d25441eabde7ea136d5de59.php?stopid='+stopid+'&rdv='+rdv+'&seq='+seq+'&bound='+bound+'&l='+lang,'popupboxlist', ajaxindex);
}
function showeta(){
//-----Check call recaptcha or not------
if (recaptcha_check_called == false) {
makeRequest("checkCall.php?type=eta", "dummydiv");
return;
}
recaptcha_check_called = false;
//-----Origin code-----
var tmpref = ++ajaxindex;
geteta_ref = tmpref;
makeRequestref('auto_a03391056d25441eabde7ea136d5de59.php?l='+lang,'popupboxlist', tmpref);
}
function showprintout(code){
document.getElementById('printout').style.visibility = "visible";
makeRequest('printout.php?code='+code+'&l='+lang,'printout');
}
function hideprintout(){
document.getElementById('printout').style.visibility = "hidden";
}
function shownotice_stop(stopid){
makeRequest('getnotice_stop.php?stopid='+stopid+'&l='+lang+'<ab='+lasttab,'popupboxlist');
}
function showroute_eta_extra_bak(stopid){
makeRequest('auto_3ad5f9f690c44c3d85b616ad610ed193.php?stopid='+stopid+'&l='+lang,'popupboxlist');
}
function showroute_eta_extra(stopid){
//-----Check call recaptcha or not------
if (recaptcha_check_called == false) {
makeRequest("checkCall.php?type=route&stopid=" + stopid, "dummydiv");
return;
}
recaptcha_check_called = false;
//-----Origin code-----
makeRequest('auto_3ad5f9f690c44c3d85b616ad610ed193.php?l='+lang,'popupboxlist');
}
function showblank(){
makeRequest('blank.php','popupboxlist');
}
function restartPopupboxlist()
{
document.getElementById('popupboxlist').style.backgroundColor = themecolor;
document.getElementById('popupboxlist').style.overflow="auto";
}
function shownotice(r){
loadbox2("boxtitle2.php?t=notice&l="+lang,"custnotice.php?l="+lang+"&route="+r+"&route2="+r2+"&syscode=3583452268b3160659c253d165395b3031cbb8fc16");
}
function shownotice2(r,r2){
loadbox2("boxtitle2.php?t=notice&l="+lang,"custnotice.php?l="+lang+"&route="+r+"&route2="+r2+"&syscode=35834579186481e926094e3ff2ab65cdf1bbd119b1");
}
// function popupNotice(r)
// {
// makeRequest("specialNotice.php?l="+lang+"&route="+r,'dummydiv');
// }
function popupNotice()
{
var r = arguments[0];
var r2 = arguments[1];
var click = arguments[2] == 1 ? 1 : 0;
if (r2 == '' || r2 === undefined)
{
makeRequest("specialNotice.php?click="+click+"&l="+lang+"&route="+r+"&syscode=3583453242c7c73104cd73f87749a20bb6c1789de9",'dummydiv');
}
else
{
makeRequest("specialNotice.php?click="+click+"&l="+lang+"&route="+r+"&route2="+r2+"&syscode=35834524110dd8651bd8be03dc981425361fe10f7e",'dummydiv');
}
}
function hotspotselect(n){
if(hotspottype[n]==0)
hotspottype[n]=1;
else
hotspottype[n]=0;
if(hotspottype[1]==0)
document.getElementById('hot1').src='tdummy.png';
else
document.getElementById('hot1').src='Ok-icon.png';
if(hotspottype[2]==0)
document.getElementById('hot2').src='tdummy.png';
else
document.getElementById('hot2').src='Ok-icon.png';
if(hotspottype[3]==0)
document.getElementById('hot3').src='tdummy.png';
else
document.getElementById('hot3').src='Ok-icon.png';
showpoi();
}
function zoomclick(event){
pos_x = event.clientX;
pos_y = event.clientY;
//alert(pos_x+" "+pos_y);
if(pos_x>405 && pos_x<425 && pos_y>120 && pos_y<216){
z = 18 - Math.round((pos_y -120 - 5) / 11);
map.zoomTo(z);
}
}
function stopauto(e,input,div){
var keynum;
var skey;
var tmpstr="";
var type="";
var i=0;
if(window.event) // IE
{
keynum = e.keyCode;
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which;
}
if(keynum==8||keynum==46){
if(input=="sloc"){
var arr=tmpstr1.split('|*|');
$('#sloc').unautocomplete();
}
else if(input=="eloc"){
var arr=tmpstr2.split('|*|');
$('#eloc').unautocomplete();
}
else{
var arr=tmpstr1.split('|*|');
$('#skey').unautocomplete();
}
skey=document.getElementById(input);
if(countchar(skey.value,':')==4&&skey.value.charAt(skey.value.length-1)!=":"){
skey.value=skey.value.substring(0,skey.value.lastIndexOf(":")+1);
for(i=0;i0.0&&mapstartlon>0.0){
addcustommarker(getlonlat(mapstartlon,mapstartlat),ssmar,36,80,-20,-80);
document.getElementById("slat").value=mapstartlat;
document.getElementById("slon").value=mapstartlon;
}
reordermarker();
map.panTo(ll);
*/
abl3=false;
});
}
function getautodata2(){
//var x=document.getElementsByName("stype");
$('#sloc').unautocomplete();
var link;
link="bsearch_p3.php?l="+lang;
$("#sloc").autocomplete(link, {
width: 280,
highlight: false,
scroll: true,
scrollHeight: 300,
matchContains: true,
max: 100,
minChars:2
}).result(function(event, data, formatted) {
var result1=document.getElementById("sloc");
result1.value=data[1];
mapstartname=data[1];
var result2=document.getElementById("slat");
result2.value=data[2];
var result3=document.getElementById("slon");
result3.value=data[3];
mapstartlat=parseFloat(data[2]);
mapstartlon=parseFloat(data[3]);
startlat=mapstartlat;
startlon=mapstartlon;
startname=mapstartname;
gomenu(2,1);
mappanto(startlon,startlat);
/*
alert(mapstartlat+" "+mapstartlon);
clearmarkers();
clearCsNearbyMarker();
addcustommarker(ll,ssmar,36,80,-20,-80);
if(mapendlat>0.0&&mapendlon>0.0){
addcustommarker(getlonlat(mapendlon,mapendlat),eemar,36,80,-20,-80);
document.getElementById("elat").value=mapendlat;
document.getElementById("elon").value=mapendlon;
}
reordermarker();
map.panTo(ll);
*/
abl2=false;
});
}
function getautodata1(){
//var x=document.getElementsByName("stype");
$('#skey').unautocomplete();
var link;
link="bsearch_p3.php?l="+lang;
$("#skey").autocomplete(link, {
width: 280,
highlight: false,
scroll: true,
scrollHeight: 300,
matchContains: true,
max: 100,
minChars:2
}).result(function(event, data, formatted) {
var result1=document.getElementById("skey");
result1.value=data[1];
var result2=document.getElementById("lat");
result2.value=data[2];
var result3=document.getElementById("lon");
result3.value=data[3];
var tlat=parseFloat(data[2]);
var tlon=parseFloat(data[3]);
mappanto(tlon,tlat);
abl2=false;
});
}
function getautodata(type,div) {
if(div=="autocom"){
if(document.getElementById("autocom2")){
autooff("autocom2");
}
}
else{
if(document.getElementById("autocom")){
autooff("autocom");
}
}
var skey="";
var cnt;
var tmpstr;
var arr;
var ibottom = 0;
if(type=="s"){
skey =document.getElementById('sloc').value;
arr=tmpstr1.split('|*|');
tmpstr=arr[arr.length-2];
ibottom = findPosY(document.getElementById('ppstart'))+38;
}else if(type=="e"){
skey =document.getElementById('eloc').value;
arr=tmpstr2.split('|*|');
tmpstr=arr[arr.length-2];
ibottom = findPosY(document.getElementById('ppend'))+38;
}else{
skey =document.getElementById('skey').value;
arr=tmpstr1.split('|*|');
tmpstr=arr[arr.length-2];
ibottom = findPosY(document.getElementById('nearbybox'))+34;
}
if(skey!=""){
if(!tmpstr){
tmpstr="";
}
if(tmpstr.indexOf("|n")<=-1){
tmpstr+="|n";
}
if(tmpstr.length>2){
//document.getElementById('testing').value="IN";
c_autolist(tmpstr,div,true);
var list = document.getElementById(div);
list.style.top = ibottom+'px';
list.style.display = "block";
}
}else{
if(type=="s"){
tmpstr1="";
}else if(type=="e"){
tmpstr2="";
}else{
tmpstr1="";
}
//document.getElementById('test333').value=2;
var list = document.getElementById(div);
list.innerHTML = '...';
makeRequest("getlocation.php?k="+skey+"&t="+type+"&div="+div+"&lang="+lang+"<ab="+lasttab,div);
list.style.top = ibottom+'px';
list.style.display = "block";
}
}
function findPosY(obj)
{
var curtop = 0;
if(obj.offsetParent)
while(1)
{
curtop += obj.offsetTop;
if(!obj.offsetParent)
break;
obj = obj.offsetParent;
}
else if(obj.y)
curtop += obj.y;
return curtop;
}
function countchar(str,sec){
var arr=str.split(sec);
return arr.length;
}
function autooff(div){
var list = document.getElementById(div);
list.style.display="none";
list.innerHTML ='';
}
function clearstr(i,div,type){
var input=document.getElementById(i);
var str1;
var str2;
if(i=="sloc"){
str1="請選擇或輸入起點";
if(lang==1){
str1="Please select or input the origin";
}
if(lang==2){
str1="请选择或输入起点";
}
input.value=str1;
input.style.color='#707070';
mapstartlat=0.0;
mapstartlon=0.0;
mapstartname="";
document.getElementById('slat').value="";
document.getElementById('slon').value="";
clearmarkers();
clearCsNearbyMarker();
tmpstr1="";
if(mapendlat>0.0&&mapendlon>0.0){
addcustommarker(getlonlat(mapendlon,mapendlat),eemar,36,80,-20,-80);
document.getElementById("elat").value=mapendlat;
document.getElementById("elon").value=mapendlon;
}
}
else if(i=="eloc"){
str2="請選擇或輸入終點";
if(lang==1){
str2="Please select or input the destination";
}
if(lang==2){
str2="请选择或输入终点";
}
input.value=str2;
input.style.color='#707070';
mapendlat=0.0;
mapendlon=0.0;
mapendname="";
document.getElementById('elat').value="";
document.getElementById('elon').value="";
tmpstr2="";
clearmarkers();
clearCsNearbyMarker();
if(mapstartlat>0.0&&mapstartlon>0.0){
addcustommarker(getlonlat(mapstartlon,mapstartlat),ssmar,36,80,-20,-80);
document.getElementById("slat").value=mapstartlat;
document.getElementById("slon").value=mapstartlon;
}
}
else{
str1="請選擇或輸入地點";
if(lang==1){
str1="Please select or input the location";
}
if(lang==2){
str1="请选择或输入地点";
}
input.value=str1;
input.style.color='#707070';
tmpstr1="";
}
abl=false;
abl2=false;
abl3=false;
abl6=false;
}
function c_autolist(str,div,adstr){
var list = document.getElementById(div);
var arr=str.split('|');
var arr2;
var skey;
var tmpstr;
if(arr[5]=="s"){
skey =document.getElementById('sloc');
tmpstr=tmpstr1;
}
else if(arr[5]=="e"){
skey =document.getElementById('eloc');
tmpstr=tmpstr2;
}
else{
skey =document.getElementById('skey');
tmpstr=tmpstr1;
//document.getElementById('testing').value=tmpstr;
}
if(arr[2]<5){
if(arr[6]!="n"){
// skey.value+=arr[0]+":";
skey.value = arr[0];
//skey.focus();
}
if(arr[5]=="s"&&adstr==false){
tmpstr1+=str+"|*|";
}
else if(arr[5]=="e"&&adstr==false){
tmpstr2+=str+"|*|";
}
else{
if(adstr==false){
tmpstr1+=str+"|*|";
}
//document.getElementById('test333').value=tmpstr1;
}
//document.getElementById('test333').value=tmpstr;
list.innerHTML = '...';
//document.getElementById('testing2').value=str;
makeRequest("getlocation.php?k="+arr[1]+"&l="+arr[2]+"&t="+arr[5]+"&div="+div+'&lang='+lang+'<ab='+lasttab,div);
}
else if(arr[2]>=5){
if((countchar(tmpstr,'|'))>6){
// skey.value=skey.value.substring(0,skey.value.lastIndexOf(":")+1)+arr[0];
skey.value = arr[0];
//alert(skey.value.lastIndexOf(":"));
}
else{
// skey.value+=arr[0];
skey.value = arr[0];
if(arr[5]=="s"){
tmpstr1+="";
}
else if(arr[5]=="e"){
tmpstr2+="";
}
else{
tmpstr1+="";
}
//document.getElementById('test333').value=tmpstr;
}
//document.getElementById('tempstr').value=tmpstr;
}
if(arr[5]=="s"){
mapstartname=skey.value;
document.getElementById('slat').value=arr[3];
document.getElementById('slon').value=arr[4];
if(arr[2]==5){
mapstartlat=parseFloat(arr[3]);
mapstartlon=parseFloat(arr[4]);
startlat=mapstartlat;
startlon=mapstartlon;
startname=mapstartname;
gomenu(2,1);
mappanto(startlon,startlat);
list.style.display = "none";
abl=false;
}
}else if(arr[5]=="e"){
mapendname=skey.value;
document.getElementById('elat').value=arr[3];
document.getElementById('elon').value=arr[4];
if(arr[2]==5){
mapendlat=parseFloat(arr[3]);
mapendlon=parseFloat(arr[4]);
endlat=mapendlat;
endlon=mapendlon;
endname=mapendname;
gomenu(2,1);
mappanto(endlon,endlat);
list.style.display = "none";
abl=false;
}
}else{
if(arr[2]==5){
clearmarkers();
clearCsNearbyMarker();
map.zoomTo(16);
var lon = parseFloat(arr[4]);
var lat = parseFloat(arr[3]);
mappanto(lon,lat);
document.getElementById("lat").value=arr[3];
document.getElementById("lon").value=arr[4];
document.getElementById("autocom").style.display="none";
abl=false;
}
}
}
var lat=22.290000
var lon=114.1800
var zoom=10
var map; //complex object of type OpenLayers.Map
var alat=-0.0001935197;
var alon=0.0000697374;
var layerCenterMap;
//var markersize = new OpenLayers.Size(49,32);
//var markeroffset = new OpenLayers.Pixel(-17, -markersize.h);
var checkcnt=0;
var sysmode=-1;
var errorcnt=0;
var ajaxindex=0;
var mapclicklat=0.0;
var mapclicklon=0.0;
var templocname="";
var chmenumode=0;
var controls;
var movingmarker = null;
var smarker = null;
var emarker = null;
var sn=0;
var hlstop="";
var lastnearbylat = "";
var lastnearbylon = "";
var ssid = "679951e4c4849";
//var lang=0;
//Initialise the 'map' object
function init() {
alert("hello");
mapinit();
map.events.register("click", map, function(e) {
hiderightclickbox();
var ll1= map.getLonLatFromViewPortPx(e.xy);
if(syspopup=="A"){
map.panTo(ll1);
var ll2= ll1.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
tlat=ll2.lat-alat;
tlon=ll2.lon-alon;
}else{
mwypopupremove();
map.panTo(ll1);
var ositem=document.getElementById(hlstop);
if(ositem){
ositem.style.backgroundColor='';
hlstop='';
}
}
});
map.events.register("mousemove", map, function(e) {
//hiderightclickbox();
if(emarker!=null && movingmarker==emarker){
var opx = map.getLayerPxFromViewPortPx(e.xy) ;
emarker.moveTo(opx) ;
}
});
map.events.register("moveend",map,function(e){
if(sysmode==0 && syspopup=="A"){
nearby();
hidep2pmenu();
}
});
map.events.register("movestart", map, function(e) {
if(sysmode==0 && syspopup=="A"){
//document.getElementById('redcross').style.visibility = "visible";
}
});
map.div.oncontextmenu = function noContextMenu(evt) {
var str,str1,str2;
if (true || OpenLayers.Event.isRightClick(evt)){
var mx=0; var my=0;
if(document.all){
mx=window.event.clientX;
my=window.event.clientY;
}else{
mx= evt.pageX;
my= evt.pageY;
}
var posx = (mx-4)+"px"; var posy = (my-4)+"px";
var atts = document.getElementById("rightclickoption");
var ll1= map.getLonLatFromViewPortPx(new OpenLayers.Pixel(mx-386,my-24));
var ll2= ll1.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
mapclicklat=ll2.lat-alat;
mapclicklon=ll2.lon-alon;
atts.oncontextmenu=function(){return false;};
if (lang==0){
str="設為起點";
str1="設為終點";
str2="加至我的書籤";
}
else if(lang==1){
str="Set Origin";
str1="Set Destination";
str2="Add Bookmark";
}
else{
str="设为起点";
str1="设为终点";
str2="加至我的书签";
}
var s = '';
s+='';
s+='';
s+='';
s+='';
s+='
'+str+'
'+str1+'
'+str2+'
';
atts.innerHTML = s;
atts.style.position='absolute';
atts.style.top=posy;
atts.style.left=posx;
atts.style.display='block';
//Event.stop(evt);
}
return false;
};
hotspottype[0]=hotspottype[1]=hotspottype[2]=hotspottype[3]=1;
showpoi();
}
function rmenumousedown(){
return false;
}
function hiderightclickbox(){
var atts = document.getElementById("rightclickoption");
if(atts.style.top.substring(0,1)!='-'){
atts.style.top="-300px";
}
}
function shownearbybookmark(name,lat,lon){
clearmarkers();
clearCsNearbyMarker();
var ll = getlonlat(lon,lat);
addmarker(ll,"B");
map.panTo(ll);
var sss = document.getElementById("skey");
if(sss){
sss.value=name;
}
}
function showbookmarkonmap(lat,lon){
clearmarkers();
clearCsNearbyMarker();
var ll = getlonlat(lon,lat);
addcustommarker(ll,"marker-blue.png",49,32,-8,-32,"Dummy");
mappanto(ll[0],ll[1]);
showmarker();
}
function addbookmark(lat,lon,name){
name=encodeURIComponent(name);
if(lat!=""&&lon!=""&&name!="")
loadbox2("boxtitle2.php?t=bookmark"+"&l="+lang+"<ab="+lasttab,"newlocationbookmark.php?lat="+lat+"&lon="+lon+"&name="+name+"&l="+lang+"<ab="+lasttab);
}
function callweb(weburl){
var url = weburl;
var result = "";
$.ajax({
url: url,
type: 'GET',
async: false,
cache: false,
timeout: 30000,
error: function(){
alert("Error to connect server!");
},
success: function(msg){
result = msg;
}
});
return result;
}
function gorightclick(mode){
switch(mode){
case 0:
startlat=mapclicklat;
startlon=mapclicklon;
mapstartlat=mapclicklat;
mapstartlon=mapclicklon;
var rrr = callweb("get_rgeocode.php?lat="+mapclicklat+"&lon="+mapclicklon+"&l="+lang);
mapstartname = rrr;
if (locbookmark != "") mapstartname = locbookmark;
startname = mapendname;
gomenu(2,1);
//mapstartname=mapclicklat.toPrecision(8)+","+mapclicklon.toPrecision(9);
break;
case 1:
endlat=mapclicklat;
endlon=mapclicklon;
mapendlat=mapclicklat;
mapendlon=mapclicklon;
var rrr = callweb("get_rgeocode.php?lat="+mapclicklat+"&lon="+mapclicklon+"&l="+lang);
mapendname = rrr;
if (locbookmark != "") mapendname = locbookmark;
endname = mapendname;
gomenu(2,1);
//mapendname=mapclicklat.toPrecision(8)+","+mapclicklon.toPrecision(9);
break;
case 2:
var rrr = callweb("get_rgeocode.php?lat="+mapclicklat+"&lon="+mapclicklon+"&l="+lang);
bookmarkname = rrr;
addbookmark(mapclicklat,mapclicklon, bookmarkname);
clearmarkers();
clearCsNearbyMarker();
removeline();
break;
}
hiderightclickbox();
if(mode==0 || mode==1){
chmenumode=1;
gomenu(2);
if(mapendlat>mapstartlat){
if(mapendlat>0.0){
var ll = getlonlat(mapendlon,mapendlat);
//emarker = addcustommarker(ll,"endpoint_tc.png",84,31,-33,-31);
emarker = addcustommarker(ll,eemar,36,80,-20,-80);
emarker.events.register("mousedown", emarker, function(e) {
movingmarker=emarker;
});
emarker.events.register("mouseup", emarker, function(e) {
movingmarker=null;
});
emarker.events.register("mouseout", emarker, function(e) {
movingmarker=null;
});
}
if(mapstartlat>0.0){
var ll=getlonlat(mapstartlon,mapstartlat);
emarker = addcustommarker(ll,ssmar,36,80,-20,-80);
m.events.register("click", m, function(e) {
movingmarker=m;
movingmarkerxy=e.xy;
});
}
reordermarker();
}else{
if(mapstartlat>0.0){
var ll=getlonlat(mapstartlon,mapstartlat);
var m = addcustommarker(ll,ssmar,36,80,-20,-80);
m.events.register("click", m, function(e) {
movingmarker=m;
movingmarkerxy=e.xy;
});
}
if(mapendlat>0.0){
var ll=getlonlat(mapendlon,mapendlat);
var m = addcustommarker(ll,eemar,36,80,-20,-80);
m.events.register("click", m, function(e) {
movingmarker=m;
movingmarkerxy=e.xy;
});
}
reordermarker();
}
}
loclocbookmark = "";
}
function showstartendpoints(){
if(mapstartlat>0.0){
var ll=getlonlat(mapstartlon,mapstartlat);
console.log(mapstartlon);
var m = addcustommarker(ll,ssmar,36,80,-10,-80,lstartpo);
}
if(mapendlat>0.0){
var ll=getlonlat(mapendlon,mapendlat);
var m = addcustommarker(ll,eemar,36,80,-10,-80,lendpo);
}
//reordermarker();
showmarker();
}
var markersize = new Array(1000);
function addcustommarker(ll,png,sizex,sizey,offx,offy,name){
var lng=parseFloat(ll[0]);
var lat=parseFloat(ll[1]);
var increment = 1;
var lastpoint = -1;
var info = name+"||C||"+lat+"||"+lng+"||"+png+"||"+sizex+"||"+sizey+"||"+offx+"||"+offy;
if(lastpoint==-1) lastpoint=markercount;
if(sizex==15)
markercodes[lastpoint] = "P";
else
markercodes[lastpoint] = "C";
markerlat[lastpoint] = lat;
markersize[lastpoint] = [sizex,sizey,offx,offy];
markers[lastpoint] = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([lng+alon,lat+alat],'EPSG:4326', 'EPSG:3857')),
name: info
});
amode='pixels';
ax=(-offx)*2;
ay=(-offy);
if(sizex==15){
ax=0.5;
ay=0.5;
amode='fraction';
}
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(({
scale: 1,
anchor: [ax,ay],
anchorXUnits: amode,
anchorYUnits: amode,
opacity: 1,
src: png
}))
});
markers[lastpoint].setStyle(iconStyle);
markercount+=increment;
}
function addstoponmap(stopid,lon,lat,ccode,bsa_seq,name,rdv,bound,eta,altLon,altLat){
name=name+"{"+stopid+"^"+lat+"^"+lon+"^"+bsa_seq+"^"+rdv+"^"+bound+"^"+eta+"^"+altLat+"^"+altLon+"}";
if(ccode=='B')
var mmm = addcustommarker(getlonlat(lon,lat),"xstop.png",40,40,-2,-40,name);
else if(ccode=='S')
var mmm = addcustommarker(getlonlat(lon,lat),"sstop.png",40,40,-2,-40,name);
else if(ccode=='E')
var mmm = addcustommarker(getlonlat(lon,lat),"estop.png",40,40,-2,-40,name);
else if(ccode=='C')
var mmm = addcustommarker(getlonlat(lon,lat),"xstop.png",40,40,-2,-40,name);
else if(ccode=='R')
var mmm = addcustommarker(getlonlat(lon,lat),"sstop.png",40,40,-2,-40,name);
else if(ccode=='G')
var mmm = addcustommarker(getlonlat(lon,lat),"estop.png",40,40,-2,-40,name);
else if(ccode=='Y')
var mmm = addcustommarker(getlonlat(lon,lat),stop_marker,40,40,-2,-40,name);
else
var mmm = addcustommarker(getlonlat(lon,lat),"stop.png",15,15,-7,-7,name);
if(ccode=='S' || ccode=='E')
var mmm = addcustommarker(getlonlat(lon,lat),"dummy.png",15,15,-7,-7,name);
/*
mmm.events.register("click", mmm, function(e){
stopclick1(stopid,lat,lon,bsa_seq,rdv,bound,eta)
});
*/
}
function addstoponmap_near(stopid,lon,lat,ccode,bsa_seq,name,rdv,altLon,altLat){
lon = lon-0;
lat = lat-0;
altLon = altLon - 0;
altLat = altLat - 0;
var temp = '||0||0||0';
var etainfo = stopid.concat(temp);
//makeRequest(\'auto_baa57ea2dd804339a399dfc61c962d42.php?info='.$etainfo.'\',\'dummydiv\')
//var mmm = addmarker(getlonlat(lon,lat),ccode,num,name);
name=name+"|*|["+stopid+"]"+stopid+"|*|"+altLon+"||"+altLat+"|*|";
//alert(name);
if(ccode=='B')
var mmm = addcustommarker(getlonlat(lon,lat),"xstop.png",40,40,-2,-40,name);
else if(ccode=='S')
var mmm = addcustommarker(getlonlat(lon,lat),"sstop.png",40,40,-2,-40,name);
else if(ccode=='E')
var mmm = addcustommarker(getlonlat(lon,lat),"estop.png",40,40,-2,-40,name);
else if(ccode=='C')
var mmm = addcustommarker(getlonlat(lon,lat),"xstop.png",40,40,-2,-40,name);
else if(ccode=='R')
var mmm = addcustommarker(getlonlat(lon,lat),"sstop.png",40,40,-2,-40,name);
else if(ccode=='G')
var mmm = addcustommarker(getlonlat(lon,lat),"estop.png",40,40,-2,-40,name);
else if(ccode=='Y')
var mmm = addcustommarker(getlonlat(lon,lat),stop_marker,40,40,-2,-40,name);
else
var mmm = addcustommarker(getlonlat(lon,lat),"stop.png",15,15,-7,-7,name);
/*
mmm.events.register("click", mmm, function(e){
makeRequest('auto_baa57ea2dd804339a399dfc61c962d42.php?info='+etainfo,'dummydiv')
stopclick1_nearby(stopid,lat,lon)
});
*/
}
var lhotspot = "熱點";
function hotspotonmap(id,lat,lon,cat,name){
lat = lat-0;
lon = lon-0;
var ll = getlonlat(lon,lat);
//var mmm = addmarker(ll,"B");
var img = "";
if (cat=='Leisure')
img='poi_leisure.png';
else if (cat=='Shopping')
img='poi_shopping.png';
else if (cat=='Exhibitions')
img='poi_exhibitions.png';
var name = "*"+name+"{"+id+"^"+lat+"^"+lon;
addcustommarker(getlonlat(lon,lat),img,40,40,-6,-40,name);
}
function hotspotclick(id,tlat,tlon){
var lat=parseFloat(tlat);
var lon=parseFloat(tlon);
var coord = ol.proj.transform([lon, lat], 'EPSG:4326', 'EPSG:3857');
hotspotpopup.setPosition(coord);
makeRequestref('gethotspotresult.php?id='+id+'&lat='+lat+'&lon='+lon+'&l='+lang,'hpopupcontent',ajaxindex);
var z = Math.floor(map.getView().getZoom());
if(z>=10 && z<=18){
var coord2 = ol.proj.transform([lon, lat-difflat[z]], 'EPSG:4326', 'EPSG:3857');
mappantoxy(coord2);
}
hideleftpanel();
}
function hotspotclickdelay(id,lat,lon){
poipopup(getlonlat(lon,lat));
ajaxindex++;
var ositem=document.getElementById(hlstop);
if(ositem){
ositem.style.backgroundColor="";
}
var sitem=document.getElementById(id);
if(sitem){
hlstop=id;
sitem.style.backgroundColor="#FFEA80";
}
var url='gethotspotresult.php?id='+id+'&lat='+lat+'&lon='+lon+'&l='+lang;
setTimeout("makeRequestref('"+url+"','popupcontent',ajaxindex)",1000);
}
/************* Not In Use *************/
function stopclick(id,lat,lon,num,rnum,d,v,altLat,altLon){
fbpopup(getlonlat(lon,lat));
ajaxindex++;
var ositem=document.getElementById(hlstop);
if(ositem){
ositem.style.backgroundColor="";
}
var sitem=document.getElementById(num);
if(sitem){
hlstop=num;
sitem.style.backgroundColor="#FFEA80";
}
makeRequestref('getrouteinstop.php?id='+id+'&lat='+lat+'&lon='+lon+'&r='+rnum+'&d='+d+'&v='+v+'&l='+lang+'&altLat='+altLat+'&altLon='+altLon,'popupcontent',ajaxindex);
document.getElementById('redcross').style.visibility='hidden';
currentlist=0;
}
var latest_stopclick1_time = (new Date()).getTime();
var getrouteinstop_ref = 0;
//function stopclick1(stopid,lat,lon,bsa_seq,rdv,bound){
function stopclick1(stopid,lat,lon,bsa_seq,rdv,bound,eta,altLat,altLon){
//alert('in stopclick1');
if (isBlueTheme){
// alert('it is blue theme' + v_slide_d);
}
if ((new Date()).getTime() - latest_stopclick1_time < 500)
{
//alert( 'too fast');
return;
}
getrouteinstop_ref = ++ajaxindex;
latest_stopclick1_time = (new Date()).getTime();
//alert(latest_stopclick1_time);
tlon = parseFloat(lon)+alon;
tlat = parseFloat(lat)+alat;
var ositem=document.getElementById(hlstop);
if(ositem){
ositem.style.backgroundColor="";
}
var sitem=document.getElementById('slist'+stopid+'-'+bsa_seq);
if(sitem){
hlstop='slist'+stopid+'-'+bsa_seq;
sitem.style.backgroundColor="#FFEA80";
}
makeRequestref('getrouteinstop.php?stopid='+stopid+'&lat='+lat+'&lon='+lon+'&seq='+bsa_seq+'&rdv='+rdv+'&bound='+bound+'&eta='+eta+'&l='+lang+'&ref='+getrouteinstop_ref+
'&altLat='+altLat+'&altLon='+altLon
,'popupcontent',getrouteinstop_ref);
document.getElementById('redcross').style.visibility='hidden';
currentlist=0;
var coord = ol.proj.transform([tlon, tlat], 'EPSG:4326', 'EPSG:3857');
markerpopup.setPosition(coord);
//showmarkerpopupinfo(undefined)
var z = Math.floor(map.getView().getZoom());
if(z>=10 && z<=18){
var coord2 = ol.proj.transform([tlon+difflon[z], tlat-difflat[z]], 'EPSG:4326', 'EPSG:3857');
mappantoxy(coord2);
}
}
// ******** Not in use ********
function stopclick1_nearby(stopid,lat,lon){
fbpopup(getlonlat(lon,lat));
ajaxindex++;
makeRequestref('getrouteinstop_nearby.php?stopid='+stopid+'&lat='+lat+'&lon='+lon+'&l='+lang,'popupcontent',ajaxindex);
document.getElementById('redcross').style.visibility='hidden';
currentlist=0;
}
function panto(lat,lon){
map.panTo(getlonlat(lon,lat));
}
function mapgoto(lat,lon){
var lonlat = getlonlat(lon,lat);
map.setCenter (lonlat, 14);
hidebox2();
}
function nearby(){
currentloc="";
showloading();
clearmarkers();
clearCsNearbyMarker();
removeline();
var ll1= map.getCenter();
var ll2= ll1.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
tlat=ll2.lat-alat;
tlon=ll2.lon-alon;
lastnearbylat = lat;
lastnearbylon = lon;
ajaxindex++;
makeRequestref('getnearbyroute.php?lat='+tlat+'&lon='+tlon+'&l='+lang,'sysitembox',ajaxindex);
setTimeout(function(){ makeRequestref('getnearbystop.php?lat='+tlat+'&lon='+tlon+'&l='+lang,'dummydiv',ajaxindex);}, 1000);
currentlist=0;
currentloc = callweb("get_rgeocode.php?lat="+tlat+"&lon="+tlon+"&l="+lang);
var aaa = document.getElementById('skey');
aaa.value = currentloc;
// map.zoomTo(17);
}
function shownearbystop(r,d,v,lat,lon){
clearmarkers();
clearCsNearbyMarker();
var ll1= map.getCenter();
var ll2= ll1.transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
tlat=ll2.lat-alat;
tlon=ll2.lon-alon;
ajaxindex++;
if(lat!=0,lon!=0){
makeRequestref('getnearbystopinroute.php?lat='+lat+'&lon='+lon+'&r='+r+'&d='+d+'&v='+v,'dummydiv',ajaxindex);
}
else{
makeRequestref('getnearbystopinroute.php?lat='+tlat+'&lon='+tlon+'&r='+r+'&d='+d+'&v='+v,'dummydiv',ajaxindex);
}
}
function getlonlat(lon,lat){
return [lon,lat];
//alert(lon+" "+lat);
//return ol.proj.transform( [lon+alon, lat+alat], 'EPSG:4326', 'EPSG:3857');
}
function callweb(weburl){
var url = weburl;
var result = "";
url = url.replace("'","~SQ~");
url = url.replace('""','~DQ~');
var n = url.indexOf("?");
if (n > 0){
url = url + "&ssid=" + ssid;
}else{
url = url + "?ssid=" + ssid;
}
sn++;
if(url.indexOf("?")>0)
url=url+'&sysid='+sn;
else
url=url+'?sysid='+sn;
$.ajax({
url: url,
type: 'GET',
async: false,
cache: false,
timeout: 30000,
error: function(){
//debug("Error to connect server!");
},
success: function(msg){
result = msg;
}
});
return result;
}
var lastmakerequesturl = "";
function makeRequestref(urlx,id,ref) {
if(id=="sysinfo"){
lastmakerequesturl=urlx;
}
urlx = urlx.replace("'","~SQ~");
urlx = urlx.replace('""','~DQ~');
var n = urlx.indexOf("?");
if (n > 0){
urlx = urlx + "&ssid=" + ssid;
}else{
urlx = urlx + "?ssid=" + ssid;
}
sn++;
var pdf11 = document.getElementById('pdf11');
if(pdf11 && id!="lbox2"){
hidebox2();
}
sn++;
var url="";
if(urlx.indexOf("?")>0)
url=urlx+'&sysid='+sn;
else
url=urlx+'?sysid='+sn;
var http_request = false;
var ts1 = "";
var ts2 = "";
var p=0;
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() {
alertContentsref(urlx,http_request,id,ref); };
http_request.open('GET', url, true);
http_request.send(null);
}
function alertContentsref(urlx,http_request,id,ref) {
if (http_request.readyState == 4 && ajaxindex==ref) {
if (http_request.status == 200) {
var mesg = http_request.responseText;
if(id=="v_ustatus"){
v_ustatus=mesg;
}else{
if(id.substring(0,4)=='txt_'){
document.getElementById(id).value=mesg;
}else{
if (urlx.indexOf('auto_a03391056d25441eabde7ea136d5de59.php'))
{
console.log('>>>>>>>>>>>>>> ' + ref);
}
var checkcnt=0;
/*while(document.getElementById(id) && checkcnt<5){
setTimeout('',500);
checkcnt=checkcnt+1;
}*/
if (urlx.indexOf('auto_a03391056d25441eabde7ea136d5de59.php') > -1 && geteta_ref != ref)
return;
else
document.getElementById(id).innerHTML=mesg;
}
window.scrollTo(0,0);
}
} else {
errorcnt++;
//alert('There was a problem with the ajax request.');
}
}
}
function menu2action(){
if(chmenumode==1 || true){
if(startlat>0.0){
document.ppsearch.sloc.value = Math.round(startlat*1000000)/1000000+','+Math.round(startlon*1000000)/1000000;
startname=convertcharBACK(startname);
document.getElementById('sloc').value=startname;
document.getElementById('sloc').style.color='#000000';
mapstartname=startname;
mapstartlat=startlat;
mapstartlon=startlon;
}
if(endlat>0.0){
document.ppsearch.eloc.value = Math.round(endlat*1000000)/1000000+','+Math.round(endlon*1000000)/1000000;
endname=convertcharBACK(endname);
document.getElementById('eloc').value=endname;
document.getElementById('eloc').style.color='#000000';
mapendname=endname;
mapendlat=endlat;
mapendlon=endlon;
}
}else{
startlon=startlat=endlon=endlat=0.0;
}
chmenumode=0;
if(actioncode=='B' || true){
clearmarkers();
clearCsNearbyMarker();
showstartendpoints();
}
}
function makeRequest(urlx,id) {
if(id=="sysinfo"){
var aaa = urlx.split(".");
if(aaa[0]=="menu2" && lastmakerequesturl=="menu2"){
menu2action();
return;
}
lastmakerequesturl=aaa[0];
}
urlx = urlx.replace("'","~SQ~");
urlx = urlx.replace('""','~DQ~');
var n = urlx.indexOf("?");
if (n > 0){
urlx = urlx + "&ssid=" + ssid;
}else{
urlx = urlx + "?ssid=" + ssid;
}
sn++;
var url="";
if(urlx.indexOf("?")>0)
url=urlx+'&sysid='+sn;
else
url=urlx+'?sysid='+sn;
var http_request = false;
var ts1 = "";
var ts2 = "";
var p=0;
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() {
alertContents(http_request,id); };
http_request.open('GET', url, true);
http_request.send(null);
}
function alertContents(http_request,id) {
if (http_request.readyState == 4) {
if (id=='sysitembox2' || id=='sysitembox3' || id=='darea' || id=='dummydiv')
hideloading(1000);
if (http_request.status == 200) {
var mesg = http_request.responseText;
if(id=="v_ustatus"){
v_ustatus=mesg;
}else if(id=="*popup*"){
popup_request(mesg);
}else{
if(id.substring(0,4)=='txt_'){
document.getElementById(id).value=mesg;
}else{
var checkcnt=0;
while(document.getElementById(id) && checkcnt<5){
setTimeout('',500);
checkcnt=checkcnt+1;
}
document.getElementById(id).innerHTML=mesg;
if(id=="autocom" || id=="autocom2"){
if(mesg.length<10){
document.getElementById(id).style.display ="none";
}
}
}
window.scrollTo(0,0);
}
goresize();
} else {
errorcnt++;
//alert('There was a problem with the ajax request.');
}
}
}
function gosearch(aaa){
makeRequest('gosearch.php','search');
}
function vmarker(lat,lon){
var ll;
clearmarkers();
clearCsNearbyMarker();
ll=getlonlat(lon,lat);
addmarker(ll,"R");
map.setCenter(ll, 17);
//map.panTo(ll);
}
function vroute(id){
addline('route.php?id='+id,'#FF0000');
makeRequest('busstop.php?id='+id,'dummydiv');
}
function goresizex()
{
var p2p_guide = document.getElementById('p2p_guide');
var p2pmenu = document.getElementById('p2pmenu');
var myHeight = document.body.clientHeight-10;
//alert(myHeight);
if(p2p_guide && p2pmenu) {
p2p_guide.style.height=(myHeight - 22 - 52 - 84 - 8 - p2pmenu.clientHeight)+"px";
}
var itemlist_title_height=0;
var itemlist_title = document.getElementById('itemlist_title');
if(itemlist_title) {
itemlist_title_height = itemlist_title.clientHeight;
}
var stoplist_title_height=0;
var stoplist_title = document.getElementById('stoplist_title');
if(stoplist_title) {
stoplist_title_height = stoplist_title.clientHeight;
}
var p2p_routelist_title_height=0;
var p2p_routelist_title = document.getElementById('p2p_routelist_title');
if(p2p_routelist_title) {
p2p_routelist_title_height = p2p_routelist_title.clientHeight;
console.log("set p2p_routelist_title_height");
}
var p2p_stoplist_title_height=0;
var p2p_stoplist_title = document.getElementById('p2p_stoplist_title');
if(p2p_stoplist_title) {
p2p_stoplist_title_height = p2p_stoplist_title.clientHeight;
console.log("set p2p_stoplist_title_height");
}
var p2p_routenote_height=0;
var routenote = document.getElementById('routenote');
if(routenote) {
p2p_routenote_height = routenote.clientHeight;
console.log("set p2p_routenote_height");
}
var ajheight=0;
var businfo = document.getElementById('businfo');
if(businfo){
ajheight=businfo.clientHeight-32;
}
var businfo2 = document.getElementById('businfo2');
if(businfo2){
ajheight=businfo2.clientHeight-50;
}
var x,y;
if (self.innerHeight) // all except Explorer
{
x = self.innerWidth;
y = self.innerHeight;
}
else if (document.documentElement && document.documentElement.clientHeight)
// Explorer 6 Strict Mode
{
x = document.documentElement.clientWidth;
y = document.documentElement.clientHeight;
}
else if (document.body) // other Explorers
{
x = document.body.clientWidth;
y = document.body.clientHeight;
}
var screenh = y-28;
var screenw = x-389;
var ob = document.getElementById('optionbar');
if(ob)
ob.style.left = (screenw+265)+"px";
var bmlist = document.getElementById('bookmarklist');
if(bmlist)
bmlist.style.left = (screenw+265-190)+"px";
var bs1 = document.getElementById('hotspot');
if(bs1){
bs1.style.left = (screenw+265)+"px";
bs1.style.top = (screenh-25)+"px";
}
var bs2 = document.getElementById('hotspot2');
if(bs2){
bs2.style.left = (screenw+265)+"px";
bs2.style.top = (screenh-84)+"px";
}
var mwy = document.getElementById('mapwithyou');
if(mwy){
mwy.style.left = (screenw+235)+"px";
mwy.style.top = (screenh+6)+"px";
}
var w = document.getElementById('wrapper');
if(w){
w.style.top = ((document.documentElement.clientHeight-500)/2)+"px";
w.style.left = ((document.documentElement.clientWidth-600)/2)+"px";
}
var w2 = document.getElementById('wrapper2');
if(w2){
w2.style.top = ((document.documentElement.clientHeight-300)/2)+"px";
w2.style.left = ((document.documentElement.clientWidth-400)/2)+"px";
}
var w3 = document.getElementById('wrapper3');
if(w3){
document.getElementById('wrapper3').style.top = ((document.documentElement.clientHeight-600)/2) +"px";
if (document.getElementById('wrapper4').style.visibility!="hidden")
{
document.getElementById('wrapper3').style.left = ((document.documentElement.clientWidth)/2+50)+"px";
}
else
{
document.getElementById('wrapper3').style.left = ((document.documentElement.clientWidth-400)/2)+"px";
}
// document.getElementById('wrapper3').style.visibility = "visible";
}
var w4 = document.getElementById('wrapper4');
if(w4){
document.getElementById('wrapper4').style.top = ((document.documentElement.clientHeight-600)/2) +"px";
if (document.getElementById('wrapper3').style.visibility!="hidden")
{
document.getElementById('wrapper4').style.left = ((document.documentElement.clientWidth)/2-450)+"px";
}
else
{
document.getElementById('wrapper4').style.left = ((document.documentElement.clientWidth-500)/2)+"px";
}
// document.getElementById('wrapper4').style.visibility = "visible";
}
var w5 = document.getElementById('wrapper5');
if(w5){
document.getElementById('wrapper5').style.top = ((document.documentElement.clientHeight-600)/2) +"px";
// if (document.getElementById('wrapper3').style.visibility!="hidden")
// {
document.getElementById('wrapper4').style.left = ((document.documentElement.clientWidth)/2-450)+"px";
// }
// else
// {
// document.getElementById('wrapper4').style.left = ((document.documentElement.clientWidth-500)/2)+"px";
// }
// document.getElementById('wrapper4').style.visibility = "visible";
}
var ibox = document.getElementById('sysitembox');
if(ibox){
sysboxheight(ibox);
}
var ibox2 = document.getElementById('sysitembox2');
if(ibox2){
sysboxheight(ibox2);
}
var ibox3 = document.getElementById('sysitembox3');
if(ibox3){
console.log("Top "+ibox3.style.top);
sysboxheight(ibox3);
}
var ibox4 = document.getElementById('sysitembox4');
if(ibox4){
ibox4.style.height=(screenh-162)+"px";
}
var nbbox = document.getElementById('nearbylist');
if(nbbox){
var cheight = parseInt(ibox.style.height.replace("px", ""));
nbbox.style.height=(cheight-43)+"px";
}
var al1 = document.getElementById('arealist1');
if(al1){
var cheight = parseInt(ibox3.style.height.replace("px", ""));
al1.style.height=(cheight-43)+"px";
}
var rl1 = document.getElementById('routelist1');
if(rl1){
if(ibox2){
var cheight = parseInt(ibox2.style.height.replace("px", ""));
rl1.style.height=(cheight-42)+"px";
}
if(ibox3){
var cheight = parseInt(ibox3.style.height.replace("px", ""));
rl1.style.height=(cheight-48)+"px";
}
}
var rl2 = document.getElementById('routelist2');
if(rl2 && ibox2){
var cheight = parseInt(ibox2.style.height.replace("px", ""));
if (p2p_routelist_title_height!= 0){
rl2.style.height=(cheight - p2p_routelist_title_height- p2p_routenote_height - 5)+"px";
console.log("r1="+rl2.style.height);
}
if (itemlist_title_height!= 0){
rl2.style.height=(cheight - itemlist_title_height)+"px";
rl2.style.height="calc(100vh - 230px)";
console.log("r3="+rl2.style.height);
}
}else if(rl2 && ibox){
var cheight = parseInt(ibox.style.height.replace("px", ""));
rl2.style.height=(cheight-42)+"px";
rl2.style.height="calc(100vh - 226px)";
console.log("r4="+rl2.style.height);
}else if(rl2 && ibox3){
var cheight = parseInt(ibox3.style.height.replace("px", ""));
rl2.style.height=(cheight - p2p_routelist_title_height - p2p_routenote_height - 5)+"px";
console.log("set p2p_routelist height");
console.log("r5="+rl2.style.height);
}
var slpp = document.getElementById('sysstoplistpp');
if(slpp){
var dtheight = 0;
var ttheight = 26;
var cheight = parseInt(ibox3.style.height.replace("px", ""));
slpp.style.height=(cheight-101-40-ajheight)+"px";
var dtheight=(cheight-101-40-ajheight-ttheight);
var dtsl1 = document.getElementById('dtsysstoplist1');
dtsl1.style.height=(dtheight+45)+"px";
console.log("test 3");
}
var sl1 = document.getElementById('sysstoplist1');
if(sl1){
var dtheight = 0;
var ttheight = 26;
var sysstoplist1_height = 0;
if(ibox2){
var cheight = parseInt(ibox2.style.height.replace("px", ""));
sl1.style.height=(cheight-42-stoplist_title_height-35-5+5)+"px";
dtheight=(cheight-101-40-ajheight-ttheight-50);
console.log("set sysstoplist 1");
}else if(ibox3){
var cheight = parseInt(ibox3.style.height.replace("px", ""));
sl1.style.height=(cheight-42-stoplist_title_height-35-5+5)+"px";
dtheight=(cheight-101-40-ajheight-ttheight);
console.log("set sysstoplist 1");
}else{
var cheight = parseInt(ibox.style.height.replace("px", ""));
sl1.style.height=(cheight-42-stoplist_title_height-35-5+5)+"px";
dtheight=(cheight-101-35-ajheight-ttheight);
console.log("xtest 3");
}
sysstoplist1_height = parseInt(sl1.style.height.replace("px", ""));
}
var il1 = document.getElementById('itemlist1');
if(il1){
if(ibox3){
var cheight = parseInt(ibox3.style.height.replace("px", ""));
il1.style.height = (cheight - p2p_stoplist_title_height - p2p_routenote_height)+"px";
il1.style.height = (sysstoplist1_height)+"px";
}else if(ibox2 || ibox){
il1.style.height = (sysstoplist1_height)+"px";
console.log("set itemlist1height");
}
var dtsl1 = document.getElementById('dtsysstoplist1');
if(dtsl1){
dtsl1.style.height=(sysstoplist1_height-24)+"px"; // Busstop, fare title height = 24
console.log("set dtsystoplist1 height");
}
}
var il2 = document.getElementById('itemlist2');
if(il2){
if(ibox3){
var cheight = parseInt(ibox3.style.height.replace("px", ""));
il2.style.height = (cheight - p2p_stoplist_title_height)+"px";
il2.style.height = (sysstoplist1_height)+"px";
}else if(ibox2 || ibox){
il2.style.height = (sysstoplist1_height)+"px";
console.log("set itemlist2 height");
}
}
var pbar = document.getElementById('pdfbar');
if(pbar){
pbar.style.top=(screenh+20)+"px";
}
var rc = document.getElementById('redcross');
if(rc){
rc.style.top=(screenh/2+7)+"px";
rc.style.left=(screenw/2+387-15)+"px";
}
var snote = document.getElementById('specialNote');
if(snote){
snote.style.bottom=10+"px";
}
}
function fixtop(sid,top){
var sbox = document.getElementById(sid);
if(sbox){
sbox.style.top = top+"px";
}
}
function goetaresize()
{
var popupboxlist = document.getElementById('popupboxlist');
var nextbus = document.getElementById('nextbus');
nextbus.style.height = (popupboxlist.clientHeight - 18) + "px";
var nextbus_title = document.getElementById('nextbus_title');
var nextbus_list = document.getElementById('nextbus_list');
var nextbus_refresh = document.getElementById('nextbus_refresh');
if(nextbus_refresh){
nextbus_list.style.height=(nextbus.clientHeight - nextbus_title.clientHeight - nextbus_refresh.clientHeight - 10)+"px";
var nextbus_listitem = document.getElementById('nextbus_listitem');
var nextbus_space = document.getElementById('nextbus_space');
var nextbus_disclaimer = document.getElementById('nextbus_disclaimer');
console.log("Listitem ="+nextbus_listitem.clientHeight+"||Disclaimer ="+nextbus_disclaimer.clientHeight+"|| List ="+nextbus_list.clientHeight);
if((nextbus_listitem.clientHeight + nextbus_disclaimer.clientHeight) < nextbus_list.clientHeight){
nextbus_space.style.height = (nextbus_list.clientHeight - nextbus_listitem.clientHeight - nextbus_disclaimer.clientHeight) + "px";
}
}
}
function gorouteinstopresize()
{
var infoonmap = document.getElementById('infoonmap');
var busstopname = document.getElementById('busstopname');
var popupboxlist = document.getElementById('popupboxlist');
var popupboxlistmenu = document.getElementById('popupboxlistmenu');
popupboxlist.style.height=(infoonmap.clientHeight - busstopname.clientHeight - popupboxlistmenu.clientHeight)+"px";
}
function movesider(){
var siderbar = document.getElementById('zoomslider');
if(siderbar && map!=null){
siderbar.style.top = ((18-map.getZoom())*11+119)+"px";
}
}
function itemhighlighton(ss){
if(ss.substring(0,2)=="xx")
//document.getElementById(ss).style.backgroundColor='#808080';
document.getElementById(ss).style.backgroundColor='#bdbdbd';
else
document.getElementById(ss).style.backgroundColor=themecolor;
}
function itemhighlightoff(ss){
document.getElementById(ss).style.backgroundColor='';
}
function menuon(ss,mode){
if(mode==1)
document.getElementById(ss).style.backgroundColor='#FF0000';
else
document.getElementById(ss).style.backgroundColor='#FFA500';
}
function moption(ss,mode){
if(mode==1)
document.getElementById(ss).style.backgroundColor='#E0E0E0';
else
document.getElementById(ss).style.backgroundColor='#FFFFFF';
}
function gomenu(ss,m){
if(ss!=4){
clearmarkers();
clearCsNearbyMarker();
hidebox2();
}
if(ss!=0 && ss!=4 ){
clearmarkers();
}
clearCsNearbyMarker();
if(mapstartlat>0.0&&mapstartlon>0.0){
addcustommarker(getlonlat(mapstartlon,mapstartlat),ssmar,36,80,-20,-80);
}
if(mapendlat>0.0&&mapendlon>0.0){
addcustommarker(getlonlat(mapendlon,mapendlat),eemar,36,80,-20,-80);
}
if(ss!=4){
//mwypopupremove();
//removeline();
hidebox5();
hidebox4();
}
makeRequest('menu'+ss+'.php'+'?l='+lang+'&m='+m,'sysinfo');
currentmenu=ss;
if(ss!=0){
stopnearby();
}
cleartraffic();
}
function hidemenubar(){
document.getElementById("hotspot_line").style.backgroundColor='';
}
function loadbox2(boxheadfile,boxfile){
makeRequest(boxheadfile,'boxhead2');
makeRequest(boxfile,'lbox2');
showbox2();
}
function loadbox3(boxheadfile,boxfile)
{
makeRequest(boxheadfile,'boxhead3');
makeRequest(boxfile,'lbox3');
showbox3();
}
function loadbox4(boxheadfile,boxfile,mode)
{
makeRequest(boxheadfile,'boxhead4');
makeRequest(boxfile,'lbox4');
showbox4(mode);
}
function loadbox5(boxheadfile,boxheadfile2,boxfile,boxfile2)
{
makeRequest(boxheadfile,'boxhead5-1');
makeRequest(boxheadfile2,'boxhead5-2');
makeRequest(boxfile,'lbox5-1');
makeRequest(boxfile2,'lbox5-2');
showbox5();
}
function loadbox6(boxheadfile,boxfile)
{
makeRequest(boxheadfile,'boxhead6');
makeRequest(boxfile,'lbox6');
showbox6();
}
function loadbox7(boxheadfile,boxfile)
{
makeRequest(boxheadfile,'boxhead7');
makeRequest(boxfile,'lbox7');
showbox7();
}
function genpdf(f){
str1="正在產生報表,請稍候...";
if(lang==1){
str1="Generating, please wait...";
}
if(lang==2){
str1="正在产生报表,请稍候...";
}
var box2=document.getElementById('lbox2');
box2.innerHTML='
'+
'
'+str1+'
';
makeRequest('pp2genpdf.php?f='+f,'dummydiv');
}
function fbgenpdf(f1,f2){
makeRequest("fbgenpdf.php?f1="+f1+"&f2="+f2,"dummydiv");
}
function pdftomail(e,f,fx){
pic="pdfview.png";
pdfname=f;
pdfnamex=fx;
str1="檢視";
str2="發送郵件";
bk="返回";
if(lang==1){
str1="View";
str2="Send Email";
bk="back";
}
if(lang==2){
str1="检视";
str2="发送邮件";
bk="返回";
}
var box2=document.getElementById('lbox2');
if(e!=""){
sendpdf(e);
box2.innerHTML=oldpdf;
document.getElementById('femail').value=e;
/*
box2.innerHTML='';
*/
}else{
var p=oldpdf.toLowerCase().indexOf(' '+str1+' ';
if(fx!="")
ts2=' '+str1+'';
var tpdf = oldpdf.substring(0,p);
box2.innerHTML=''+
'