0

google earth in zk

asked 2012-01-19 12:00:52 +0800

mhj gravatar image mhj flag of Brazil
806 1 7

Hello guys!
I did a test where I display Google Earth. I wanna know if it has a better way to do this.
thanks in advance.

Java code:

Sessions.getCurrent().setAttribute("link", "home(\"<your link to kml file>\")");
Executions.getCurrent().sendRedirect("/test.zul", "");

test.zul

<zk xmlns="http://www.zkoss.org/2005/zul" 
xmlns:n="http://www.zkoss.org/2005/zk/native">    
    <window width="100%" height="100%" style="padding:0px;marging:0px;" onCreate='Clients.evalJavaScript(Sessions.getCurrent().getAttribute("link").toString())' >
     <n:head>
   <script src="http://www.google.com/jsapi?key=<your google earth key>"> </script>
   <script id="scriptTest" type="text/javascript">
      var ge;
      var href;
      google.load("earth", "1");
      
      function home(str){
        href = str;
      }
     
      function init() {
          if(navigator.appName == "Microsoft Internet Explorer"){
            setTimeout(function() { google.earth.createInstance('map3d', initCB, failureCB); }, 1000);
          }else{
            google.earth.createInstance('map3d', initCB, failureCB);
          }
      }

      function initCB(instance) {
         ge = instance;
         ge.getWindow().setVisibility(true);         
        test();
      }

      function failureCB(errorCode) {
      }

      google.setOnLoadCallback(init);
      
      function test(){
      google.earth.fetchKml(ge, href, function(kmlObject) {
      if (kmlObject)
         ge.getFeatures().appendChild(kmlObject);
      });
      
      //LAYER_BORDERS - mostra os limites dos países e das áreas, e coloca marcadores para cidades, estados, países, oceanos etc.
      //LAYER_BUILDINGS - construções em 3D
      //LAYER_BUILDINGS_LOW_RESOLUTION - construções cinzas (não fotorrealista). Observe que essa opção não contém cópias de construções fotorrealistas. Em vez disso, ela inclui construções que não existem ainda na camada de construções fotorrealistas. À medida que as versões fotorrealistas de construções cinzas são criadas, as construções serão adicionadas a LAYER_BUILDINGS e removidas de LAYER_BUILDINGS_LOW_RESOLUTION.
      //LAYER_ROADS - exibe rodovias e nomes de rodovias
      //LAYER_TERRAIN - terreno 3D
      
      ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
      ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS , true);
      ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, true);
      
      //sun
      //ge.getSun().setVisibility(true);
      
      //controls      
      //ge.VISIBILITY_SHOW
      //ge.VISIBILITY_HIDE
      //ge.VISIBILITY_AUTO
      
      ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
      
      // Set the FlyTo speed
      ge.getOptions().setFlyToSpeed(0.2);  
      
        // Create a new LookAt
        var lookAt = ge.createLookAt('');

        // Set the position values
        lookAt.setLatitude(-20.29651);
        lookAt.setLongitude(-40.303412);
        lookAt.setRange(100.0); //default is 0.0
        
        // Add 15 degrees to the current tilt
        lookAt.setTilt(75.0);
        //alert(lookAt.getTilt());

        // Update the view in Google Earth
        ge.getView().setAbstractView(lookAt);
        
      }
   </script>

</n:head>
<n:body style="margin: 0px; overflow: hidden;">
   <n:div id="map3d" style="border: 1px solid #cccccc; width: 100%; height:99%;"></n:div>
</n:body>
    </window>
</zk>

KML file

<?xml version='1.0' encoding='UTF-8'?>
<kml xmlns='http://earth.google.com/kml/2.1'>
<Document>
<name>Country Name Pie Charts</name>

<Style id='defaultStyle'>
  <LineStyle>
    <color>ffffffff</color>
    <width>1</width>
  </LineStyle>
  <PolyStyle>
    <color>a0a0a0a0</color>
    <colorMode>random</colorMode>
    <fill>1</fill>
    <outline>1</outline>
  </PolyStyle>
  <LabelStyle>
    <scale>1.0</scale>
  </LabelStyle>
  <IconStyle>
    <scale>1.0</scale>
  </IconStyle>
</Style>


