使用方法新建一个文件measureArea.js将下面代码贴上去
- // DrawPolygon
- /*
- 绘制面(面积测量)
- */
-
- class measureArea {
- constructor(arg) {
- this.objId = Number(
- new Date().getTime() + "" + Number(Math.random() * 1000).toFixed(0)
- );
- this.viewer = arg.viewer;
- this.Cesium = arg.Cesium;
- this.callback = arg.callback;
- this._polygon = null; //活动面
- this._polygonLast = null; //最后一个面
- this._positions = []; //活动点
- this._entities_point = []; //脏数据
- this._entities_polygon = []; //脏数据
- this._polygonData = null; //用户构造面
- }
-
- //返回最后活动面
- get polygon() {
- return this._polygonLast;
- }
-
- //返回面数据用于加载面
- getData() {
- return this._polygonData;
- }
-
- //加载面
- loadPolygon(data) {
- var $this = this;
- return this.viewer.entities.add({
- polygon: {
- hierarchy: new $this.Cesium.PolygonHierarchy(data),
- clampToGround: true,
- show: true,
- fill: true,
- material: $this.Cesi