Constructor
new Map(options)
构造函数
Parameters:
Name | Type | Description | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object | 参数列表
Properties
|
Example
var app = new THING.App({
container: 't3d', // 3D 的容器
});
//直接创建Map对象
var map = app.create({
type: 'Map'
atmosphere :false,//不开大气效果 默认开启
terrainUrl: 'http://data.marsgis.cn/terrain',//地形服务url
restrictedLevel:[0,22],//定义地图层级
maxPitch:82,//地球最大俯仰角度,不能大于90
style:{
night:false, //不开启白天黑夜 默认开启
fog :false //开启雾效果 默认关闭 目前该参数只能在初始化时设置
},
attribution:'Google' //地图右下角的信息
});
//通过CityBuilder导出的url创建地图
var map = app.create({
type: 'Map'
url:'https://www.thingjs.com/citybuilder_console/mapProject/config/TVRFNE9UZz1DaXR5QnVpbGRlckAyMDE5',
complete:function(e){
//地图上要素创建完毕的回调函数
console.log(e.object.userLayers.length);
}
});
map.on('click',function (event){
//对于Map 事件返回的属性中添加了coordinates 代表点击的经纬度信息
console.log(event.coordinates);
});
Extends
- THING.BaseObject
Members
(readonly) allLayers :CMAP.LayerCollection
所有图层的集合,包含baseLayers,terrainLayer,useLayers
Type:
attribution :String
设置地图的attribution,在地图右下角有一个小方盒子中呈现,如果不填写,会默认展示ThingJs的超链接,
如果填写,会在ThingJS后添加相应的内容
系统内置了几种常用的地图的attribution的写法,如Google OSM Carto GeoQ Gaode,系统会自动生成对应的attribution.
如果传none 则不会生成attribution
也可以自定义attribution
Type:
- String
Example
map.attribution = 'Google';//设置谷歌地图的版权信息
map.attribution = 'My Attribution'; //自定义版权信息 右下角会展示ThingJS|My Attribuition
map.attribution = 'none'; //不显示版权信息
(readonly) baseLayers :CMAP.BaseLayerCollection
基础底图集合
Type:
(readonly) currentLevel :Number
获取当前地图层级
Type:
- Number
level :Array
设置地图可以缩放层级,默认是[0,22] 推荐使用restrictedLevel
Type:
- Array
- Deprecated:
- Yes
Example
map.style.level = [0,18]; //设置地图默认缩放层级为最小0最大18
maxPitch :Number
地图最大俯仰角 最大90
Type:
- Number
Example
map.maxPitch = 60; //设置地图最大俯仰角为60度
restrictedLevel :Array
设置地图可以缩放层级,默认是[0,22]
Type:
- Array
Example
map.style.restrictedLevel = [0,18]; //设置地图默认缩放层级为最小0最大18
terrainLayer :CMAP.TerrainLayer
地形图层
Type:
(readonly) userLayers :CMAP.UserLayerCollection
业务图层的集合
Type:
(readonly) util :CMAP.Util
地球相关工具,包括坐标转换,角度计算等 也可通过CMAP.Util获取
Type:
visible :boolean
地球是否显示 true:显示;false:不显示
Type:
- boolean
Example
map.visible = false;//不显示地球
Methods
addLayer(layer) → {void}
map中添加layer,可以添加FeatureLayer、ThingLayer、TileLayer等
Parameters:
Name | Type | Description |
---|---|---|
layer |
CMAP.TileLayer | CMAP.ThingLayer | CMAP.FeatureLayer | 需要添加的图层 |
Returns:
- Type
- void
destroy()
销毁地球实例,释放内存
getLayerByName(name) → {THING.Selector}
根据图层名称获取图层
Parameters:
Name | Type | Description |
---|---|---|
name |
String | 图层实例的name |
Returns:
图层的集合
- Type
- THING.Selector
Example
var layer = map.getLayerByName('name1');//获取name为name1的图层
removeLayer(layer) → {void}
map中移除layer,可以移除FeatureLayer、ThingLayer、TileLayer等
Parameters:
Name | Type | Description |
---|---|---|
layer |
CMAP.TileLayer | CMAP.ThingLayer | CMAP.FeatureLayer | 需要移除的图层 |
Returns:
- Type
- void
rotate(param) → {void}
地球旋转
Parameters:
Name | Type | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
param |
Object | 参数列表
Properties
|
Returns:
- Type
- void