<Folder>
  <name>Consonants</name>

<Placemark>
  <name>Brazil</name>
  <description>Brazil  (2 vowels, 4 consonants)</description>
  <styleUrl>#style_cons</styleUrl>
<Style>
  <PolyStyle>
    <color>bf0000ff</color>
    <outline>0</outline>
  </PolyStyle>
  <LabelStyle>
    <scale>1.0</scale>
  </LabelStyle>
  <IconStyle>
    <scale>1.0</scale>
  </IconStyle>
</Style>

<Polygon>
    <extrude>1</extrude>
    <altitudeMode>relativeToGround</altitudeMode>
  <outerBoundaryIs>
  <LinearRing>
    <extrude>1</extrude>
    <altitudeMode>relativeToGround</altitudeMode>
    <coordinates>
	-40.303586,-20.296155,30.0 
	-40.303353,-20.29611,30.0 
	-40.303307,-20.296281,30.0 
	-40.303551,-20.296318,30.0 
	-40.303586,-20.296155,30.0 
	   </coordinates>
  </LinearRing>
  </outerBoundaryIs>
</Polygon>
</Placemark>
</Folder>
</Document>
</kml>

delete flag offensive retag edit

1 Reply

Sort by » oldest newest

answered 2012-03-08 16:27:43 +0800

mhj gravatar image mhj flag of Brazil
806 1 7

I made an simple example in zkfiddle, then I'll add new features

ZKFiddle-Link

earth.js
var ge;
var strKml;
var lat,lng;
var kmlObject=null;

google.load("earth", "1");
google.setOnLoadCallback(init);

function init() {
if(navigator.appName == "Microsoft Internet Explorer"){
setTimeout(function() {
google.earth.createInstance('map3d', initCB, failureCB);
}, 1000);
}else{
google.earth.createInstance('map3d', initCB, failureCB);
}
}

function initCB(instance) {
ge = instance;
ge.getWindow().setVisibility(true);
google.earth.addEventListener(ge.getView(), 'viewchange', recordAltitude);
ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS , true);
ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, true);
ge.getNavigationControl().setVisibility(ge.VISIBILITY_SHOW);
ge.getOptions().setFlyToSpeed(0.2);
setPosCamera();
}

function failureCB(errorCode) {
alert("Error: "+errorCode);
}

function setPosCamera(){
var lookAt = ge.createLookAt('');
lookAt.setLatitude(latitude);
lookAt.setLongitude(longitude);
lookAt.setRange(5000.0);
lookAt.setTilt(65.0);
ge.getView().setAbstractView(lookAt);
}


TestComposer.java
package j19rqo3d$v4;

import org.zkoss.zk.ui.*;
import org.zkoss.zk.ui.event.*;
import org.zkoss.zk.ui.util.*;
import org.zkoss.zk.ui.ext.*;
import org.zkoss.zk.au.*;
import org.zkoss.zk.au.out.*;
import org.zkoss.zul.*;

public class TestComposer extends GenericForwardComposer{

public void doAfterCompose(Component comp) throws Exception {
super.doAfterCompose(comp);

}

public void onClick$btn(Event e) throws InterruptedException{
Messagebox.show("Hi btn");
}
}


index.zul
<zk xmlns="http://www.zkoss.org/2005/zul" 
xmlns:n="http://www.zkoss.org/2005/zk/native">
<window border="normal" title="Hello world literally!" apply="j19rqo3d$v4.TestComposer">
<div id="divHtml" height="94%">
<n:head>
<!--I don't know if the key below works for everybody-->
<script src="http://www.google.com/jsapi?key=ABQIAAAAUmCssU8WfJ3_lWr4wLTVphTEyxCBY0btOUIx3c_IqXBzz9srphSEZ34N86Ta9Zq5pSDprGzlFVDjlg"> </script>
<script id="scriptTest" type="text/javascript" src="earth.js">
</script>
</n:head>
<n:body style="margin: 0px; overflow: hidden;">
<n:div id="map3d" style="border: 1px solid #cccccc; width: 100%; height:100%;"></n:div>
</n:body>
</div>
</window>
</zk>

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-01-19 12:00:52 +0800

Seen: 444 times

Last updated: Mar 08 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More