var groundOverlay = ge.createGroundOverlay( );
groundOverlay.setIcon(ge.createIcon( ))
groundOverlay.getIcon().
setHref("http://www.google.com/intl/en_ALL/images/logo.gif");
groundOverlay.setLatLonBox(ge.createLatLonBox( ));
var center = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
var north = center.getLatitude() + .85;
var south = center.getLatitude() - .85;
var east = center.getLongitude() + .55;
var west = center.getLongitude() - .55;
var rotation = 0;
var latLonBox = groundOverlay.getLatLonBox();
latLonBox.setBox(north, south, east, west, rotation);
ge.getFeatures().appendChild(groundOverlay);
var screenOverlay = ge.createScreenOverlay( );
screenOverlay.setIcon(ge.createIcon( ));
screenOverlay.getIcon().
setHref("http://www.google.com/intl/en_ALL/images/logo.gif");
// Set screen position in pixels
screenOverlay.getOverlayXY().setXUnits(ge.UNITS_PIXELS);
screenOverlay.getOverlayXY().setYUnits(ge.UNITS_PIXELS);
screenOverlay.getOverlayXY().setX(400);
screenOverlay.getOverlayXY().setY(200);
// Rotate around object s center point
screenOverlay.getRotationXY().setXUnits(ge.UNITS_FRACTION);
screenOverlay.getRotationXY().setYUnits(ge.UNITS_FRACTION);
screenOverlay.getRotationXY().setX(0.5);
screenOverlay.getRotationXY().setY(0.5);
// Set object s size in pixels
screenOverlay.getSize().setXUnits(ge.UNITS_PIXELS);
screenOverlay.getSize().setYUnits(ge.UNITS_PIXELS);
screenOverlay.getSize().setX(300);
screenOverlay.getSize().setY(75);
// Rotate 45 degrees
screenOverlay.setRotation(45);
ge.getFeatures().appendChild(screenOverlay);
map = ge.createStyleMap( styleMap + counter);
// Create icon normal for style map
normal = ge.createIcon( );
normal.setHref( http://maps.google.com/mapfiles/kml/shapes/triangle.png );
iconNormal = ge.createStyle( styleIconNormal + counter);
iconNormal.getIconStyle().setIcon(normal);
? // Create icon highlight for style map
highlight = ge.createIcon( );
highlight.setHref( http://maps.google.com/mapfiles/kml/shapes/square.png );
iconHighlight = ge.createStyle( styleIconHighlight + counter);
iconHighlight.getIconStyle().setIcon(highlight);
// Set normal and highlight for stylemap
map.setNormalStyleUrl( #styleIconNormal + counter);
map.setHighlightStyleUrl( #styleIconHighlight + counter);
// Apply to placemark
placemark.setStyleUrl( #styleMap + counter);
}
var pentagon = ge.parseKml( +
+
+
The Pentagon +
+
1 +
relativeToGround +
+
+
+
-77.05788457660967,38.87253259892824,100 +
-77.05465973756702,38.87291016281703,100 +
-77.05315536854791,38.87053267794386,100 +
-77.05552622493516,38.868757801256,100 +
-77.05844056290393,38.86996206506943,100 +
-77.05788457660967,38.87253259892824,100 +
+
+
+
+
+
+
-77.05668055019126,38.87154239798456,100 +
-77.05542625960818,38.87167890344077,100 +
-77.05485125901024,38.87076535397792,100 +
-77.05577677433152,38.87008686581446,100 +
-77.05691162017543,38.87054446963351,100 +
-77.05668055019126,38.87154239798456,100 +
+
+
+
+
+
);
ge.getFeatures().appendChild(pentagon);
var la = ge.createLookAt( );
la.set(38.867, -77.0565, 500, ge.ALTITUDE_RELATIVE_TO_GROUND, 0, 45, 900);
ge.getView().setAbstractView(la);
placemark = ge.createPlacemark( );
placemark.setName( model );
model = ge.createModel( );
ge.getFeatures().appendChild(placemark);
loc = ge.createLocation( );
model.setLocation(loc);
link = ge.createLink( );
// A textured model created in Sketchup and exported as Collada.
var href = window.location.href;
var pagePath = href.substring(0, href.lastIndexOf( / )) + / ;
link.setHref(pagePath + splotchy_box.dae );
model.setLink(link);
la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
loc.setLatitude(la.getLatitude());
loc.setLongitude(la.getLongitude());
placemark.setGeometry(model);
la.setRange(300);
la.setTilt(80);
ge.getView().setAbstractView(la);
Using Google Earth API with the Maps API
function initialize() {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(37.4419, -122.1419), 13);
map.addMapType(G_SATELLITE_3D_MAP);
map.addControl(new GHierarchicalMapTypeControl());
// Uncomment the following line to start the map with 3D enabled.
// map.setMapType(G_SATELLITE_3D_MAP);
// Obtain a pointer to the Google Earth instance attached to
// your map.
map.getEarthInstance(getEarthInstanceCB);
}
var ge;
function getEarthInstanceCB(object) {
ge = object;
// You can now manipulate ge using the full Google Earth API.
}
除了addMapType,您还可以用gMap.setMapType(G_SATELLITE_3D_MAP)直接把地图切换至Google Earth。同样,调用gMapType.setMapType()可以隐藏Google Earth窗口,地图切换到其他类型。
转自
http://www.d3dweb.com/Documents/201203/17-17562793368.html
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public static class GEHelper
{
#region
// Keep an angle(角度) in [-180,180]
/**
* Keep an angle in the [-180, 180] range
* @param {number} a Angle in degrees
* @return {number} The angle in the [-180, 180] degree range
*/
private static Double fixAngle(double a)
{
while (a < -180)
a += 360;
while (a > 180)
a -= 360;
return a;
}
/**
* Converts degrees(角度) to radians(弧度)
* @param {number} d Degrees
* @return {number} Radians
*/
private static decimal deg2rad(decimal d)
{
return d * Convert.ToDecimal(Math.PI) / Convert.ToDecimal(180.0);
}
/**
* Converts radians(弧度) to degrees(角度)
* @param {number} r Radians
* @return {number} Degrees
*/
private static double rad2deg(double r)
{
return r * 180.0 / Math.PI;
}
/** 计算两点之间的方位
* Calculates the heading/bearing between two locations. Taken from the formula
* provided at http://mathforum.org/library/drmath/view/55417.html
* @param {google.maps.LatLng} loc1 The start location
* @param {google.maps.LatLng} loc2 The destination location
* @return {number} The heading from loc1 to loc2, in degrees
*/
public static double getHeading(GeMode ge1, GeMode ge2)
{
decimal lat1; decimal lon1; decimal lat2; decimal lon2;
lat1 = deg2rad(ge1.lat);
lon1 = deg2rad(ge1.lng);
lat2 = deg2rad(ge2.lat);
lon2 = deg2rad(ge2.lng);
var heading = fixAngle(rad2deg(Math.Atan2(
Math.Sin(Convert.ToDouble(lon2 - lon1)) * Math.Cos(Convert.ToDouble(lat2)),
Math.Cos(Convert.ToDouble(lat1)) * Math.Sin(Convert.ToDouble(lat2)) - Math.Sin(Convert.ToDouble(lat1)) * Math.Cos(Convert.ToDouble(lat2)) *
Math.Cos(Convert.ToDouble(lon2 - lon1)))));
return heading;
}
///
/// //找到两点之间的中间
/**
* Calculates an intermediate lat/lon, (100 * f)% between loc1 and loc2
* @param {google.maps.LatLng} loc1 The start location
* @param {google.maps.LatLng} loc2 The end location
* @return {google.maps.LatLng} An intermediate location between loc1 and loc2
*/
///
///
///
///
///
public static GeMode interpolateLoc(GeMode ge1, GeMode ge2, decimal f)
{
//decimal d = Convert.ToDecimal(getHeading(ge1, ge2));
decimal lat = ge1.lat + f * (ge2.lat - ge1.lat);
decimal lng = ge2.lng + f * (ge2.lng - ge1.lng);
GeMode ge = new GeMode(lat, lng);
return ge;
}
#endregion
#region
/**
* 经线方向长度转化成纬度
* @param {leng} 经线向量长度(米)
* @return 返回纬度差
*/
private static decimal lenToLat(decimal leng)
{
var L = 10002150; // 半个经线长度(经线圈的1/4),对应90°纬度
var angle = 90 * leng / L; return angle;
}
/**
* 纬线方向长度转化成经度
* @param {lat} 纬度值
* @param {leng} 纬线向量长度(米)
* @return 返回精度差
*/
private static decimal lenToLng(decimal lat, decimal leng)
{
var L = 20037508; // 赤道一半长度(半圈,对应180°经度)
var latL = Convert.ToDecimal(L * Math.Cos(Math.PI / 180 * Convert.ToDouble(lat))); // 指定纬度对应的纬线长度(半圈)
var angle = 180 * leng / latL;
return angle;
}
///
/// 根据已知相邻3点,求中点的等距平行点经纬度
///
/// @param {p0, p1, p2} 相邻三个LatLng点
///
///
/// @return {t} 待求平行点到线段的垂直距离
///
public static GeMode getParallelPoint(GeMode p0, GeMode p1, GeMode p2, double t)
{
// 经纬度分别转换成长度单位
decimal y12 = p2.lat - p1.lat;
decimal x12 = p2.lng - p1.lng;
decimal y01 = p1.lat - p0.lat;
decimal x01 = p1.lng - p0.lng;
double a, b;
if (x12 == 0)
{
a = Math.PI / 2;
if (y12 < 0)
a = -a;
}
else
{
a = Math.Atan(Convert.ToDouble(y12 / x12));
}
if (x01 == 0)
{
b = Math.PI / 2;
if (y01 < 0)
b = -b;
}
else
{
b = Math.Atan(Convert.ToDouble(y01 / x01));
}
//alert(b);
// 关键核心处
if (p2.lng < p1.lng)
{
a += Math.PI;
}
if (p1.lng < p0.lng)
{
b += Math.PI;
}
var k = (b - a - Math.PI) / 2;
var r = a + k;
var d = t / Math.Sin(k);
var sinr = Math.Sin(r);
var cosr = Math.Cos(r);
// alert(d * sinr);
var d_lat = lenToLat(Convert.ToDecimal(d * sinr));
var d_lng = lenToLng(p1.lat, Convert.ToDecimal(d * cosr));
d_lat = p1.lat + d_lat;
d_lng = p1.lng + d_lng;
GeMode g = new GeMode(d_lat, d_lng);
return g;
// addMark(obj);
}
#endregion
public class GeMode
{
///
///
///
/// 纬度
/// 进度
public GeMode(decimal lat, decimal lng)
{
_lat = lat;//
_lng = lng;//
}
private decimal _lat;
private decimal _lng;
public decimal lat
{
set { _lat = value; }
get { return _lat; }
}
public decimal lng
{
set { _lng = value; }
get { return _lng; }
}
}
}