THING.EARTH.Map(param)

地图对象

new Map(param)

构造函数

Parameters:
Name Type Description
param Object 参数列表
Properties
Name Type Attributes Default Description
terrain Terrain <optional>
地形对象
sceneMode THING.EARTH.SceneMode <optional>
THING.EARTH.SceneMode.EarthView 地图场景类型 三维地球 or 2.5维平面地图
projectionType THING.EARTH.MapProjectionType <optional>
THING.EARTH.MapProjectionType.Geographic 2.5维平面地图时 创建平面使用的投影类型 经纬度直投 or Web墨卡托投影
isChinaCentered Boolean <optional>
false 2.5D下 中国是否居中显示 默认情况下 中国在东边,美洲在西边
style THING.EARTH.MapStyle <optional>
地图样式 主要是指大气 雾效等地球级别的样式 数据结构可参考THING.EARTH.MapStyle
baseMaps Object | Array.<Object> <optional>
瓦片配置 可能是对象或数组 对象的数据结构可参考THING.EARTH.TileLayer 如果是以为数组,代表是多层瓦片,如果是二维数据代表多级瓦片
renderSettings THING.EARTH.MapRenderSettings | Array.<THING.EARTH.MapRenderSettings> <optional>
环境参数配置 包括灯光、后期、背景参数,数据结构可参考THING.EARTH.MapRenderSettings 如果是数组,代表多级环境参数
layers Array.<Object> <optional>
图层配置 数据结构可参考THING.EARTH.FeatureLayer/THING.EARTH.BigDataLayer
restrictedLevel Array.<Number> <optional>
地图最大最小缩放级别 默认全级别显示
attribution String <optional>
右下角地图的版权信息 支持google、amap、osm、tianditu、baidu、tencent或者自定义
minPitch Number <optional>
8 相机最小倾角
maxPitch Number <optional>
89.9 相机最大倾角
depthMode THING.EARTH.DepthMode <optional>
THING.EARTH.DepthMode.DepthGlobe 深度模式 默认是深度球模式,只有地球背面的物体会被遮挡,
如果设置为THING.EARTH.DepthMode.Earth 地形会开启深度 会遮挡地球上创建的对象
如果设置为THING.EARTH.DepthMode.None 地形不会遮挡任何对象 包括地球背面的对象
blurActiveElementOnCanvasFocus Boolean <optional>
true 点击地图场景时 是否让当前正在输入/激活的元素失去焦点 默认为true
url String <optional>
地图场景的url 指向一个地图场景的json文件 如果使用url创建地图场景
style,baseMaps,lights,postEffects,background,layers,terrain均使用url指向的地图场景中的配置
resourceConfig Object <optional>
加载地图场景时的资源配置
Properties
Name Type Attributes Default Description
baseLayerUrls Array | String <optional>
需要替换地图场景中的瓦片地址 数据结构与地图场景中的瓦片一致,如果传字符串,会整体替换所有瓦片的url
resourcePrefix String <optional>
资源前缀 会给地图包中的资源相对路径添加资源前缀 包括数据,贴图,模型等资源
useDynamicExtrude Boolean <optional>
false 创建建筑是否支持动态修改拔高和离地高度 默认是false 如果要支持 需要设置为true 并且将usePickId也设置为true
usePickId Boolean <optional>
false 创建BigDataLayer 是否支持拾取 默认false
loadHiddenLayers Boolean <optional>
true 是否加载地图包中隐藏的图层
onComplete function <optional>
创建完成的回调函数
Author:
  • caihuimin

Extends

  • THING.Object3D

Members

active :Boolean

设置地图的显示/隐藏状态 不会影响图层的显示隐藏状态

Default Value:
  • true

readonly allLayers :LayerCollection

地图上全部图层对象

attribution :String

设置/获取 地图的attribution

Author:
Example
map.attribution = '高德';//设置高德地图的版权信息
		map.attribution = 'My Attribution'; //自定义版权信息 右下角会展示ThingJS|My Attribuition
		map.attribution = 'none'; //不显示版权信息

readonly baseLayers :LayerCollection

获取基础地图集合

clippingArea :Array

地图挖洞区域

符合Polygon类型的坐标
Example
map.clippingArea = [[[116,39],[116,40],[117,40],[117,39],[116,39]]];

readonly currentLevel :Number

获取地图当前层级

depthMode :Boolean

设置深度模式0 (DepthMode.None) 不使用地球深度1 (DepthMode.DepthGlobe)采用深度球,深度球的半径要比地球半径小一些,这样地球背面的东西会被遮挡 但地球上的面和线仍然会显示 默认采用这种模式2 (DepthMode.Earth)采用地球瓦片真实深度,这样可能地球上直连的线和大面会被遮挡或者撕面,但是如果有地形或者有半地下的场景,需要采用这种模式应用时可以根据应用场景切换深度模式

Example
map.depthMode = DepthMode.None;//不使用地球的深度
map.depthMode = DepthMode.DepthGlobe;//采用深度球的深度
map.depthMode = DepthMode.Earth;//采用地球瓦片真实深度

disableMapLevelChange :Boolean

是否禁用地球层级切换事件

Example
map.disableMapLevelChange = true;//禁用地球层级切换事件

readonly layers :LayerCollection

业务图层的集合

maxPitch :Number

设置/获取地图相机的最大倾角 默认89.9

Example
map.maxPitch = 80

minPitch :Number

设置/获取地图相机的最小倾角 默认8

Example
map.minPitch = 10

readonly mode :THING.EARTH.SceneMode

地图场景类型 三维地球 or 2.5维平面地图

