- var ge;
- var geHelpers_;
- /*
- var init;
- var placemark1;
- var placemark2;
- var placemark2s;
- var placemark3;
- var model1;
- var model2;
- var model2s;
- var model3;
- */
- var cameraList;
- var modelList;
- var viewList;
- var CAMERAICONDOWNURL = "http://google-maps-icons.googlecode.com/files/photodown.png";
- var CAMERAICONUPURL = "http://google-maps-icons.googlecode.com/files/photoup.png";
- //var directionsService = new google.maps.DirectionsService();
- //var directionsService = null;
- google.load("earth", "1");
- function init() {
- google.earth.createInstance('map3d', initCallback, failureCallback);
- addSampleButton('Birds eye!', buttonClick);
- }
- function initCallback(instance) {
- //init = 1;
- ge = instance;
- geHelpers_ = new GEHelpers(ge);
- ge.getWindow().setVisibility(true);
- // add a navigation control
- ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
- // add some layers
- ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
- ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
- //ge.getSun().setVisibility(true);
- //ge.getOptions().setAtmosphereVisibility(true);
- ge.getOptions().setScaleLegendVisibility(true);
- ge.getOptions().setStatusBarVisibility(true);
- //ge.getTime().setHistoricalImageryEnabled(true);
- //create3dModelIni();
- /* initialize view over Pittsburgh */
- var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
- la.setLatitude(40.43346237762932);
- la.setLongitude(-80.0173172514702);
- la.setTilt(0);
- la.setHeading(0);
- la.setRange(20000);
- ge.getView().setAbstractView(la);
- document.getElementById('installed-plugin-version').innerHTML =
- ge.getPluginVersion().toString();
- /* initialize models */
- initialize3dModels();
- /* begin updating models */
- timedCount();
- }
- function timedCount()
- {
- update3dModels();
- //create3dModel();
- t=setTimeout("timedCount()",2500);
- }
- function failureCallback(errorCode) {
- }
- /* Read camera files and create all models, add to model array */
- function initialize3dModels() {
- /* get camera directions */
- getCameraDirections();
- /* read xml file */
- var xmlDoc = loadXMLDoc("cameras.xml");
- cameraList = xmlDoc.getElementsByTagName("camera");
- modelList = new Array();
- for(var j = 0; j < cameraList.length; j ++) {
- createModel(cameraList[j]);
- }
- }
- function getCameraDirections() {
- var xmlDoc = loadXMLDoc("views.xml");
- viewList = xmlDoc.getElementsByTagName("camera");
- }
- function loadXMLDoc(url)
- {
- if (window.XMLHttpRequest)
- {
- xhttp=new XMLHttpRequest();
- }
- else
- {
- xhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xhttp.open("GET",url,false);
- xhttp.send();
- return xhttp.responseXML;
- }
- /* Iterate through array of models and update their images */
- function update3dModels() {
- var currentCamera = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
- document.getElementById('currentview').innerHTML = "Tilt: " + currentCamera.getTilt().toString() + " Altitude: " + currentCamera.getAltitude().toString() + " Longitude: " + currentCamera.getLongitude().toString() + " Latitude: " + currentCamera.getLatitude().toString();
- /* foreach camera:
- * only need string + model? */
- for(var i = 0; i < cameraList.length; i ++) {
- var link = ge.createLink('');
- var href = cameraList[i].getElementsByTagName("model_url")[0].textContent;
- link.setHref(href);
- modelList[i].setLink(link);
- }
- }
- function getView(imgHref) {
- for(var i = 0; i < viewList.length; i ++) {
- var imgURL = viewList[i].getElementsByTagName("image_url")[0].textContent;
- if(imgURL == imgHref)
- return viewList[i].getElementsByTagName("view")[0].textContent;
- }
- return "";
- }
- /* Create all Google earth objects associated with one camera
- * Parameters: Name(description?), Heading, Sketchup file, Location (Latitude, Longitude),
- * Direction?, Camera IMG URL, Camera: Latitude, Longitude, Tilt, Heading, Range */
- function createModel(camera) {
- // Create a 3D model, initialize it from a Collada file, and place it
- // in the world.
- var sName = camera.getElementsByTagName("name")[0].textContent;
- /* lookup model's view */
- var imgHref = camera.getElementsByTagName("image_url")[0].textContent;
- var viewName = getView(imgHref);
- var views = camera.getElementsByTagName("view");
- var viewIndex = 0;
- for(var i = 0; i < views.length; i ++) {
- if(views[i].getElementsByTagName("name")[0].textContent == viewName) {
- viewIndex = i;
- break;
- }
- }
- /* select correct icon */
- var iconHref = CAMERAICONDOWNURL;
- if(viewName == "Southbound")
- iconHref = CAMERAICONUPURL;
- var nModel = camera.getElementsByTagName("model")[viewIndex];
- var nLookat = camera.getElementsByTagName("lookat")[viewIndex];
- //alert(viewName + "," + viewIndex);
- var placemark = ge.createPlacemark('');
- placemark.setName(sName);
- var model = ge.createModel('');
- ge.getFeatures().appendChild(placemark);
- var loc = ge.createLocation('');
- model.setLocation(loc);
- var ori = ge.createOrientation('');
- var heading = parseInt(nModel.getElementsByTagName("heading")[0].textContent);
- ori.setHeading(heading);
- model.setOrientation(ori);
- var link = ge.createLink('');
- var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
- // A textured model created in Sketchup and exported as Collada.
- var href = camera.getElementsByTagName("model_url")[0].textContent;
- link.setHref(href);
- var car = new Array();
- car.model = model;
- car.placemark = placemark;
- model.setLink(link);
- /* zoom */
- var modelZoom = parseFloat(nModel.getElementsByTagName("zoom")[0].textContent);
- var mScale = model.getScale();
- mScale.setX(mScale.getX() * modelZoom);
- mScale.setY(mScale.getY() * modelZoom);
- var modelLatitude = parseFloat(nModel.getElementsByTagName("latitude")[0].textContent);
- var modelLongitude = parseFloat(nModel.getElementsByTagName("longitude")[0].textContent);
- loc.setLatitude(modelLatitude);
- loc.setLongitude(modelLongitude);
- placemark.setGeometry(model);
- // add model to array:
- modelList.push(model);
- // create the placemark Button
- var pmButton = ge.createPlacemark('');
- var point = ge.createPoint('');
- point.setLatitude(modelLatitude);
- point.setLongitude(modelLongitude);
- pmButton.setGeometry(point);
- // Create a style map.
- var styleMap = ge.createStyleMap('');
- // Create normal style for style map.
- var normalStyle = ge.createStyle('');
- var normalIcon = ge.createIcon('');
- normalIcon.setHref(iconHref);
- normalStyle.getIconStyle().setIcon(normalIcon);
- // Create highlight style for style map.
- var highlightStyle = ge.createStyle('');
- var highlightIcon = ge.createIcon('');
- highlightIcon.setHref(imgHref);
- highlightStyle.getIconStyle().setIcon(highlightIcon);
- highlightStyle.getIconStyle().setScale(2.0);
- styleMap.setNormalStyle(normalStyle);
- styleMap.setHighlightStyle(highlightStyle);
- // Apply stylemap to a placemark.
- pmButton.setStyleSelector(styleMap);
- // add the placemark to the earth DOM
- ge.getFeatures().appendChild(pmButton);
- google.earth.addEventListener(pmButton, 'click', function(event) {
- // Prevent the default balloon from appearing.
- event.preventDefault();
- var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
- var viewLatitude = parseFloat(nLookat.getElementsByTagName("latitude")[0].textContent);
- var viewLongitude = parseFloat(nLookat.getElementsByTagName("longitude")[0].textContent);
- var viewTilt = parseFloat(nLookat.getElementsByTagName("tilt")[0].textContent);
- var viewHeading = parseInt(nLookat.getElementsByTagName("heading")[0].textContent);
- var viewRange = parseInt(nLookat.getElementsByTagName("range")[0].textContent);
- la.setLatitude(viewLatitude);
- la.setLongitude(viewLongitude);
- la.setTilt(viewTilt);
- la.setHeading(viewHeading);
- la.setRange(viewRange);
- ge.getView().setAbstractView(la);
- });
- ////////////////////////////////////////////////////////////
- }
- function getValue(node, key) {
- return (node.getElementsByTagName(key))[0].textContent;
- }
- function create3dModel() {
- if (init==1){
- // Create a 3D model, initialize it from a Collada file, and place it
- // in the world.
- placemark1 = ge.createPlacemark('');
- placemark1.setName("model1");
- model1 = ge.createModel('');
- ge.getFeatures().appendChild(placemark1);
- var loc1 = ge.createLocation('');
- model1.setLocation(loc1);
- var ori1 = ge.createOrientation('');
- ori1.setHeading(140);
- model1.setOrientation(ori1);
- var link1 = ge.createLink('');
- var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
- // A textured model created in Sketchup and exported as Collada.
- link1.setHref("http://www.cmu.edu/vis/video/camera1.dae");
- var car1 = new Array();
- car1.model = model1;
- car1.placemark = placemark1;
- model1.setLink(link1);
- loc1.setLatitude(40.433714999827764);
- loc1.setLongitude(-80.11024186884087 );
- placemark1.setGeometry(model1);
- // create the placemark Button
- placemarkb1 = ge.createPlacemark('');
- var point = ge.createPoint('');
- point.setLatitude(40.433714999827764);
- point.setLongitude(-80.11024186884087 );
- placemarkb1.setGeometry(point);
- // Create a style map.
- var styleMap1 = ge.createStyleMap('');
- // Create normal style for style map.
- var normalStyle1 = ge.createStyle('');
- var normalIcon1 = ge.createIcon('');
- normalIcon1.setHref('http://google-maps-icons.googlecode.com/files/photodown.png');
- normalStyle1.getIconStyle().setIcon(normalIcon1);
- // Create highlight style for style map.
- var highlightStyle1 = ge.createStyle('');
- var highlightIcon1 = ge.createIcon('');
- highlightIcon1.setHref('http://www.dot35.state.pa.us/public/Districts/District11/WebCams/D11-605.jpg');
- highlightStyle1.getIconStyle().setIcon(highlightIcon1);
- highlightStyle1.getIconStyle().setScale(2.0);
- styleMap1.setNormalStyle(normalStyle1);
- styleMap1.setHighlightStyle(highlightStyle1);
- // Apply stylemap to a placemark.
- placemarkb1.setStyleSelector(styleMap1);
- // add the placemark to the earth DOM
- ge.getFeatures().appendChild(placemarkb1);
- google.earth.addEventListener(placemarkb1, 'click', function(event) {
- // Prevent the default balloon from appearing.
- event.preventDefault();
- var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
- la.setLatitude(40.4345406494454);
- la.setLongitude(-80.11078134543826);
- la.setTilt(67.2967669601648 );
- la.setHeading(165);
- la.setRange(40);
- ge.getView().setAbstractView(la);
- });
- ////////////////////////////////////////////////////////////
- placemark2 = ge.createPlacemark('');
- placemark2.setName("model2");
- model2 = ge.createModel('');
- ge.getFeatures().appendChild(placemark2);
- var loc2 = ge.createLocation('');
- model2.setLocation(loc2);
- var ori2 = ge.createOrientation('');
- ori2.setHeading(0);
- model2.setOrientation(ori2);
- var link2 = ge.createLink('');
- // A textured model created in Sketchup and exported as Collada.
- link2.setHref("http://www.cmu.edu/vis/video/camera2.dae");
- var car2 = new Array();
- car2.model = model2;
- car2.placemark = placemark2;
- model2.setLink(link2);
- loc2.setLatitude(40.45069303613354);
- loc2.setLongitude(-80.1108431548594);
- placemark2.setGeometry(model2);
- // create the placemark Button
- placemarkb2 = ge.createPlacemark('');
- var point = ge.createPoint('');
- point.setLatitude(40.45069303613354);
- point.setLongitude(-80.1108431548594);
- placemarkb2.setGeometry(point);
- // Create a style map.
- var styleMap2 = ge.createStyleMap('');
- // Create normal style for style map.
- var normalStyle2 = ge.createStyle('');
- var normalIcon2 = ge.createIcon('');
- normalIcon2.setHref('http://google-maps-icons.googlecode.com/files/photoup.png');
- normalStyle2.getIconStyle().setIcon(normalIcon2);
- // Create highlight style for style map.
- var highlightStyle2 = ge.createStyle('');
- var highlightIcon2 = ge.createIcon('');
- highlightIcon2.setHref('http://www.dot35.state.pa.us/public/Districts/District11/WebCams/D11-610.jpg');
- highlightStyle2.getIconStyle().setIcon(highlightIcon2);
- highlightStyle2.getIconStyle().setScale(2.0);
- styleMap2.setNormalStyle(normalStyle2);
- styleMap2.setHighlightStyle(highlightStyle2);
- // Apply stylemap to a placemark.
- placemarkb2.setStyleSelector(styleMap2);
- // add the placemark to the earth DOM
- ge.getFeatures().appendChild(placemarkb2);
- google.earth.addEventListener(placemarkb2, 'click', function(event) {
- // Prevent the default balloon from appearing.
- event.preventDefault();
- var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
- la.setLatitude(40.45083627184732);
- la.setLongitude(-80.1109844995387);
- la.setTilt(70.26032093626698 );
- la.setHeading(0);
- la.setRange(48);
- ge.getView().setAbstractView(la);
- });
- ////////////////////////////////////////////////////////////
- placemark2s = ge.createPlacemark('');
- placemark2s.setName("model2s");
- model2s = ge.createModel('');
- ge.getFeatures().appendChild(placemark2s);
- var loc2s = ge.createLocation('');
- model2s.setLocation(loc2s);
- var ori2s = ge.createOrientation('');
- ori2s.setHeading(180);
- model2s.setOrientation(ori2s);
- var link2s = ge.createLink('');
- // A textured model created in Sketchup and exported as Collada.
- link2s.setHref("http://www.cmu.edu/vis/video/camera2.dae");
- var car2s = new Array();
- car2s.model = model2s;
- car2s.placemark = placemark2s;
- model2s.setLink(link2s);
- loc2s.setLatitude(40.44977701019319);
- loc2s.setLongitude( -80.11104025634937);
- placemark2s.setGeometry(model2s);
- // create the placemark Button
- placemarkb2s = ge.createPlacemark('');
- var point = ge.createPoint('');
- point.setLatitude(40.44977701019319);
- point.setLongitude( -80.11104025634937);
- placemarkb2s.setGeometry(point);
- // Create a style map.
- var styleMap2s = ge.createStyleMap('');
- // Create normal style for style map.
- var normalStyle2s = ge.createStyle('');
- var normalIcon2s = ge.createIcon('');
- normalIcon2s.setHref('http://google-maps-icons.googlecode.com/files/photodown.png');
- normalStyle2s.getIconStyle().setIcon(normalIcon2s);
- // Create highlight style for style map.
- var highlightStyle2s = ge.createStyle('');
- var highlightIcon2s = ge.createIcon('');
- highlightIcon2s.setHref('http://www.dot35.state.pa.us/public/Districts/District11/WebCams/D11-610.jpg');
- highlightStyle2s.getIconStyle().setIcon(highlightIcon2s);
- highlightStyle2s.getIconStyle().setScale(2.0);
- styleMap2s.setNormalStyle(normalStyle2s);
- styleMap2s.setHighlightStyle(highlightStyle2s);
- // Apply stylemap to a placemark.
- placemarkb2s.setStyleSelector(styleMap2s);
- // add the placemark to the earth DOM
- ge.getFeatures().appendChild(placemarkb2s);
- google.earth.addEventListener(placemarkb2s, 'click', function(event) {
- // Prevent the default balloon from appearing.
- event.preventDefault();
- var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
- la.setLatitude(40.449638480064394);
- la.setLongitude(-80.11090778784572);
- la.setTilt(74.70601877454101);
- la.setHeading(180);
- la.setRange(56);
- ge.getView().setAbstractView(la);
- });
- ////////////////////////////////////////////////////////////
- placemark3 = ge.createPlacemark('');
- placemark3.setName("model3");
- model3 = ge.createModel('');
- ge.getFeatures().appendChild(placemark3);
- var loc3 = ge.createLocation('');
- model3.setLocation(loc3);
- var ori3 = ge.createOrientation('');
- ori3.setHeading(180);
- model3.setOrientation(ori3);
- var link3 = ge.createLink('');
- // A textured model created in Sketchup and exported as Collada.
- link3.setHref("http://www.cmu.edu/vis/video/camera3.dae");
- var car3 = new Array();
- car3.model = model3;
- car3.placemark = placemark3;
- model3.setLink(link3);
- loc3.setLatitude(40.46549556059307);
- loc3.setLongitude(-80.11198023280035);
- placemark3.setGeometry(model3);
- // create the placemark Button
- placemarkb3 = ge.createPlacemark('');
- var point = ge.createPoint('');
- point.setLatitude(40.46549556059307);
- point.setLongitude(-80.11198023280035);
- placemarkb3.setGeometry(point);
- // Create a style map.
- var styleMap3 = ge.createStyleMap('');
- // Create normal style for style map.
- var normalStyle3 = ge.createStyle('');
- var normalIcon3 = ge.createIcon('');
- normalIcon3.setHref('http://google-maps-icons.googlecode.com/files/photodown.png');
- normalStyle3.getIconStyle().setIcon(normalIcon3);
- // Create highlight style for style map.
- var highlightStyle3 = ge.createStyle('');
- var highlightIcon3 = ge.createIcon('');
- highlightIcon3.setHref('http://www.dot35.state.pa.us/public/Districts/District11/WebCams/D11-612.jpg');
- highlightStyle3.getIconStyle().setIcon(highlightIcon3);
- highlightStyle3.getIconStyle().setScale(2.0);
- styleMap3.setNormalStyle(normalStyle3);
- styleMap3.setHighlightStyle(highlightStyle3);
- // Apply stylemap to a placemark.
- placemarkb3.setStyleSelector(styleMap3);
- // add the placemark to the earth DOM
- ge.getFeatures().appendChild(placemarkb3);
- google.earth.addEventListener(placemarkb3, 'click', function(event) {
- // Prevent the default balloon from appearing.
- event.preventDefault();
- var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
- la.setLatitude(40.46508842540561);
- la.setLongitude(-80.11185727742705);
- la.setTilt(70.11096303583611);
- la.setHeading(180);
- la.setRange(83);
- ge.getView().setAbstractView(la);
- });
- init = 0;
- }
- else{
- var currentCamera = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
- document.getElementById('currentview').innerHTML = "Tilt: " + currentCamera.getTilt().toString() + " Altitude: " + currentCamera.getAltitude().toString() + " Longitude: " + currentCamera.getLongitude().toString() + " Latitude: " + currentCamera.getLatitude().toString();
- var link1 = ge.createLink('');
- link1.setHref("http://www.cmu.edu/vis/video/camera1.dae");
- model1.setLink(link1);
- //placemark1.setGeometry(model1);
- var link2 = ge.createLink('');
- link2.setHref("http://www.cmu.edu/vis/video/camera2.dae");
- model2.setLink(link2);
- //placemark2.setGeometry(model2);
- var link2s = ge.createLink('');
- link2s.setHref("http://www.cmu.edu/vis/video/camera2.dae");
- model2s.setLink(link2s);
- //placemark2.setGeometry(model2);
- var link3 = ge.createLink('');
- link3.setHref("http://www.cmu.edu/vis/video/camera3.dae");
- model3.setLink(link3);
- //placemark3.setGeometry(model3);
- }
- }
- function log(msg) {
- setTimeout(function() {
- throw new Error(msg);
- }, 0);
- }
- function buttonClick() {
- var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
- la.setLatitude(40.43346237762932);
- la.setLongitude(-80.0173172514702);
- la.setTilt(0);
- la.setHeading(0);
- la.setRange(20000);
- ge.getView().setAbstractView(la);
- }
- function newAjax(){
- var xmlhttp=false;
- try {
- xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
- try {
- xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (E) {
- xmlhttp = false;
- }
- }
- if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
- xmlhttp = new XMLHttpRequest();
- }
- return xmlhttp;
- }
- function loadContent(url, container){
- ajax=newAjax();
- ajax.open("GET", url,true);
- ajax.onreadystatechange=function() {
- if (ajax.readyState==4 && this.status != 200) {
- container.innerHTML = ajax.responseXML
- }
- }
- ajax.send("");
- }