forked from SuperMap/iClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPolygon.js
More file actions
59 lines (52 loc) · 2.15 KB
/
Copy pathPolygon.js
File metadata and controls
59 lines (52 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/* Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
* This program are made available under the terms of the Apache License, Version 2.0
* which accompanies this distribution and is available at http://www.apache.org/licenses/LICENSE-2.0.html.*/
import {SuperMap} from '../../SuperMap';
import {Collection} from './Collection';
import './Point';
import './LineString';
import './LinearRing';
/**
* @class SuperMap.Geometry.Polygon
* @classdesc 多边形几何对象类。
* @category BaseTypes Geometry
* @extends {SuperMap.Geometry.Collection}
* @param {Array.<SuperMap.Geometry.LinearRing>} components - 用来生成多边形的线环数组。
* @example
* var points =[new SuperMap.Geometry.Point(0,4010338),
* new SuperMap.Geometry.Point(1063524,4010338),
* new SuperMap.Geometry.Point(1063524,3150322),
* new SuperMap.Geometry.Point(0,3150322)
* ],
* var linearRings = new SuperMap.Geometry.LinearRing(points),
* var region = new SuperMap.Geometry.Polygon([linearRings]);
*/
export class Polygon extends Collection {
constructor(components) {
super(components);
/**
* @member {Array.<string>} [SuperMap.Geometry.Polygon.prototype.componentTypes=["SuperMap.Geometry.LinearRing"]]
* @description components 存储的的几何对象所支持的几何类型数组。
* @readonly
*/
this.componentTypes = ["SuperMap.Geometry.LinearRing"];
this.CLASS_NAME = "SuperMap.Geometry.Polygon";
this.geometryType = "Polygon";
}
/**
* @function SuperMap.Geometry.Polygon.prototype.getArea
* @description 获得区域面积,从区域的外部口径减去计此区域内部口径算所得的面积。
* @returns {float} 几何对象的面积。
*/
getArea() {
var area = 0.0;
if (this.components && (this.components.length > 0)) {
area += Math.abs(this.components[0].getArea());
for (var i = 1, len = this.components.length; i < len; i++) {
area -= Math.abs(this.components[i].getArea());
}
}
return area;
}
}
SuperMap.Geometry.Polygon = Polygon;