Default Value:
  • THING.EARTH.SceneMode.EarthView

readonly projectionType :THING.EARTH.MapProjectionType

2.5维平面地图时 创建平面使用的投影类型 经纬度直投 or Web墨卡托投影

Default Value:
  • THING.EARTH.MapProjectionType.Geographic

readonly renderSettings :MapRenderSettings

地图环境配置 包括灯光 后期 背景等

restrictedLevel :Array.<Number>

设置/获取地图缩放层级 默认为[0,23]

Example
map.restrictedLevel = [0,18]; //设置地图默认缩放层级为最小0最大18

readonly style :MapStyle

获取地图样式 如需要修改可以使用map.style.xxx = value;

terrain :Terrain

获取/设置地形

Example
map.terrain = new THING.EARTH.Terrain({url:'http://data.marsgis.cn/terrain'});

useDepthStencilRenderBufferWhenUseMSAA :Boolean

当开启MSAA时,是否使用深度模板作为帧缓冲区的附件,默认为false,只有深度附件注意:如果开启MSAA且加载贴地面和一部分倾斜摄影数据时,该参数应设置为true,否则效果会有问题

Default Value:
  • false

visible :Boolean

设置/获取地图是否可见

Example
map.visible = false;//设置地球不可见 会隐藏地球上所有物体

Methods

addBaseLayer(layer) → {Promise.<Object>}

添加基础底图

Parameters:
Name Type Description
layer Layer
Returns:
Promise.<Object>
Example
const layer = new TileLayer({
			url:"http://webst01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}"
		});
			map.addBaseLayer(layer);//将瓦片图层作为底图加入地球

addLayer(layer, renderOrder) → {Promise.<Layer>}

添加图层到地图上

Parameters:
Name Type Description
layer Layer 待添加图层
renderOrder Number 渲染顺序 渲染顺序越大越后渲染
Returns:
Promise.<Layer>
Example
const layer = new FeatureLayer({
			url:"data.geojson",
			geoObjectType: "GeoPoint",
			style: {
				pointType: "Image",
				url: "../texture/pop.png",
				size: 4				
			}
		});
		map.addLayer(layer).then(()=>{
			console.log('layer loaded!')
		});

destroy() → {Boolean}

销毁地图

销毁地图时,会卸载所有图层,卸载大气,修改相机锚点矩阵为单位矩阵,同时也会卸载所有注册事件
Returns:
Boolean - - 销毁成功

getCenter() → {Array.<Number>}

获取地图中心点

Returns:
Array.<Number>

getExtent() → {Extent}

获取当前可视范围

Returns:
Extent

getLayerById(id) → {Layer}

根据id获取图层

Parameters:
Name Type Description
id String 图层的id
Returns:
Layer
Example
map.getLayerById(1) //获取id为1的图层

getLayerByName(name) → {Selector}

根据名称获取图层

Parameters:
Name Type Description
name String 图层的name
Returns:
Selector
Example
map.getLayerByName('layerName') //获取name为layerName的图层集合

loadLayers(layersConfig, resourceConfig)

根据图层配置加载图层

Parameters:
Name Type Description
layersConfig Array 图层配置(2.0的配置)
resourceConfig Object 资源配置
Properties
Name Type Description
resourcePrefix String 资源前缀

removeBaseLayer(layer) → {Boolean}

移除基础底图

Parameters:
Name Type Description
layer Layer
Returns:
Boolean
Example
const layer = map.baseLayer[0] //瓦片图层
			map.removeBaseLayer(layer);     //移除瓦片图层

removeLayer(layer) → {Boolean}

移除地图上的图层

Parameters:
Name Type Description
layer Layer 待添加图层
Returns:
Boolean
Example
const layer = map.layers[0];
map.removeLayer(layer);        //删除第一个图层

removeLayerById(id) → {Boolean}

根据id移除图层

Parameters:
Name Type Description
id String
Returns:
Boolean
Example
map.removeLayerById(1);

rotate(param)

地球旋转

Parameters:
Name Type Description
param Object 参数列表
Properties
Name Type Description
angle Number 旋转角度
speed Number 旋转速度 单位:(度/秒)
complete function 旋转完毕后的回调函数
Example
map.rotate({angle:360}); //地球自传360度

switchTo3DView(time, options)

切换到3D地球视图 注意:切换时地球上创建的物体不会跟着切换,需要上层控制隐藏或销毁

Parameters:
Name Type Default Description
time Number 1000 切换时间
options Object 切换选项
Properties
Name Type Description
onComplete function 切换完成回调
Example
map.switchTo3DView(1000, () => {
  console.log('切换完成');
});

switchToPlanView(time, options)

切换到3D地球视图 注意:切换时地球上创建的物体不会跟着切换,需要上层控制隐藏或销毁

Parameters:
Name Type Default Description
time Number 1000 切换时间
options Object 切换选项
Properties
Name Type Description
mapProjectionType MapProjectionType 地图投影类型
isChinaCentered Boolean 是否居中显示中国
onComplete function 切换完成回调
Example
map.switchTo3DView(1000, () => {
  console.log('切换完成');
});

toJSON() → {Object}

导出地图配置

Returns:
Object - result

updateByMapConfig(config, resourceConfig)

给地图应用效果模板 支持1.0的配置与2.0的配置

Parameters:
Name Type Description
config Object 效果模板的配置参数
resourceConfig Object 资源配置
Properties
Name Type Description
ignoreParams Boolean 要忽略的配置项 例如basemaps,lights,camera等
removeUnmatched Boolean 是否移除未匹配的图层
resourcePrefix String 资源前缀