如何设置Cesium JS地图中心(坐标:纬度和经度) [英] How to set Cesium JS map center (coordinates: latitude & longitude)

查看:2303
本文介绍了如何设置Cesium JS地图中心(坐标:纬度和经度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想初始化 cesium ,以便地图以某些特定坐标为中心而不是默认坐标。我有以下初始化代码:

I would like to initialize cesium so that the map is centered on some specific coordinates instead of the default ones. I have the following initialization code:

var map = new Cesium.CesiumWidget('map-js');
map.centralBody.terrainProvider = new Cesium.CesiumTerrainProvider({
    url : 'http://cesiumjs.org/smallterrain'
});

通常,对于其他映射库,我会在初始化时设置中心,例如在mapbox上:

Usually, with other mapping libraries, I would set the center on initialization, eg on mapbox:

map = L.mapbox.map('map-js', 'api-key').setView([42.12, 12.45], 9);

如何用 cesium 做到这一点?

推荐答案

尝试在上面第一段代码后添加:

Try adding this after your first block of code above:

var scene = map.scene;
var ellipsoid = Cesium.Ellipsoid.WGS84;
var west = Cesium.Math.toRadians(-77.0);
var south = Cesium.Math.toRadians(38.0);
var east = Cesium.Math.toRadians(-72.0);
var north = Cesium.Math.toRadians(42.0);

var extent = new Cesium.Rectangle(west, south, east, north);
scene.camera.viewRectangle(extent, ellipsoid);

我们的相机演示

编辑(2014年5月):由于Cesium API更改, .getCamera()重命名为 .camera ,相机的 .controller 已删除并滚入相机本身, Extent 重命名为 Rectangle 。上面的代码现在反映了新的API。有关重大更改的完整列表,请参阅 CHANGES.md

EDIT (May 2014): Due to Cesium API changes, .getCamera() is renamed .camera, the camera's .controller was removed and rolled into the camera itself, and Extent is renamed to Rectangle. The above code now reflects the new API. For a complete list of breaking changes, see CHANGES.md.

这篇关于如何设置Cesium JS地图中心(坐标:纬度和经度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