var ge;
google.load("earth", "1");
function init() {
google.earth.createInstance('map3d', initCallback, failureCallback);
addSampleButton('Create a Circle!', buttonClick);
}
function initCallback(instance) {
ge = instance;
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_ROADS, true);
var la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
la.setRange(50000);
ge.getView().setAbstractView(la);
createCirclePolygon();
document.getElementById('installed-plugin-version').innerHTML =
ge.getPluginVersion().toString();
}
function failureCallback(errorCode) {
}
function createCirclePolygon() {
function makeCircle(radius, x, y) {
var center = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
var ring = ge.createLinearRing('');
var steps = 100;
var pi2 = Math.PI * 2;
for (var i = 0; i < steps; i++) {
var lat = 30 + x + radius * Math.cos(i / steps * pi2);
var lng = -85 + y + radius * Math.sin(i / steps * pi2);
ring.getCoordinates().pushLatLngAlt(lat, lng, 0);
}
return ring;
}
var polygonPlacemark = ge.createPlacemark('');
polygonPlacemark.setGeometry(ge.createPolygon(''));
var outer = ge.createLinearRing('');
polygonPlacemark.getGeometry().setOuterBoundary(makeCircle(0.1, 0, 0));
ge.getFeatures().appendChild(polygonPlacemark);
}
function buttonClick() {
createCirclePolygon();
}
嗨,我正在使用谷歌游戏场构建一些代码来创建圆形多边形,我能够绘制圆形,我只是想重定向地图,我正在绘制圆形多边形,但它重定向到一些其他地方(默认地点),我如何使用我的代码更改这个,任何帮助高度赞赏
答案 0 :(得分:0)
您可以尝试使用fitBounds()将地图重定向到有绘制内容的地方
var bounds = new google.maps.LatLngBounds();
bounds.extend(marker.position);
map.fitBounds(bounds);
适用于标记