Class: View

olview~ View


new View(options)

视图,负责地图的初始化、调度、管理等功能,是地图的最核心部分。
Parameters:
Name Type Description
options Object
Properties
Name Type Argument Default Description
target HTMLElement | String 视图所在的容器
name String <optional>
'二维视图' 视图名称
layers Array.<module:olview.Layer> <optional>
[ ] 初始视图的时候,需要加载的图层
projection Projection | String <optional>
'EPSG:4326' 地图投影坐标系
center Coordinate <optional>
[100, 30] 初始化地图时,视角所在经纬度位置
zoom Number <optional>
4 初始化地图时,地图的缩放层级
Fires:
  • event:ChangeProjection
Example
var olView = new sg.olview.View({
    target: 'map2d',
    layers: [new sg.olimage.GeoqTileLayer({
         name: 'google地图影像',
         url: 'https://mt0.google.cn/vt/lyrs=s&hl=zh-CN&gl=cn&x={x}&y={y}&z={z}'
    })]
});

Extends

Methods


getName()

获取视图名称

setName(value)

设置视图名称
Parameters:
Name Type Description
value String

getMap()

获取openlayers原始map对象

getProjection()

获取当前地图的投影坐标系

setProjection(newProjection)

设置当前地图的投影坐标系
Parameters:
Name Type Description
newProjection Projection | String

getCamera()

获取视图的相机
See:
Example
var camera = olView.getCamera();
camera.zoomToClientPos([100,40], [130,10]);

getRootLayer()

获取视图的根图层(组)

addLayer(layer)

添加图层
Parameters:
Name Type Description
layer module:olview.Layer 图层对象,有各种影像图层,矢量图层,态势符号图层、动目标图层等

removeLayer(layer)

移除图层
Parameters:
Name Type Description
layer module:olview.Layer 图层对象

removeLayers()

移除所有图层

getLayers()

获取所有图层

getLayerByName(value)

根据图层名称获取图层对象
Parameters:
Name Type Description
value String 图层名称

removeLayerByName(value)

根据图层名称移除图层对象
Parameters:
Name Type Description
value String 图层名称

moveLayer(layer, newIndex)

将指定图层对象移动到新的位置
Parameters:
Name Type Description
layer module:olview.Layer 图层对象
newIndex Number 索引号

getLayerIndex(layer)

根据图层对象获取该图层所在索引号
Parameters:
Name Type Description
layer module:olview.Layer 图层对象

createPopup(lonlat, content)

创建标牌
Parameters:
Name Type Description
lonlat Coordinate 经纬度坐标,比如[114,30]
content string 标牌内容,支持html格式和样式
Example
var popup = olView.createPopup([114,30], '这是一个标牌');

createPopupDetailed(options)

创建标牌
Parameters:
Name Type Description
options Object
Properties
Name Type Argument Default Description
lonlat Coordinate 经纬度坐标
content string <optional>
'标牌' 标牌内容,支持html格式和样式
offset Array.<number> <optional>
[20, 0] 标牌偏移位置
element HTMLElement <optional>
标牌内容的容器
leadlineColor string <optional>
'cyan' 标牌牵引线的颜色
leadlineWidth number <optional>
2.0 标牌牵引线的宽度
leadlineDash Cesium.Cartesian2 <optional>
[2, 8] 标牌牵引线的虚线样式
lock boolean <optional>
false 是否锁定标牌,锁定的标牌不能通过鼠标移动
Example
var lonlat = [114,30];
var content = '这是一个标牌';
var offset = [0, -40];
var element = document.createElement('div');
var leadlineColor = 'yellow';
var lock = true;
var options = {
    lonlat,
    content,
    offset,
    element,
    leadlineColor,
    lock
}
var popup = olView.createPopupDetailed(options);

removePopup(popup)

移除标牌
Parameters:
Name Type Description
popup module:olview.Popup

removePopups()

移除所有标牌

addHandler(handler)

添加处理器
Parameters:
Name Type Description
handler module:olview.Handler

removeHandler(handler)

移除处理器
Parameters:
Name Type Description
handler module:olview.Handler

