1var lat; 2var lon; 3 4 5function plugin_geonav() { 6 page = plugin_geonav_category; 7 initPage (page); 8 google.earth.createInstance('map3d', initCallback, failureCallback); 9 addSampleButton('focus-btn', 'Focus In', buttonClick); 10} 11 12 function addSampleButton(btnLoc, caption, clickHandler) { 13 var focus = document.getElementById(btnLoc); 14 focus.addEventListener('click', clickHandler, false); 15 } 16 17 function exchangeHandler(btnLoc, oldHandler, newHandler) { 18 var focus = document.getElementById(btnLoc); 19 focus.removeEventListener('click', oldHandler, false); 20 focus.addEventListener('click', newHandler, false); 21 } 22 23 function hideButton(which){ 24 if (!document.getElementById(which)) 25 return; 26 document.getElementById(which).style.display="none"; 27 } 28 29 function showButton(which){ 30 if (!document.getElementById(which)) 31 return; 32 document.getElementById(which).style.display="inherit"; 33 } 34 35 function takeOut(which){ 36 if (!document.getElementById) 37 return; 38 which.style.display="none"; 39 } 40 41 function addSampleUIHtml(item, html) { 42 document.getElementById(item).innerHTML = html; 43 } 44 45 function initCallback(instance) { 46 ge = instance; 47 ge.getWindow().setVisibility(true); 48 49 // add a navigation control 50 ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO); 51 52 // add some layers 53 ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true); 54 ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, false); 55 } 56 57 function failureCallback(errorCode) { 58 if (errorCode == "ERR_CREATE_PLUGIN") { 59 alert("Google Earth Plugin not installed. To view more local data on a topic this Plugin is required. The window at the top left provides a download link to download the Plugin. Then by running the downloaded file the Plugin would be installed."); 60 } else { 61 alert("Other failure loading the Google Earth Plugin: " + errorCode); 62 } 63 } 64 65 function zoomIn(altitude) { 66 var lookAt = ge.createLookAt(''); 67 lookAt.set(parseFloat(lat), parseFloat(lon), 10, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 0,altitude); 68 ge.getView().setAbstractView(lookAt); 69 } 70 71 function buttonClick(e) { 72 var geocodeLocation = document.getElementById('location').value; 73 var geocoder = new google.maps.ClientGeocoder(); 74 75 var element = e.target; 76 77 geocoder.getLatLng(geocodeLocation, function(point) { 78 console.log("loc= "+geocodeLocation); 79 console.log("loc= "+point); 80 if (!point) { 81 alert(geocodeLocation + " not found"); 82 } else { 83 var matchll=/\(([-.\d]*), ([-.\d]*)/.exec(point); 84 if(matchll){ 85 lat=parseFloat(matchll[1]); 86 lon=parseFloat(matchll[2]); 87 lat=lat.toFixed(6); 88 lon=lon.toFixed(6);} 89 var lookAt = ge.createLookAt(''); 90 console.log("y= "+lat); 91 console.log("x= "+lon); 92 lookAt.set(parseFloat(lat), parseFloat(lon), 10, ge.ALTITUDE_RELATIVE_TO_GROUND,0, 0,6000000); 93 ge.getView().setAbstractView(lookAt); 94 reverseGeocode(lat, lon, element.id); 95 } 96 } 97 ); 98 } 99 100 var ge; 101 google.load("earth", "1"); 102 google.setOnLoadCallback(plugin_geonav); 103 104