`

Google Earth 开发示例(Hello World)

阅读更多
Google Earth Hello World 示例
<html>
  <head>
    <title>Hello Google Earth!</title>
    <!-- *** Replace the key below below with your own API key, available at http://code.google.com/apis/maps/signup.html *** -->
    <script src="http://www.google.com/jsapi?key=ABQIAAAA4ZZxnijCQhlZlf57igoGExTwM0brOpm-All5BF6PoaKBxRWWERR0mYEVnCnlZi8Qmoq3uoivZ9cIgQ";></script>
    <script>
//google.load("earth", "1");
google.load('earth', '1');
var ge = null;
/**
	Init
*/
function init() {
  google.earth.setLanguage('zh_CN');
  google.earth.createInstance("map3d", initCallback, failureCallback);

}
/*
	Call Back
*/
function initCallback(object) {
  ge = object;
 /*
	LAYER_BORDERS - shows country and area borders, and place labels for cities, states, countries, oceans, etc
	LAYER_BUILDINGS - 3D buildings
	LAYER_BUILDINGS_LOW_RESOLUTION - grey buildings (non-photorealistic). Note that this does not contain copies of photorealistic buildings; rather, it includes				buildings that do not yet exist in the photorealistic buildings layer. As photorealistic versions of grey buildings are created, the buildings will be added			to LAYER_BUILDINGS and removed from LAYER_BUILDINGS_LOW_RESOLUTION.
	LAYER_ROADS - displays roads and road names
	LAYER_TERRAIN - 3D terrain
	LAYER_TREES - 3D tree models
*/
  ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS_LOW_RESOLUTION, true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN, true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_TREES, true);

	/*
	ge.VISIBILITY_SHOW
	ge.VISIBILITY_HIDE
	ge.VISIBILITY_AUTO
	*/
  ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
	//parseKmlString(ge);

  ge.getWindow().setVisibility(true);

}

function parseKmlString(ge){
	var kmlString = ''
			+ '<?xml version="1.0" encoding="UTF-8"?>'
			+ '<kml xmlns="http://www.opengis.net/kml/2.2">'
			+ '<Document>'              + '  <Camera>' 
			+ '    <longitude>-122.444633</longitude>' 
			+ '    <latitude>37.801899</latitude>' 
			+ '    <altitude>139.629438</altitude>' 
			+ '    <heading>-70.0</heading>' 
			+ '    <tilt>75</tilt>' 
			+ '  </Camera>'
			+ '  <Placemark>'
			+ '    <name>Placemark from KML string</name>'
			+ '    <Point>'
			+ '      <coordinates>-122.448425,37.802907,0</coordinates>'
			+ '    </Point>'
			+ '  </Placemark>'
			+ '</Document>'
			+ '</kml>';
	var kmlObject = ge.parseKml(kmlString);
	ge.getFeatures().appendChild(kmlObject);

}

/*CallBack*/
function failureCallback(object) {

}


var placemark = ge.createPlacemark('');

placemark.setName("You are at Google");

ge.getFeatures().appendChild(placemark);


// Create style map for placemark

var normal = ge.createIcon('');

normal.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');

var iconNormal = ge.createStyle('');

iconNormal.getIconStyle().setIcon(normal);

var highlight = ge.createIcon('');

highlight.setHref('http://maps.google.com/mapfiles/kml/paddle/red-circle.png');

var iconHighlight = ge.createStyle('');

iconHighlight.getIconStyle().setIcon(highlight);

var styleMap = ge.createStyleMap('');

styleMap.setNormalStyle(iconNormal);

styleMap.setHighlightStyle(iconHighlight);

placemark.setStyleSelector(styleMap);
  

// Create point

var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);

var point = ge.createPoint('');

point.setLatitude(la.getLatitude());

point.setLongitude(la.getLongitude());

placemark.setGeometry(point);


</script>
  </head>
  <body onload='init()';


      <div>
        He Nan Qi Xiang
      </div>

      <div id='map3d_container'
           style='border: 1px solid silver; height: 600px; width: 800px;'>
        <div id='map3d' style='height: 100%;'></div>
      </div>
  </body>

</html>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics