Class: Point

Point

new Point(options)

base/geometry/Point.js, line 6

点几何对象,使用二维或三维坐标描述一个离散位置。

Name Type Default Description
options Object {} 可选

构造参数

Name Type Default Description
coordinates Array [] 可选

点坐标数组,支持 [x, y][x, y, z]

spatialReference SpatialReference new zondy.SpatialReference('EPSG:4326') 可选

点对象的空间参考系,默认 4326;当使用其他坐标系时建议显式指定。

Examples

创建几何对象

// ES5引入方式
const { Point } = zondy.geometry

// ES6引入方式
import { Point } from "@mapgis/webclient-common"
new Point({
  coordinates: [100.0, 0.0]
})

指定坐标系

// ES5引入方式
const { Point } = zondy.geometry
const { SpatialReference } = zondy

// ES6引入方式
import { Point, SpatialReference } from "@mapgis/webclient-common"
new Point({
  // 现在为3857坐标系
  coordinates: [12929863.44711455, 3377247.5680546067],
  // 当不是4326时请指定坐标系,方便进行投影转换
  spatialReference: new SpatialReference('EPSG:3857')
})

Extends

Members

coordinatesArray

几何点的坐标数组

extensionOptionsObject

初始化几何的额外参数,可以通过该参数传入引擎原生的构造参数

Default Value:
{}

extentNumber

外包盒

hasZBoolean

是否含有z坐标

spatialReferenceSpatialReference

几何点的空间参考系

几何类型

Methods

clone(){Geometry}

base/geometry/Point.js, line 399

克隆几何对象

Returns:
Type Description
Geometry 克隆后的几何对象

copy(point){Point}

base/geometry/Point.js, line 145

将另一个点对象的所有值复制到当前点对象

Name Type Description
point Point

被复制的点对象

Returns:
Type Description
Point 修改后的Point
Example

将另一个点对象的所有值复制到当前点对象

// ES5引入方式
const { Point } = zondy.geometry

// ES6引入方式
import { Point } from "@mapgis/webclient-common"
const point1 = new Point({
  coordinates: [100.0, 0.0]
})
const point2 = new Point({
  coordinates: [200.0, 10.0]
})
point1.copy(point2)

distance(point){Number}

base/geometry/Point.js, line 169

计算与另一个点的距离

Name Type Description
point Point | Array.<Number>

用于计算距离的点

Returns:
Type Description
Number 距离
Example

计算与另一个点的距离

// ES5引入方式
const { Point } = zondy.geometry

// ES6引入方式
import { Point } from "@mapgis/webclient-common"
const point1 = new Point({
  coordinates: [100.0, 0.0]
})
const point2 = new Point({
  coordinates: [200.0, 10.0]
})
const distance = point1.distance(point2)

equals(point){Boolean}

base/geometry/Point.js, line 200

判断两个点是否相等

Name Type Default Description
point Point | Array.<Number> null 可选

点对象或坐标数组

Returns:
Type Description
Boolean 两个点是否相等
Example

判断两个点是否相等

// ES5引入方式
const { Point } = zondy.geometry

// ES6引入方式
import { Point } from "@mapgis/webclient-common"
const point1 = new Point({
  coordinates: [100.0, 0.0]
})
const point2 = new Point({
  coordinates: [200.0, 10.0]
})
const equal = point1.equals(point2)

inherited fire(type, data, propagate){Object}

base/Evented.js, line 523

激发指定类型的事件

Name Type Description
type string 可选

事件类型

data Object 可选

待传递的数据

propagate Boolean 可选

是否传播到父级

Returns:
Type Description
Object 当前实例

inherited fromGeoJSON(GeoJSON)

base/geometry/Geometry.js, line 144

导入GeoJSON

Name Type Description
GeoJSON Object

Object

inherited getGeometryType(){String}

base/geometry/Geometry.js, line 181

获取GeometryModule型

Returns:
Type Description
String GeometryModule型

getIGSType()

base/geometry/Point.js, line 329

返回IGS所对应的GeometryModule型

Returns:
string GeometryModule型

inherited getType(){String}

base/geometry/Geometry.js, line 165

返回所对应的GeometryModule型

Returns:
Type Description
String GeometryModule型

normalize(){Point}

base/geometry/Point.js, line 270

归一化计算

Returns:
Type Description
Point 归一化后的点对象
Example

归一化计算

// ES5引入方式
const { Point } = zondy.geometry

// ES6引入方式
import { Point } from "@mapgis/webclient-common"
const point1 = new Point({
  coordinates: [100.0, 0.0]
})
const normalize = point1.normalize()

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

base/Evented.js, line 337
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 240
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)

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

base/Evented.js, line 592

事件监听,仅触发一次

Name Type Description
types string 可选

将侦听器函数(fn)添加到对象的特定事件类型中。您还可以传递几个空格分隔的类型(例如“click dblclick”),也可以传入例如 {click: onClick, mousemove: onMouseMove}。

fn function 可选

侦听器函数

context Object 可选

指定侦听器的上下文(this关键字将指向的对象)

Returns:
Type Description
Object 当前实例

inherited toGeoJSON(){Object}

base/geometry/Geometry.js, line 133

导出为GeoJSON

Returns:
Type Description
Object GeoJSON对象

toJSON(){Object}

base/geometry/Point.js, line 318

导出为 JSON 对象

Returns:
Type Description
Object JSON对象

toOldIGSGeometry()

base/geometry/Point.js, line 340

返回igs1.0的几何对象

Returns:
Object igs1.0的几何对象

toString(){String}

base/geometry/Point.js, line 307

返回如下格式的字符串:"x,y",如果有z,则返回"x,y,z"

Returns:
Type Description
String 字符串
Example

返回字符串

// ES5引入方式
const { Point } = zondy.geometry

// ES6引入方式
import { Point } from "@mapgis/webclient-common"
const point1 = new Point({
  coordinates: [100.0, 0.0]
})
const str = point1.toString()

inherited toXML(){String}

base/geometry/Geometry.js, line 157

导出为OGC服务要求的xml字符串,子类实现

Returns:
Type Description
String 字符串

Point.fromJSON(json)

base/geometry/Point.js, line 122

通过传入的 JSON 构造并返回一个新的几何对象

Name Type Description
json Object 可选

JSON对象

Example

通过传入的 JSON 构造并返回一个新的几何对象

// ES5引入方式
const { Point } = zondy.geometry

// ES6引入方式
import { Point } from "@mapgis/webclient-common"
const json = {
  coordinates: [100.0, 0.0]
}
const point = Point.fromJSON(json)

Point.toCoordinates(point){Array.<Number>}

base/geometry/Point.js, line 95

获取坐标数组

Name Type Description
point Point | Array.<Number>

输入坐标信息

Returns:
Type Description
Array.<Number> 坐标数组
Example

获取坐标数组

// ES5引入方式
const { Point } = zondy.geometry

// ES6引入方式
import { Point } from "@mapgis/webclient-common"
const point = new Point({
  coordinates: [100.0, 0.0]
})
const coordinates = Point.toCoordinates(point)