(function () {
var map = parent.map;//二维地图。二维、三维各自放在一个iframe里。
var sgworld = parent.sgworld;//三维对象
var token = parent.token;//当前控制权在二维还是三维?
//二维控制三维
dojo.connect(map, "onMouseUp", function () {
token.set2D();//当前控制权在二维
});
dojo.connect(map, "onMouseWheel", function () {
token.set2D();
});
dojo.connect(map, "onExtentChange", function(eve) {
if (token.is3D()) return;
var pointLB = utils.xyToLngLat(eve.xmin, eve.ymin);//左下
var pointRT = utils.xyToLngLat(eve.xmax, eve.ymax);//右上
var xMax = pointRT[0];
var yMax = pointRT[1];
var xMin = pointLB[0];
var yMin = pointLB[1];
_move3DMapTo(xMax, yMax, xMin, yMin);
});
//三维控制二维
sgworld.AttachEvent("OnLButtonUp", function () {
token.set3D();//当前控制权在三维
_move2DMapTo();
});
sgworld.AttachEvent("OnMouseWheel", function () {
token.set3D();
_move2DMapTo();
});
function _move2DMapTo() {//二维跟随移动
var rect = sgworld.Window.Rect;
var positionMax = sgworld.Window.PixelToWorld(0, rect.Height - 1, -1).Position;
var positionMin = sgworld.Window.PixelToWorld(rect.Width - 1, 0, -1).Position;
var extent = new esri.geometry.Extent({ "xmax": positionMin.X, "ymax": positionMin.Y, "xmin": positionMax.X, "ymin": positionMax.Y });
map.setExtent(extent);
}
function _move3DMapTo(xMax, yMax, xMin, yMin) {//三维跟随移动
var lgtd = (xMax + xMin) / 2;
var lttd = (yMax + yMin) / 2;
var altitude = sgworld.CoordServices.GetDistance(xMax, yMax, xMin, yMin);
var altitudeTypeCode = 0;
var yaw = 0.0;
var pitch = -90;
var roll = 0.0;
var distance = sgworld.CoordServices.GetDistance(xMax, yMax, xMin, yMin);
var pPosition = sgworld.Creator.CreatePosition(lgtd, lttd, altitude, altitudeTypeCode, yaw, pitch, roll, distance);
sgworld.Navigate.SetPosition(pPosition);
}
})();