removeHandlers()

移除所有的处理器

getHandlers()

获取所有的处理器

setHandlers(handlers)

设置当前处理器或者处理器数组,每次设置会移除已有的处理器
Parameters:
Name Type Description
handlers module:olview.Handler | Array.<module:olview.Handler>

pick(pixel [, hitTolerance])

根据屏幕位置获取在该屏幕位置的最顶层的对象
Parameters:
Name Type Argument Default Description
pixel Pixel 屏幕坐标[x, y],比如 [200,100]
hitTolerance Number <optional>
10 像素容差,点选时候的像素容差
Returns:
对象
Type
Object

drillPick(pixel [, hitTolerance])

根据屏幕位置获取在该屏幕位置的所有对象
Parameters:
Name Type Argument Default Description
pixel Pixel 屏幕坐标[x, y],比如 [200,100]
hitTolerance Number <optional>
10 像素容差,点选时候的像素容差
Returns:
对象数组
Type
Array.<Object>

pickPosition(pixel)

根据屏幕位置获取在该屏幕位置的经纬度坐标
Parameters:
Name Type Description
pixel Pixel 屏幕坐标[x, y],比如 [200,100]
Returns:
[lon, lat]
Type
Coordinate

toJson()

导出为json字符串

<static> fromJson(jsonObject, options)

从json对象中构造视图
Parameters:
Name Type Description
jsonObject Object json对象,保存的是视图对象
options Object
Properties
Name Type Argument Default Description
target HTMLElement | String 视图所在的容器
name String <optional>
'二维视图' 视图名称
projection Projection | String <optional>
jsonObject.projection 地图投影坐标系
center Coordinate <optional>
jsonObject.center 初始化地图时,视角所在经纬度位置
zoom Number <optional>
jsonObject.zoom 初始化地图时,地图的缩放层级
Returns:
Type
module:olview.View

<static> copy(object, newOptions)

拷贝视图对象,构造新的视图
Parameters:
Name Type Description
object module:olview.View 视图对象
newOptions Object
Properties
Name Type Argument Default Description
target HTMLElement | String 视图所在的容器
name String <optional>
'二维视图' 视图名称
projection Projection | String <optional>
object.projection 地图投影坐标系
center Coordinate <optional>
object.center 初始化地图时,视角所在经纬度位置
zoom Number <optional>
object.zoom 初始化地图时,地图的缩放层级
Returns:
Type
module:olview.View

destroy()

销毁视图
Overrides:

dispatchEvent(event)

发送事件消息,每个事件消息都有类型(type),所有监听此对象对应类型事件的监听者都会接收到相应的事件消息
Parameters:
Name Type Description
event string | module:events.Event 事件对象
Inherited From:
Overrides:

on(type, listener [, opt_this])

指定监听器监听指定类型的事件
Parameters:
Name Type Argument Default Description
type string 事件类型
listener callback | function 监听器
opt_this Object <optional>
target 在监听器中的`this`所指示的对象,默认是`target`自身
Inherited From:
Overrides:
Returns:
监听器的唯一标识.
Type
Object

once(type, listener [, opt_this])

指定监听器只监听一次指定类型的事件
Parameters:
Name Type Argument Default Description
type string 事件类型
listener callback | function 监听器
opt_this Object <optional>
target 在监听器中的`this`所指示的对象,默认是`target`自身
Inherited From:
Overrides:
Returns:
监听器的唯一标识.
Type
Object

un(type, listener [, opt_this])

取消指定监听器监听指定类型的事件
Parameters:
Name Type Argument Default Description
type string 事件类型
listener callback | function 监听器
opt_this Object <optional>
target 在监听器中的`this`所指示的对象,默认是`target`自身
Inherited From:
Overrides:

unByKey(key)

根据监听器的唯一标识取消指定监听器监听事件,监听器的唯一标识通过`on()`或者`once()`返回得到
Parameters:
Name Type Description
key Object | Array.<Object> 监听器的唯一标识,通过`on()`或者`once()`返回得到,可以是多个监听器的唯一标识数组
Inherited From:
Overrides: