Class: Basemap

Basemap

new Basemap(options)

document/mapCollection/Basemap.js, line 9

支持如下方法:
[1、销毁Map对象]
[2、通过json对象构造并返回一个新的Map对象]
[3、转换为json对象]
[4、克隆并返回一个新的Map对象]

基础地图对象
[ES5引入方式]:
zondy.Basemap()
[ES6引入方式]:
import { Map } from "@mapgis/webclient-common"

Name Type Description
options Object

构造参数

Name Type Default Description
baseLayers Collection new Collection() 可选

图层管理器

id String '' 可选

基础地图的ID

title String '' 可选

基础地图的名称

thumbnailUrl String '' 可选

基础地图的缩略图地址

Fires
  • Map#event:添加基础图层事件
Example

添加底图图层

// ES5引入方式
const { Map, Basemap, Collection } = zondy
const { IGSTileLayer } = zondy.layer
// ES6引入方式
import { Map, Basemap, Collection, IGSTileLayer } from "@mapgis/webclient-common"
//创建Map对象
const map = new Map({
  // 初始化底图图层集合
  basemap: new Basemap({
    // 可以设置多个图层到底图集合中
    baseLayers: new Collection(
      [
        // 创建一个图层
        new IGSTileLayer({
          url: '服务及地址'
        })
      ]
    )
  })
});

Extends

Members

baseLayersCollection

图层管理容器中包含的图层

idString

基础地图的id

spatialReferenceSpatialReference

基础地图的坐标系

thumbnailUrlString

基础地图的缩略图地址

titleString

基础地图的名称

Events

底图图层创建事件(已废弃)

document/mapCollection/Basemap.js, line 54
Properties:
Name Type Description
event Object

事件对象

Properties
Name Type Default Description
type LayerEventType 'layerview-created' 可选

事件类型

layer Layer 可选

事件接收对象

layerView LayerView 可选

事件地图视图中心

view BaseView 可选

事件地图视图对象

Example

视图图层创建事件

basemap.on('layerview-created', (event) => {
  console.log("添加地图图层事件:", event)
})

底图图层更新事件(已废弃)

document/mapCollection/Basemap.js, line 80
Properties:
Name Type Description
event Object

事件对象

Properties
Name Type Default Description
type LayerEventType 'layerview-update' 可选

事件类型

layer Layer 可选

事件接收对象

layerView LayerView 可选

事件地图视图中心

view BaseView 可选

事件地图视图对象

Example

视图图层创建事件

basemap.on('layerview-update', (event) => {
  console.log("添加地图图层事件:", event)
})

底图图层移除事件(已废弃)

document/mapCollection/Basemap.js, line 67
Properties:
Name Type Description
event Object

事件对象

Properties
Name Type Default Description
type LayerEventType 'layerview-remove' 可选

事件类型

layer Layer 可选

事件接收对象

layerView LayerView 可选

事件地图视图中心

view BaseView 可选

事件地图视图对象

Example

视图图层创建事件

basemap.on('layerview-remove', (event) => {
  console.log("添加地图图层事件:", event)
})

Methods

Basemap.fromJSON(json){Map}

document/mapCollection/Basemap.js, line 143

通过json对象构造并返回一个新的Map对象

Name Type Description
json Object

json数据

Returns:
Type Description
Map 一个新的Map对象

clone(){Basemap}

document/mapCollection/Basemap.js, line 166

克隆并返回一个新的Map对象

Returns:
Type Description
Basemap 新的Basemap对象

destroy()

document/mapCollection/Basemap.js, line 173

销毁Map对象

inherited off(types, fn, context){Object}

base/Evented.js, line 328
Name Type Description
types string 可选

移除指定事件类型上绑定的回调函数
当类型为字符串时,可以移除单个或多个事件类型绑定的回调函数,单个事件:"click",多个事件:以空格分割:"click double-click";
当types为对象时,使用如下方式移除事件:{'click': onClickFun, 'mouse-move': onMouseMoveFun}

fn function 可选

事件回调函数,当types为字符串,且不指定要删除的回调函数时,删除该事件上的所有回调函数

context Object 可选

事件回调函数的this关键字将指向的对象

