var getBuildingNameById = function(id, oRst){
for(var i in oRst.building){
if(oRst.building[i].uid == id){
return oRst.building[i].name;
}
}
}
var getFloorNameById = function(id, oRst){
for(var i in oRst.floors){
if(oRst.floors[i].uid == id){
return oRst.floors[i].name;
}
}
}
var m22_googlemap = function(directionsFromAdress){
var mile22 = {};
var parkingImage = '/resources/img/p.gif';
var targetImage = '/resources/img/t.png';
var infoWindows = [];
var directionBuid, directionRuid, directionTitle, directionContent;
var directionsDisplay = new google.maps.DirectionsRenderer();
var directionsService = new google.maps.DirectionsService();
var flightPath1, flightPath2;
var drivingMarkersArray = [];
var start; //start position
var end = new google.maps.LatLng(GOOGLE_MAP_lAT, GOOGLE_MAP_lNG);
var defaultMapCenter = new google.maps.LatLng(GOOGLE_MAP_lAT, GOOGLE_MAP_lNG);
var zoomMapCenter = new google.maps.LatLng(GOOGLE_MAP_lAT, GOOGLE_MAP_lNG);
var geocoder = new google.maps.Geocoder();
var defaultZoomLevel = 16;
var mapOptions = {
zoom:defaultZoomLevel,
center: defaultMapCenter
};
var zoomMapOptions = {
zoom:defaultZoomLevel + 1,
center: zoomMapCenter
};
var map = new google.maps.Map(document.getElementById('js_googlemap'), mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('js_directionsPanel'));
var getFloorDatasById = function(id, oRst){
for(var i in oRst.floors){
if(oRst.floors[i].uid == id){
var rst = [];
rst['name'] = oRst.floors[i].name;
rst['level'] = oRst.floors[i].level;
return rst;
}
}
}
setTimeout(function(){
geocoder.geocode( { 'address': directionsFromAdress}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
start = results[0].geometry.location;
calcRoute();
}
});
}, 1000);
function openInfowindow(title, content){
if(infoWindows.length > 0){
for(var i in infoWindows){
infoWindows[i].close();
}
}
infoWindows.length = 0;
var contentString = '
'+
'
'+
'
'+
'
'+
title +
'
'+
'
'+
'
';
var infowindow = new google.maps.InfoWindow({
content: contentString
});
infoWindows.push(infowindow);
return infowindow;
}
function initialize() {
//addOverlay();
}
function drawPath(){
var flightPlanCoordinates = [
new google.maps.LatLng(37.451275, -122.114970),
new google.maps.LatLng(37.451247, -122.114817),
new google.maps.LatLng(37.451692, -122.114110),
new google.maps.LatLng(37.451571, -122.113984)
];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: "#a90533",
strokeOpacity: 1.0,
strokeWeight: 4
});
flightPath.setMap(map);
drivingMarkersArray.push(flightPath);
}
function drawPath_parking(flightPlanCoordinates){
/*
var lineSymbol = {
path: google.maps.SymbolPath.FORWARD_CLOSED_ARROW
};
var lineSymbol = {
path: 'M 0,-1 0,1',
strokeOpacity: 1,
scale: 4
};
flightPath1 = new google.maps.Polyline({
path: flightPlanCoordinates,
icons: [{
icon: lineSymbol,
offset: '100%',
repeat: '20px'
}],
strokeColor: "#71B7FC",
strokeOpacity: 0,
strokeWeight: 2
});
flightPath1.setMap(map);
drivingMarkersArray.push(flightPath1);
*/
}
function calcRoute() {
selectedMode = 'DRIVING';
var request = {
origin:start,
destination:end,
travelMode: google.maps.TravelMode[selectedMode]
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
addBuildingMarker(directionBuid, directionRuid, directionTitle, directionContent);
});
if(selectedMode == 'DRIVING'){
addPMarker();
drawPath();
}else{
if (drivingMarkersArray) {
for (i in drivingMarkersArray) {
drivingMarkersArray[i].setMap(null);
}
drivingMarkersArray.length = 0;
}
}
}
function addOverlay() {
/*
var p1ImageBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(37.404805, -122.141864),
new google.maps.LatLng(37.403753, -122.141596));
var p1Overlay = new google.maps.GroundOverlay(
'http://www.th7.cn/d/file/p/2012/07/17/2cecebb05847269ae8d4431bda4127fb.jpg',
p1ImageBounds);
p1Overlay.setMap(map);
*/
}
function addPMarker(){
/*
//parking1
var myLatLng1 = new google.maps.LatLng(37.404375, -122.141730);
var pMarker1 = new google.maps.Marker({
position: myLatLng1,
map: map,
title: "Parking Lots",
icon: parkingImage
});
drivingMarkersArray.push(pMarker1);
google.maps.event.addListener(pMarker1, 'click', function() {
var flightPlanCoordinates = [
new google.maps.LatLng(37.403493, -122.141440),
new google.maps.LatLng(37.403858, -122.142098),
new google.maps.LatLng(37.404404, -122.141671)
];
drawPath_parking(flightPlanCoordinates);
openInfowindow('', 'Parking').open(map,pMarker1);
});
//parking2
var myLatLng2 = new google.maps.LatLng(37.403808, -122.140373);
var pMarker2 = new google.maps.Marker({
position: myLatLng2,
map: map,
title: "Parking Lots",
icon: parkingImage
});
drivingMarkersArray.push(pMarker2);
google.maps.event.addListener(pMarker2, 'click', function() {
var flightPlanCoordinates = [
new google.maps.LatLng(37.402930, -122.141907),
new google.maps.LatLng(37.403494, -122.141449),
new google.maps.LatLng(37.403644, -122.141308),
new google.maps.LatLng(37.403811, -122.140356)
];
drawPath_parking(flightPlanCoordinates);
openInfowindow('', 'Parking').open(map,pMarker2);
});
//parking3
var myLatLng3 = new google.maps.LatLng(37.406518, -122.142145);
var pMarker3 = new google.maps.Marker({
position: myLatLng3,
map: map,
title: "Parking Lots",
icon: parkingImage
});
drivingMarkersArray.push(pMarker3);
google.maps.event.addListener(pMarker3, 'click', function() {
var flightPlanCoordinates = [
new google.maps.LatLng(37.402930, -122.141907),
new google.maps.LatLng(37.403494, -122.141449),
new google.maps.LatLng(37.403640, -122.141713),
new google.maps.LatLng(37.404040, -122.142462),
new google.maps.LatLng(37.404206, -122.143047),
new google.maps.LatLng(37.404227, -122.143432),
new google.maps.LatLng(37.404436, -122.144044),
new google.maps.LatLng(37.404670, -122.144436),
new google.maps.LatLng(37.404854, -122.144522),
new google.maps.LatLng(37.404998, -122.144463),
new google.maps.LatLng(37.406688, -122.143285),
new google.maps.LatLng(37.407001, -122.143038),
new google.maps.LatLng(37.407225, -122.142660),
new google.maps.LatLng(37.406475, -122.142473),
new google.maps.LatLng(37.406518, -122.142145)
];
drawPath_parking(flightPlanCoordinates);
openInfowindow('', 'Parking').open(map,pMarker3);
});
*/
}
function addBuildingMarker(buildingId, roomId, title, detail){
/*
switch(buildingId){
case '65FFC84A-F176-4F2A-5EA6-BFE115E58A28':
var latLng = new google.maps.LatLng(37.405422, -122.139932);
var marker = new google.maps.Marker({
position: latLng,
map: map,
title: title,
icon: targetImage
});
openInfowindow(title, detail).open(map,marker);
google.maps.event.addListener(marker, 'click', function() {
openInfowindow(title, detail).open(map,marker);
});
var coordinates = [
end,
new google.maps.LatLng(37.403508, -122.141445),
new google.maps.LatLng(37.404216, -122.140823),
new google.maps.LatLng(37.404292, -122.140731),
new google.maps.LatLng(37.404331, -122.140613),
new google.maps.LatLng(37.404761, -122.140292),
new google.maps.LatLng(37.404869, -122.140312),
new google.maps.LatLng(37.404912, -122.140361)
];
var flightPath = new google.maps.Polyline({
path: coordinates,
strokeColor: "#71B7FC",
strokeOpacity: 0.8,
strokeWeight: 7
});
flightPath.setMap(map);
break;
}
*/
}
$(document).on('mousedown', '.js_zoomin', function(){
map.setOptions(zoomMapOptions);
});
$(document).on('mousedown', '.js_mapDetail', function(){
$('#js_myMap').modal('show');
switch(directionBuid){
case '65FFC84A-F176-4F2A-5EA6-BFE115E58A28':
var sta = '950C665B-1F07-89C6-700A-CBFC9F85047A,1305,692';
var iframeSrc = '/tdmb/r.php?sta='+ sta + '&des='+ directionRuid;
break;
}
var iframeHtml = '';
setTimeout(function(){
$('#js_myMap .modal-body').html(iframeHtml);
}, 1000);
});
google.maps.event.addDomListener(window, 'load', initialize);
};
$(document).ready(function(){
$("#js_googlemap").height($(window).height());
});