Class: Map

CMAP.Map(options)

地图类

Constructor

new Map(options)

构造函数
Parameters:
Name Type Description
options Object 参数列表
Properties
Name Type Description
type String 类型'Map'
terrainUrl String 地形服务url,如果不传就不加地形,目前地形必须在map初始化时设置,设置后,会创建一个TerrainLayer并且赋值给Map.terrainLayer
这里的地形服务是遵循TMS切片规范的terrain格式的地形服务
一个高程数据集的瓦片url类似于:https://assets.cesium.com/1/{z}/{x}/{y}.terrain(需要token才可以访问)
atmosphere Boolean 是否开启大气效果,默认为 true
style CMAP.MapStyle 地图渲染效果
restrictedLevel Array 地图最大最小缩放级别 之前的属性名为level 也支持但推荐使用restrictedLevel 默认[0,22]
attribution String 右下角地图的版权信息
Author:
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:
Author:

attribution :String

设置地图的attribution,在地图右下角有一个小方盒子中呈现,如果不填写,会默认展示ThingJs的超链接, 如果填写,会在ThingJS后添加相应的内容
系统内置了几种常用的地图的attribution的写法,如Google OSM Carto GeoQ Gaode,系统会自动生成对应的attribution.
如果传none 则不会生成attribution
也可以自定义attribution
Type:
  • String
Author:
Example
map.attribution = 'Google';//设置谷歌地图的版权信息
map.attribution = 'My Attribution'; //自定义版权信息 右下角会展示ThingJS|My Attribuition
map.attribution = 'none'; //不显示版权信息

(readonly) baseLayers :CMAP.BaseLayerCollection

基础底图集合
Type:
Author:

(readonly) currentLevel :Number

获取当前地图层级
Type:
  • Number
Author:

level :Array

设置地图可以缩放层级,默认是[0,22] 推荐使用restrictedLevel
Type:
  • Array
Deprecated:
  • Yes
Author:
Example
map.style.level = [0,18]; //设置地图默认缩放层级为最小0最大18

maxPitch :Number

地图最大俯仰角 最大90
Type:
  • Number
Author:
Example
map.maxPitch = 60; //设置地图最大俯仰角为60度

restrictedLevel :Array

设置地图可以缩放层级,默认是[0,22]
Type:
  • Array
Author:
Example
map.style.restrictedLevel = [0,18]; //设置地图默认缩放层级为最小0最大18

terrainLayer :CMAP.TerrainLayer

地形图层
Type:
Author:

(readonly) userLayers :CMAP.UserLayerCollection

业务图层的集合
Type:
Author:

(readonly) util :CMAP.Util

地球相关工具,包括坐标转换,角度计算等 也可通过CMAP.Util获取
Type:
Author:

visible :boolean

地球是否显示 true:显示;false:不显示
Type:
  • boolean
Author:
Example
map.visible = false;//不显示地球

Methods

addLayer(layer) → {void}

map中添加layer,可以添加FeatureLayer、ThingLayer、TileLayer等
Parameters:
Name Type Description
layer CMAP.TileLayer | CMAP.ThingLayer | CMAP.FeatureLayer 需要添加的图层
Author:
Returns:
Type
void

destroy()

销毁地球实例,释放内存

getLayerByName(name) → {THING.Selector}

根据图层名称获取图层
Parameters:
Name Type Description
name String 图层实例的name
Author:
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 需要移除的图层
Author:
Returns:
Type
void

rotate(param) → {void}

地球旋转
Parameters:
Name Type Description
param Object 参数列表
Properties
Name Type Description
angle Number 旋转角度
speed Number 旋转速度 单位:(度/秒)
complete Number 旋转完毕后的回调函数
Author:
Returns:
Type
void