Returns:
Type Description
Object 当前实例
Examples

移除一个事件的指定回调函数

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
}
// 调用MapView或SceneView的off方法移除一个事件的回调函数
view.off('click', clickFunction)

移除一个事件的所有回调函数

// 一个事件的回调函数1
const clickFunction1 = function (event) {
  console.log("点击事件1:", event)
}

// 一个事件的回调函数2
const clickFunction2 = function (event) {
  console.log("点击事件2:", event)
}

// 调用MapView或SceneView的off方法移除一个事件的所有回调函数
// 不指定回调函数,则移除该事件上的所有绑定的回调函数
view.off('click')

移除多个事件的同一个指定的回调函数

// 多个事件的同一个回调函数
const eventFunction = function (event) {
  console.log("事件:", event)
}
// 调用MapView或SceneView的off方法移除多个事件的同一个指定的回调函数
view.off('click double-click', eventFunction)

移除多个指定事件的回调函数

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("click事件:", event)
}
// 调用MapView或SceneView的off方法移除多个指定事件的回调函数
view.off({
   // 移除click事件上一个指定的函数
  "click": clickFunction,
  // 移除double-click上所有指定的函数
  "double-click": undefined
})

删除时指定上下文 - types类型为字符串

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
}
// 调用MapView或SceneView的off方法移除一个事件的回调函数
view.off('click', clickFunction, view)
// 调用MapView或SceneView的off方法移除一个事件的所有回调函数
view.off('click', undefined, view)

删除时指定上下文 - types类型为对象

// 一个事件的回调函数
const clickFunction = function (event) {
  console.log("click事件:", event)
}
// 调用MapView或SceneView的off方法移除多个指定事件的回调函数
view.off({
   // 移除click事件上一个指定的函数
  "click": clickFunction,
  // 移除double-click上所有指定的函数
  "double-click": undefined
}, view)

inherited on(types, fn, context){Object}

base/Evented.js, line 232
Name Type Default Description
types String | Object null 可选

事件类型
当types为字符串时,可以定义单个或多个事件,单个事件:"click",多个事件:以空格分割:"click double-click";
当types为对象时,使用如下方式指定事件:{'click': onClickFun, 'mouse-move': onMouseMoveFun}

fn function null 可选

事件回调函数

context Object null 可选

事件回调函数的this关键字将指向的对象

Returns:
Type Description
Object 当前实例
Examples

注册一个事件

// 初始化一个点击事件回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
}
// 调用MapView或SceneView的on方法注册一个点击事件
view.on('click', clickFunction)

一次注册多个事件 - 同一个回调函数

// 初始化一个事件回调函数
const eventFunction = function (event) {
  console.log("事件:", event)
}

// 调用MapView或SceneView的on方法注册多个事件
// 多个事件类型使用同一个回调函数
view.on('click right-click-down', eventFunction)

一次注册多个事件 - 分别指回调应函数

// 初始化一个左键点击事件回调函数
const clickFunction = function (event) {
  console.log("click事件:", event)
}

// 初始化一个右键按下事件回调函数
const rightClickFunction = function (event) {
  console.log("right-click-down事件:", event)
}

// 调用MapView或SceneView的on方法注册多个事件
// 每一个事件类型,使用单独的回调函数
// 注意使用此种方式,一种类型的事件仅能指定一个回调函数
view.on({
  "click": clickFunction,
  "right-click-down": rightClickFunction
})

指定上下文 - types类型为字符串

// 初始化一个点击事件回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
  console.log("上下文对象:", this)
}
// 调用MapView或SceneView的on方法注册一个点击事件
// 指定view为回调函数的上下文对象
view.on('click', clickFunction, view)

指定上下文 - types类型为对象

// 初始化一个点击事件回调函数
const clickFunction = function (event) {
  console.log("点击事件:", event)
  console.log("上下文对象:", this)
}
// 调用MapView或SceneView的on方法注册一个点击事件
// 指定view为回调函数的上下文对象
view.on({
  "click": clickFunction,
  "right-click-down": clickFunction
}, view)

toJSON(){Object}

document/mapCollection/Basemap.js, line 152

转换为json对象

Returns:
Type Description
Object 导出的json对象