1c92db51 by 刘远

jikai commit

1 parent 157f001c
{
"layers": [{
"name": "建设用地管制区",
"alias": "土地利用总体规划",
"category": "总体规划",
"id": "3G_GT_JSYDGZQ",
"keys": "intersects",
"database": [{
"table": "gt_jsydgzqgx",
"field": [{
"name": "gzqlxmc",
"alias": "用地性质"
}]
}],
"textarea": true,
"url": "http://10.6.144.134:6080/arcgis/rest/services/国土数据2000/JSYDGZQ/MapServer"
}, {
"name": "西安市总体规划2017修改版",
"alias": "西安市总体规划2017修改版",
"category": "总体规划",
"id": "3G_GH_XASZTGH",
"keys": "intersects",
"database": [{
"table": "csgh_ztgh",
"field": [{
"name": "layer",
"alias": "用地性质"
}, {
"name": "ydxzdm",
"alias": "用地性质代码"
}]
}],
"textarea": true,
"url": "http://10.6.144.134:6080/arcgis/rest/services/城市规划2000/西安市总体规划2017修改/MapServer"
}, {
"name": "西安市总体规划2008版",
"alias": "西安市总体规划2008版",
"category": "总体规划",
"id": "3G_GH_XASZTGH1",
"keys": "intersects",
"database": [{
"table": "csgh_zgydgh",
"field": [{
"name": "ydxz",
"alias": "用地性质"
}]
}],
"textarea": true,
"url": "http://10.6.144.134:6080/arcgis/rest/services/城市规划2000/西安市总体规划旧版/MapServer"
}, {
"name": "过渡期适用图层",
"alias": "过渡期适用图层",
"category": "过渡期适用图层",
"id": "3G_CSGH_GDQSY",
"keys": "intersects",
"database": [{
"table": "csgh_xxgh",
"field": [{
"name": "layer",
"alias": "用地性质"
}, {
"name": "ydxzdm",
"alias": "用地性质代码"
}, {
"name": "fqghmc",
"alias": "规划名称"
}, {
"name": "pfwh",
"alias": "批复文号"
}, {
"name": "type",
"alias": "用地类型"
}]
}, {
"table": "csgh_ghbg",
"field": [{
"name": "ydxzmc",
"alias": "用地性质"
}, {
"name": "ydxzdm",
"alias": "用地性质代码"
}, {
"name": "type",
"alias": "规划名称"
}, {
"name": "bgyj",
"alias": "变更依据"
}, {
"name": "bgqxz",
"alias": "变更前性质"
}, {
"name": "type",
"alias": "用地类型"
}]
}],
"textarea": true,
"url": "http://10.6.144.134:6080/arcgis/rest/services/城市规划2000/过渡期适用图层/MapServer"
}, {
"name": "详细规划",
"alias": "详细规划",
"category": "详细规划",
"id": "3G_JC_XXGH",
"keys": "intersects",
"database": [{
"table": "csgh_xxghkg",
"field": [{
"name": "layer",
"alias": "用地性质"
}, {
"name": "ydxzdm",
"alias": "用地性质代码"
}, {
"name": "name",
"alias": "规划名称"
}, {
"name": "fqghmc",
"alias": "批复文号"
}, {
"name": "type",
"alias": "用地类型"
}]
}],
"textarea": true,
"url": "http://10.6.144.134:6080/arcgis/rest/services/城市规划2000/详细规划/MapServer"
}, {
"name": "基本农田保护区",
"alias": "基本农田保护区",
"category": "专项规划",
"id": "3G_GH_JBNTBHQ",
"keys": "intersectsAndContains",
"database": [{
"table": "gt_jbntbhq",
"field": [{
"name": "tdytqlxmc",
"alias": "用地性质"
}]
}],
"textarea": false,
"url": "http://10.6.144.134:6080/arcgis/rest/services/国土数据2000/基本农田保护区/MapServer"
}, {
"name": "城市建设控制线",
"alias": "城市建设控制线",
"category": "专项规划",
"textarea": true,
"layers": [{
"name": "城市黄线",
"alias": "城市黄线",
"id": "3G_WX_CSHX",
"keys": "intersects",
"database": [{
"table": "kzx_huangxian",
"field": [{
"name": "layer",
"alias": "用地性质"
}]
}],
"url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/城市黄线/MapServer"
}, {
"name": "城市绿线",
"alias": "城市绿线",
"id": "3G_GH_CSLX",
"keys": "intersects",
"database": [{
"table": "kzx_lvxian",
"field": [{
"name": "layer",
"alias": "用地性质"
}]
}],
"url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/绿线/MapServer"
}, {
"name": "城市紫线",
"alias": "城市紫线",
"id": "3G_WX_CSZX",
"keys": "intersects",
"database": [{
"table": "kzx_zixian",
"field": [{
"name": "gid",
"alias": "用地性质"
}]
}],
"url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/紫线/MapServer"
}, {
"name": "道路红线",
"alias": "道路红线",
"id": "3G_GH_DLHX",
"keys": "intersects",
"database": [{
"table": "kzx_hongxian",
"field": [{
"name": "layer",
"alias": "用地性质"
}]
}],
"url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/红线/MapServer"
}, {
"name": "城市蓝线",
"alias": "城市蓝线",
"id": "3G_WX_CSLX",
"keys": "intersects",
"database": [{
"table": "kzx_lanxian",
"field": [{
"name": "layer",
"alias": "用地性质"
}]
}],
"url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/蓝线/MapServer"
}]
}, {
"name": "地铁控制线",
"alias": "地铁控制线",
"category": "专项规划",
"id": "3G_GH_DTKZX",
"keys": "intersects",
"database": [{
"table": "kzx_dtkzx",
"field": [{
"name": "objectid",
"alias": "用地性质"
}]
}],
"textarea": false,
"url": "http://10.6.144.134:6080/arcgis/rest/services/市政交通2000/地铁控制线/MapServer"
}, {
"name": "城市快速路体系",
"alias": "城市快速路体系",
"category": "专项规划",
"id": "GH_CSYS_CSKSLTX",
"keys": "intersects",
"database": [{
"table": "szjt_kslwtx",
"field": [{
"name": "layer",
"alias": "用地性质"
}]
}],
"textarea": true,
"url": "http://10.6.144.134:6080/arcgis/rest/services/市政交通2000/城市快速路体系规划/MapServer"
}, {
"name": "铁路南环线",
"alias": "铁路南环线",
"category": "专项规划",
"id": "3G_JC_TLNHX",
"keys": "intersects",
"database": [{
"table": "kzx_tlnhx",
"field": [{
"name": "layer",
"alias": "用地性质"
}]
}],
"textarea": true,
"url": "http://10.6.144.134:6080/arcgis/rest/services/五线规划2000/铁路南环线/MapServer"
}, {
"name": "公交场站规划(2018-2021年)",
"alias": "公交场站规划(2018-2021年)",
"category": "专项规划",
"keys": "intersectsAndContains",
"database": [{
"table": "szjt_gjczgh",
"field": [{
"name": "layer",
"alias": "用地性质"
}]
}],
"id": "GH_CSYS_GJCZGH",
"url": "http://10.6.144.134:6080/arcgis/rest/services/市政交通2000/公交场站规划图/MapServer"
}, {
"name": "停车场规划",
"alias": "停车场规划",
"category": "专项规划",
"id": "3G_JC_XXGH",
"keys": "intersects",
"database": [{
"table": "szjtzt_tccgh",
"field": [{
"name": "layer",
"alias": "用地性质"
}]
}],
"textarea": true,
"url": "http://10.7.120.44:6080/arcgis/rest/services/规划2000/停车场规划/MapServer"
}, {
"name": "国家级文物保护区",
"alias": "文物保护区",
"category": "专项规划",
"id": "SZ_GJWWBH",
"keys": "intersects",
"database": [{
"table": "wbgh_gjjwwbhq",
"field": [{
"name": "公布类别",
"alias": "用地性质"
}]
}, {
"table": "wbgh_gjjwwbhfw",
"field": [{
"name": "公布类别",
"alias": "用地性质"
}]
}, {
"table": "wbgh_gjjwwjskzq",
"field": [{
"name": "公布类",
"alias": "用地性质"
}]
}],
"textarea": true,
"url": "http://10.6.144.134:6080/arcgis/rest/services/市政交通2000/国家级文物保护区/MapServer"
}, {
"name": "生态控制红线",
"alias": "生态控制红线",
"category": "专项规划",
"id": "HB_STKZHX",
"keys": "intersectsAndContains",
"database": [{
"table": "stkzhx_ys",
"field": [{
"name": "类型",
"alias": "用地性质"
}]
}],
"textarea": false,
"url": "http://10.6.144.134:6080/arcgis/rest/services/生态控制红线2000/生态保护红线/MapServer"
}, {
"name": "地质灾害防治规划",
"alias": "地质灾害防治规划",
"category": "专项规划",
"id": "GT_DZZHFZGH",
"keys": "intersects",
"database": [{
"table": "gt_dlf",
"field": [{
"name": "dlfsx",
"alias": "用地性质"
}]
}, {
"table": "gt_dzzhyfq",
"field": [{
"name": "易发程",
"alias": "用地性质"
}]
}, {
"table": "gt_dzzhyhd",
"field": [{
"name": "灾害类",
"alias": "用地性质"
}]
}],
"textarea": true,
"url": "http://10.6.144.134:6080/arcgis/rest/services/国土数据2000/地质灾害/MapServer"
}, {
"name": "2018年年度变更调查",
"alias": "2018年年度变更调查",
"category": "现状",
"id": "tdgh_2018ndbgdc",
"keys": "intersects",
"database": [{
"table": "tdgh_2018ndbgdc",
"field": [{
"name": "dlmc",
"alias": "用地性质"
}]
}],
"textarea": true,
"url": "http://10.6.144.134:6080/arcgis/rest/services/国土数据2000/2018年年度变更调查/MapServer"
}, {
"name": "影像地图",
"alias": "影像地图",
"category": "现状",
"id": "yxdt",
"url": "http://10.6.144.134:6080/arcgis/rest/services/影像底图2000/2018GF影像/MapServer"
}]
}
import { loadModules } from "esri-loader";
import mapManage from './towMapObjects';
export default class GraphicAttributeManager {
static getInstance() {
mapManage.graphicManager || (mapManage.graphicManager = new this());
}
constructor() {
this.view = mapManage.mapView;
this.initGraphicManager();
}
initGraphicManager() {
};
}
\ No newline at end of file
export default {
measureTools(viewer) {
var entityCollection = [];
this.getCollection = function () {
return entityCollection;
};
/**
* 清除
*/
this.destroy = function () {
for (var i = 0; i < entityCollection.length; i++) {
viewer.entities.remove(entityCollection[i]);
}
entityCollection = [];
};
/**
* 测距
*/
this.measurePolyLine = function () {
var positions = [];
var labelEntity = null; // 标签实体
// 注册鼠标左击事件
viewer.screenSpaceEventHandler.setInputAction(function (clickEvent) {
var cartesian = viewer.scene.pickPosition(clickEvent.position); // 坐标
// 存储第一个点
if (positions.length == 0) {
positions.push(cartesian.clone());
addPoint(cartesian);
// 注册鼠标移动事件
viewer.screenSpaceEventHandler.setInputAction(function (moveEvent) {
var movePosition = viewer.scene.pickPosition(moveEvent.endPosition); // 鼠标移动的点
if (positions.length == 2) {
positions.pop();
positions.push(movePosition);
// 绘制label
if (labelEntity) {
viewer.entities.remove(labelEntity);
entityCollection.splice(entityCollection.indexOf(labelEntity), 1);
}
// 计算中点
var centerPoint = Cesium.Cartesian3.midpoint(positions[0], positions[1], new Cesium.Cartesian3());
// 计算距离
var lengthText = "距离:" + getLengthText(positions[0], positions[1]);
labelEntity = addLabel(centerPoint, lengthText);
entityCollection.push(labelEntity);
} else {
positions.push(movePosition);
// 绘制线
addLine(positions);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
} else {
// 存储第二个点
positions.pop();
positions.push(cartesian);
addPoint(cartesian);
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
};
/**
* 测面积
*/
this.measurePolygon = function () {
var positions = [];
var clickStatus = false;
var labelEntity = null;
viewer.screenSpaceEventHandler.setInputAction(function (clickEvent) {
clickStatus = true;
// var cartesian = viewer.scene.pickPosition(clickEvent.position);
var cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(clickEvent.position), viewer.scene);
if (positions.length == 0) {
positions.push(cartesian.clone()); //鼠标左击 添加第1个点
addPoint(cartesian);
viewer.screenSpaceEventHandler.setInputAction(function (moveEvent) {
// var movePosition = viewer.scene.pickPosition(moveEvent.endPosition);
var movePosition = viewer.scene.globe.pick(viewer.camera.getPickRay(moveEvent.endPosition), viewer.scene);
if (positions.length == 1) {
positions.push(movePosition);
addLine(positions);
} else {
if (clickStatus) {
positions.push(movePosition);
} else {
positions.pop();
positions.push(movePosition);
}
}
if (positions.length >= 3) {
// 绘制label
if (labelEntity) {
viewer.entities.remove(labelEntity);
entityCollection.splice(entityCollection.indexOf(labelEntity), 1);
}
var text = "面积:" + getArea(positions);
var centerPoint = getCenterOfGravityPoint(positions);
labelEntity = addLabel(centerPoint, text);
entityCollection.push(labelEntity);
}
clickStatus = false;
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
} else if (positions.length == 2) {
positions.pop();
positions.push(cartesian.clone()); // 鼠标左击 添加第2个点
addPoint(cartesian);
addPolyGon(positions);
// 右击结束
viewer.screenSpaceEventHandler.setInputAction(function (clickEvent) {
// var clickPosition = viewer.scene.pickPosition(clickEvent.position);
var clickPosition = viewer.scene.globe.pick(viewer.camera.getPickRay(clickEvent.position), viewer.scene);
// console.log(clickPosition);
positions.pop();
positions.push(clickPosition);
positions.push(positions[0]); // 闭合
addPoint(clickPosition);
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
} else if (positions.length >= 3) {
positions.pop();
positions.push(cartesian.clone()); // 鼠标左击 添加第3个点
addPoint(cartesian);
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
};
/**
* 测高
*/
this.measureHeight = function () {
var positions = [];
var labelEntity_1 = null; // 标签实体
var labelEntity_2 = null; // 标签实体
var labelEntity_3 = null; // 标签实体
// 注册鼠标左击事件
viewer.screenSpaceEventHandler.setInputAction(function (clickEvent) {
var cartesian = viewer.scene.pickPosition(clickEvent.position); // 坐标
// 存储第一个点
if (positions.length == 0) {
positions.push(cartesian.clone());
addPoint(cartesian);
// 注册鼠标移动事件
viewer.screenSpaceEventHandler.setInputAction(function (moveEvent) {
var movePosition = viewer.scene.pickPosition(moveEvent.endPosition); // 鼠标移动的点
if (positions.length >= 2) {
positions.pop();
positions.pop();
positions.pop();
var cartographic = Cesium.Cartographic.fromCartesian(movePosition);
var height = Cesium.Cartographic.fromCartesian(positions[0]).height;
var verticalPoint = Cesium.Cartesian3.fromDegrees(Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), height);
positions.push(verticalPoint);
positions.push(movePosition);
positions.push(positions[0]);
// 绘制label
if (labelEntity_1) {
viewer.entities.remove(labelEntity_1);
entityCollection.splice(entityCollection.indexOf(labelEntity_1), 1);
viewer.entities.remove(labelEntity_2);
entityCollection.splice(entityCollection.indexOf(labelEntity_2), 1);
viewer.entities.remove(labelEntity_3);
entityCollection.splice(entityCollection.indexOf(labelEntity_3), 1);
}
// 计算中点
var centerPoint_1 = Cesium.Cartesian3.midpoint(positions[0], positions[1], new Cesium.Cartesian3());
// 计算距离
var lengthText_1 = "水平距离:" + getLengthText(positions[0], positions[1]);
labelEntity_1 = addLabel(centerPoint_1, lengthText_1);
entityCollection.push(labelEntity_1);
// 计算中点
var centerPoint_2 = Cesium.Cartesian3.midpoint(positions[1], positions[2], new Cesium.Cartesian3());
// 计算距离
var lengthText_2 = "垂直距离:" + getLengthText(positions[1], positions[2]);
labelEntity_2 = addLabel(centerPoint_2, lengthText_2);
entityCollection.push(labelEntity_2);
// 计算中点
var centerPoint_3 = Cesium.Cartesian3.midpoint(positions[2], positions[3], new Cesium.Cartesian3());
// 计算距离
var lengthText_3 = "直线距离:" + getLengthText(positions[2], positions[3]);
labelEntity_3 = addLabel(centerPoint_3, lengthText_3);
entityCollection.push(labelEntity_3);
} else {
var verticalPoint = new Cesium.Cartesian3(movePosition.x, movePosition.y, positions[0].z);
positions.push(verticalPoint);
positions.push(movePosition);
positions.push(positions[0]);
// 绘制线
addLine(positions);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
} else {
// 存储第二个点
positions.pop();
positions.pop();
positions.pop();
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
var height = Cesium.Cartographic.fromCartesian(positions[0]).height;
var verticalPoint = Cesium.Cartesian3.fromDegrees(Cesium.Math.toDegrees(cartographic.longitude), Cesium.Math.toDegrees(cartographic.latitude), height);
positions.push(verticalPoint);
positions.push(cartesian);
positions.push(positions[0]);
addPoint(cartesian);
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
viewer.screenSpaceEventHandler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
};
/**
* 添加点
* @param position
*/
var addPoint = function (position) {
entityCollection.push(viewer.entities.add(new Cesium.Entity({
position: position,
point: {
// color: Cesium.Color.SKYBLUE,
// pixelSize: 8,
// outlineColor: Cesium.Color.YELLOW,
// outlineWidth: 2,
// disableDepthTestDistance: Number.POSITIVE_INFINITY
pixelSize: 5,
color: Cesium.Color.YELLOW,
outlineWidth: 2,
outlineColor: Cesium.Color.DARKRED,
disableDepthTestDistance: Number.POSITIVE_INFINITY
}
})));
};
/**
* 添加线
* @param positions
*/
var addLine = function (positions) {
entityCollection.push(viewer.entities.add(new Cesium.Entity({
polyline: {
positions: new Cesium.CallbackProperty(function () {
return positions
}, false),
perPositionHeight: true,
show: true,
material: Cesium.Color.YELLOW,
width: 3,
clampToGround: true
}
})));
};
/**
* 添加面
* @param positions
*/
var addPolyGon = function (positions) {
var dynamicPositions = new Cesium.CallbackProperty(function () {
return new Cesium.PolygonHierarchy(positions);
}, false);
entityCollection.push(viewer.entities.add(new Cesium.Entity({
polygon: {
hierarchy: dynamicPositions,
material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2),
perPositionHeight: true,
width: 3,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 3,
outline: true
// material: Cesium.Color.RED.withAlpha(0.6),
// classificationType: Cesium.ClassificationType.BOTH // 贴地表和贴模型,如果设置了,这不能使用挤出高度
}
})));
};
/**
* 添加标签
* @param position
* @param text
*/
var addLabel = function (centerPoint, text) {
return viewer.entities.add(new Cesium.Entity({
position: centerPoint,
label: {
text: text,
font: '12pt sans-serif',
style: Cesium.LabelStyle.FILL_AND_OUTLINE, //FILL FILL_AND_OUTLINE OUTLINE
fillColor: Cesium.Color.YELLOW,
showBackground: true,//指定标签后面背景的可见性
backgroundColor: new Cesium.Color(0.165, 0.165, 0.165, 0.8), // 背景颜色
backgroundPadding: new Cesium.Cartesian2(6, 6),//指定以像素为单位的水平和垂直背景填充padding
pixelOffset: new Cesium.Cartesian2(0, -25)
}
}));
};
/**
* 计算两点距离
* @param firstPoint
* @param secondPoint
*/
var getLengthText = function (firstPoint, secondPoint) {
// 计算距离
var length = Cesium.Cartesian3.distance(firstPoint, secondPoint);
if (length > 1000) {
length = (length / 1000).toFixed(2) + " 公里";
} else {
length = length.toFixed(2) + " 米";
}
return length;
};
//计算多边形面积
var getArea = function (points) {
var radiansPerDegree = Math.PI / 180.0;//角度转化为弧度(rad)
var degreesPerRadian = 180.0 / Math.PI;//弧度转化为角度
/*角度*/
function Angle(p1, p2, p3) {
var bearing21 = Bearing(p2, p1);
var bearing23 = Bearing(p2, p3);
var angle = bearing21 - bearing23;
if (angle < 0) {
angle += 360;
}
return angle;
}
/*方向*/
function Bearing(from, to) {
from = Cesium.Cartographic.fromCartesian(from);
to = Cesium.Cartographic.fromCartesian(to);
var lat1 = from.latitude;
var lon1 = from.longitude;
var lat2 = to.latitude;
var lon2 = to.longitude;
var angle = -Math.atan2(Math.sin(lon1 - lon2) * Math.cos(lat2), Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lon1 - lon2));
if (angle < 0) {
angle += Math.PI * 2.0;
}
angle = angle * degreesPerRadian;//角度
return angle;
}
function distance(point1, point2) {
var point1cartographic = Cesium.Cartographic.fromCartesian(point1);
var point2cartographic = Cesium.Cartographic.fromCartesian(point2);
/**根据经纬度计算出距离**/
var geodesic = new Cesium.EllipsoidGeodesic();
geodesic.setEndPoints(point1cartographic, point2cartographic);
var s = geodesic.surfaceDistance;
//console.log(Math.sqrt(Math.pow(distance, 2) + Math.pow(endheight, 2)));
//返回两点之间的距离
s = Math.sqrt(Math.pow(s, 2) + Math.pow(point2cartographic.height - point1cartographic.height, 2));
return s;
}
var res = 0;
//拆分三角曲面
for (var i = 0; i < points.length - 2; i++) {
var j = (i + 1) % points.length;
var k = (i + 2) % points.length;
var totalAngle = Angle(points[i], points[j], points[k]);
var dis_temp1 = distance(points[j], points[0]);
var dis_temp2 = distance(points[k], points[0]);
res += dis_temp1 * dis_temp2 * Math.sin(totalAngle) / 2;
// console.log(res);
}
if (res < 1000000) {
res = Math.abs(res).toFixed(4) + " 平方米";
} else {
res = Math.abs((res / 1000000.0).toFixed(4)) + " 平方公里";
}
return res;
};
/**
* 计算多边形的中心(简单的处理)
* @param mPoints
* @returns {*[]}
*/
var getCenterOfGravityPoint = function (mPoints) {
var centerPoint = mPoints[0];
for (var i = 1; i < mPoints.length; i++) {
centerPoint = Cesium.Cartesian3.midpoint(centerPoint, mPoints[i], new Cesium.Cartesian3());
}
return centerPoint;
}
}
}
\ No newline at end of file
export default {
createPoint(opt) {
return this.viewer.entities.add({
position: opt.position,
point: opt.point || {
pixelSize: 5,
color: Cesium.Color.YELLOW,
outlineWidth: 2,
outlineColor: Cesium.Color.DARKRED,
disableDepthTestDistance: Number.POSITIVE_INFINITY
},
show: false
});
},
createPolyline(positions) {
let style = this.style || {};
var polyline = this.viewer.entities.add({
polyline: {
positions: new Cesium.CallbackProperty(() => {
return positions || this.positions
}, false),
show: true,
material: style.material || Cesium.Color.YELLOW,
width: style.width || 3,
clampToGround: style.clampToGround == undefined ? false : true
}
});
polyline.objId = this.objId;
return polyline;
},
createPolygon() {
return this.viewer.entities.add({
polygon: {
hierarchy: new Cesium.CallbackProperty(() => {
return new Cesium.PolygonHierarchy(this.positions)
}, false),
material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2),
perPositionHeight: true,
width: 3,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 3,
outline: true
}
});
},
createRectangle() {
var that = this;
var rectangle = this.viewer.entities.add({
rectangle: {
coordinates: new Cesium.CallbackProperty(() => {
return Cesium.Rectangle.fromCartesianArray([this.leftup, this.rightdown])
}, false),
material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2),
perPositionHeight: true,
width: 3,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 3,
outline: true
}
});
rectangle.objId = this.objId;
return rectangle;
},
createCircle() {
var ellipse = this.viewer.entities.add({
position: this.center,
ellipse: {
semiMajorAxis: new Cesium.CallbackProperty(() => {
return this.radius
}, false),
semiMinorAxis: new Cesium.CallbackProperty(() => {
return this.radius
}, false),
material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2),
perPositionHeight: true,
width: 3,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 3,
outline: true
}
});
ellipse.objId = this.objId;
return ellipse;
}
}
\ No newline at end of file
import movePrompt from './MovePrompt';
export default class CreateBillboard {
constructor(viewer, style) {
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = viewer;
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.state = 0; //1为新增 2为编辑 0为清除
this.image = style.image || "content/images/map3d/mark1.png";
this.style = style;
this.billboardArg = {};
this.billboard = null;
this.openModify = false;
if (style) {
var haveImage = false;
for (var i in style) {
if (i == "image" && style[i]) {
haveImage = true;
}
if (style[i]) this.billboardArg[i] = style[i];
}
} else {
console.warn("未设置billboard的参数!");
return;
}
this.prompt = new movePrompt.movePrompt(viewer);
}
start(callBack) {
var that = this;
this.handler.setInputAction(function(evt) { //单机开始绘制
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer,[]);
that.billboard = that.createBillboard(cartesian);
that.state = 1;
that.handler.destroy();
if (that.prompt) {
that.prompt.destroy();
that.prompt = null;
}
if (callBack) callBack(that.billboard);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
this.handler.setInputAction(function(evt) { //单机开始绘制
that.prompt.updatePrompt(evt.endPosition, "单击新增");
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
}
createByPositions(lnglatArr, callBack) {
if (!lnglatArr) return;
var position = Cesium.Cartesian3.fromDegrees(lnglatArr[0], lnglatArr[1],lnglatArr[2]);
if (!position) return;
this.billboard = this.createBillboard(position);
callBack(this.billboard);
this.state = 1;
}
startModify() {
if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
var that = this;
this.modifyHandler.setInputAction(function(evt) {
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
if (!pick.id.objId)
that.forbidDrawWorld(true);
that.openModify = true;
that.forbidDrawWorld(true);
that.state = 2;
} else {
//if(that.modifyPrompt) that.modifyPrompt.destroy();
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
this.modifyHandler.setInputAction(function(evt) { //移动时绘制线
if (!that.billboard || !that.openModify) return;
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer,[]);
if (that.billboard) {
//that.modifyPrompt.updatePrompt(evt.endPosition, "鼠标拖动修改");
that.billboard.position.setValue(cartesian);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.modifyHandler.setInputAction(function(evt) { //移动时绘制线
if (!that.billboard || !that.openModify) return;
that.openModify = false;
that.forbidDrawWorld(false);
if (that.modifyHandler) {
that.modifyHandler.destroy();
that.modifyHandler = null;
}
}, Cesium.ScreenSpaceEventType.LEFT_UP);
}
endModify(callback) {
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
if (callback) callback(this.billboard);
}
this.state = 2;
}
createBillboard(cartesian) {
if (!cartesian) return;
var billboard = this.viewer.entities.add({
position: cartesian,
billboard: {
image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABMElEQVRIS+2VO0oEQRCGv38RBdFDGQumgijeQFTMjDUQr6CRsgeQDfQCmoqBZkYeQF0f+Cop6AYfa8/UOGtkw8Aw0/19XVVNlxjyUIlvZlPAGjAn6brJXn4UmNk4cJeeDtAFtiWdR0QlgUNfgDzH35+BU2AT6El6q5JFBB9ZN8ADsAXslNLXVJBlnkKPdB9YkdT/GtFvBZnnqepI+sZrQ+C1GQEWJO21GcEr8AQcAquSLgcVvEkElgp8AixLOiudpKjAi3gBLEk6rjqi/r+uwMFXCXxUB5zn1BHcJ/BuBBwR+B00L6n3L/iUATMbAx7TxxlJB62myGFmtgjMAtOS/PyHR7HhhGkDFvy9wMw2UpscDUTgd5J3u/XKy87MboGJADxP7UuarCMYbgQNdl5c8g7JKYAZpEkyjAAAAABJRU5ErkJggg==',
heightReference: this.style.heightReference || Cesium.HeightReference.NONE,
disableDepthTestDistance:Number.MAX_VALUE,
color: Cesium.Color.RED
}
})
billboard.objId = this.objId;
return billboard;
}
getPositions() {
return this.billboard.position;
}
setStyle(obj) {}
remove() {
if (this.billboard) {
this.state = 0;
this.viewer.entities.remove(this.billboard);
this.billboard = null;
}
}
setVisible(vis) {
this.billboard.show = vis;
}
forbidDrawWorld(isForbid) {
this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
}
destroy() {
this.openModify = false;
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
}
if (this.billboard) {
this.viewer.entities.remove(this.billboard);
this.billboard = null;
}
this.style = null;
if (this.prompt) {
that.prompt.destroy();
this.prompt = null;
}
}
getCatesian3FromPX(px, viewer, entitys) {
var picks = viewer.scene.drillPick(px);
this.viewer.scene.render();
var cartesian;
var isOn3dtiles = false;
for (var i = 0; i < picks.length; i++) {
var isContinue = false;
for (var step = 0; step < entitys.length; step++) {
if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
isContinue = true;
break;
}
}
if (isContinue) continue;
if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
isOn3dtiles = true;
}
}
if (isOn3dtiles) {
cartesian = viewer.scene.pickPosition(px);
} else {
var ray = viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
return cartesian;
}
}
\ No newline at end of file
import movePrompt from './MovePrompt';
import addCompany from './addCompany';
export default class CreateCircle {
constructor(viewer, style) {
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = viewer;
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.circle = null;
this.screenSpaceCameraController = [];
this.style = style;
this.floatPoint = null;
this.centerPoint = null;
this.center = null;
this.float = null;
this.radius = 0;
this.modifyPoint = null;
this.state = 0;
this.pointArr = [];
this.prompt = new movePrompt.movePrompt(viewer);
}
start(callBack) {
var that = this;
this.handler.setInputAction(function (evt) { //单机开始绘制
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.circle]);
if (!that.centerPoint) {
that.center = cartesian;
that.centerPoint = addCompany.createPoint.call(that, {position: cartesian});
that.centerPoint.typeAttr = "center";
that.floatPoint = addCompany.createPoint.call(that, {position: cartesian.clone()});
that.float = cartesian.clone();
that.floatPoint.typeAttr = "float";
that.circle = addCompany.createCircle.call(that);
} else {
return;
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
this.handler.setInputAction(function (evt) { //移动时绘制线
if (!that.centerPoint) {
that.prompt.updatePrompt(evt.endPosition, "单击开始绘制");
return;
}
that.prompt.updatePrompt(evt.endPosition, "右键结束");
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.circle]);
if (that.floatPoint) {
that.floatPoint.position.setValue(cartesian);
that.float = cartesian.clone();
}
that.radius = Cesium.Cartesian3.distance(cartesian, that.center);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.handler.setInputAction(function () { //单机开始绘制
if (!that.circle) {
return;
}
that.state = 1;
that.handler.destroy();
if (that.floatPoint) that.floatPoint.show = false;
if (that.centerPoint) that.centerPoint.show = false;
if (that.prompt) {
that.prompt.destroy();
that.prompt = null;
}
if (callBack) callBack(that.circle);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}
startModify(callback) {
if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
var that = this;
if (that.floatPoint) that.floatPoint.show = true;
if (that.centerPoint) that.centerPoint.show = true;
this.modifyHandler.setInputAction(function (evt) {
if (!that.circle) return;
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
if (!pick.id.objId)
that.modifyPoint = pick.id;
that.forbidDrawWorld(true);
} else {
if (that.floatPoint) that.floatPoint.show = false;
if (that.centerPoint) that.centerPoint.show = false;
if (that.modifyHandler) {
that.modifyHandler.destroy();
that.modifyHandler = null;
if (callback) callback(that.circle);
}
that.state = 2;
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
this.modifyHandler.setInputAction(function (evt) {
if (!that.modifyPoint) return;
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.circle]);
if (!cartesian) {
return;
}
if (that.modifyPoint.typeAttr == "center") {
that.center = cartesian
that.centerPoint.position.setValue(that.center);
that.circle.position.setValue(that.center);
} else {
that.float = cartesian
that.floatPoint.position.setValue(that.float);
}
that.radius = Cesium.Cartesian3.distance(that.float, that.center);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.modifyHandler.setInputAction(function (evt) {
if (!that.modifyPoint) return;
that.modifyPoint = null;
that.forbidDrawWorld(false);
}, Cesium.ScreenSpaceEventType.LEFT_UP);
}
endModify(callback) {
if (this.floatPoint) this.floatPoint.show = false;
if (this.centerPoint) this.centerPoint.show = false;
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
if (callback) callback(this.circle);
}
this.state = 2;
}
getCenter() {
return this.center;
}
getAttr() {
return obj;
}
setStyle(obj) {}
remove() {
if (this.circle) {
this.state = 0;
this.viewer.entities.remove(this.circle);
this.circle = null;
}
}
setVisible(vis) {
this.circle.show = vis;
}
forbidDrawWorld(isForbid) {
this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
}
destroy() {
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
}
if (this.circle) {
this.viewer.entities.remove(this.circle);
this.circle = null;
}
if (this.floatPoint) {
this.viewer.entities.remove(this.floatPoint);
this.floatPoint = null;
}
if (this.centerPoint) {
this.viewer.entities.remove(this.centerPoint);
this.centerPoint = null;
}
this.style = null;
this.modifyPoint = null;
if (this.prompt) this.prompt.destroy();
}
getCatesian3FromPX(px, viewer, entitys) {
var picks = viewer.scene.drillPick(px);
this.viewer.scene.render();
var cartesian;
var isOn3dtiles = false;
for (var i = 0; i < picks.length; i++) {
var isContinue = false;
for (var step = 0; step < entitys.length; step++) {
if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
isContinue = true;
break;
}
}
if (isContinue) continue;
if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
isOn3dtiles = true;
}
}
if (isOn3dtiles) {
cartesian = viewer.scene.pickPosition(px);
} else {
var ray = viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
return cartesian;
}
}
\ No newline at end of file
import movePrompt from './MovePrompt';
import addCompany from './addCompany';
export default class CreatePolygon {
constructor(viewer, style) {
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = viewer;
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.polygon = null;
this.polyline = null;
this.positions = [];
this.style = style;
this.state = 0; //1为新增 2为编辑 0为清除
this.gonPointArr = [];
this.modifyPoint = null;
this.prompt = new movePrompt.movePrompt(viewer);
}
start(callBack) {
var that = this;
this.handler.setInputAction(function(evt) { //单机开始绘制
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polygon]);
if (that.positions.length == 0) {
that.positions.push(cartesian.clone());
}
that.positions.push(cartesian);
var point = addCompany.createPoint.call(that, {position: cartesian});
point.wz = that.gonPointArr.length;
that.gonPointArr.push(point);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
this.handler.setInputAction(function(evt) { //移动时绘制面
if (that.positions.length < 1) {
that.prompt.updatePrompt(evt.endPosition, "单击开始绘制");
return;
}
that.prompt.updatePrompt(evt.endPosition, "单击新增,右键结束");
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.polygon]);
if (that.positions.length == 2) {
if (!Cesium.defined(that.polyline)) that.polyline = addCompany.createPolyline.call(that);
} else {
if (!Cesium.defined(that.polygon)) {
that.polygon = addCompany.createPolygon.call(that);
that.polygon.isFilter = true;
that.polygon.objId = that.objId;
if (that.polyline) that.viewer.entities.remove(that.polyline);
}
}
that.positions.pop();
that.positions.push(cartesian);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.handler.setInputAction(function(evt) {
if (!that.polygon) return;
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polygon]);
that.state = 1;
that.handler.destroy();
if (that.floatPoint) {
if (that.floatPoint) that.floatPoint.show = false;
that.floatPoint = null;
}
that.positions.pop();
that.positions.push(cartesian);
var point = addCompany.createPoint.call(that, {position: cartesian});
point.wz = that.gonPointArr.length;
that.gonPointArr.push(point);
if (that.prompt) {
that.prompt.destroy();
that.prompt = null;
}
callBack(that.polygon);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}
createByPositions(lnglatArr, callBack) {
if (!lnglatArr) return;
var positions = that.getCatesian3FromPX.lnglatArrToCartesianArr(lnglatArr);
if (!positions) return;
this.polygon = addCompany.createPolygon.call(this);
this.positions = positions;
callBack(this.polygon);
for (var i = 0; i < positions.length; i++) {
var point = addCompany.createPoint.call(that, {position: positions[i]});
point.isFilter = true;
point.wz = this.gonPointArr.length;
this.gonPointArr.push(point);
}
this.state = 1;
this.polygon.objId = this.objId;
}
startModify() {
if (this.state != 1 && this.state != 2) return; //表示还没绘制完成
if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
var that = this;
for (var i = 0; i < that.gonPointArr.length; i++) {
var point = that.gonPointArr[i];
if (point) point.show = true;
}
this.modifyHandler.setInputAction(function(evt) {
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
if (!pick.id.objId)
that.modifyPoint = pick.id;
that.forbidDrawWorld(true);
} else {
for (var i = 0; i < that.gonPointArr.length; i++) {
var point = that.gonPointArr[i];
if (point) point.show = false;
}
if (that.modifyHandler) {
that.modifyHandler.destroy();
that.modifyHandler = null;
}
that.state = 2;
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
this.modifyHandler.setInputAction(function(evt) { //移动时绘制面
if (that.positions.length < 1 || !that.modifyPoint) return;
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.polygon, that.modifyPoint]);
if (cartesian) {
that.modifyPoint.position.setValue(cartesian);
that.positions[that.modifyPoint.wz] = cartesian;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.modifyHandler.setInputAction(function(evt) {
that.forbidDrawWorld(false);
if (!that.modifyPoint) return;
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polygon, that.modifyPoint]);
that.modifyPoint.position.setValue(cartesian);
that.positions[that.modifyPoint.wz] = cartesian;
that.modifyPoint = null;
that.forbidDrawWorld(false);
}, Cesium.ScreenSpaceEventType.LEFT_UP);
}
endModify(callback) {
for (var i = 0; i < this.gonPointArr.length; i++) {
var point = this.gonPointArr[i];
if (point) point.show = false;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
}
this.state = 2;
if(callback) callback(this.polygon);
}
getPositions() {
return this.positions;
}
getLnglats() {
return Cesium.caratesianArrToLnglatArr(this.positions);
}
getAttr() {
if (!this.polygon) return;
var obj = {};
var polygon = this.polygon.polygon;
obj.fill = polygon.fill._value;
obj.outline = polygon.outline._value;
obj.outlineWidth = polygon.outlineWidth._value;
obj.outlineColor = polygon.outlineColor._value;
obj.clampToGround = line.clampToGround._value;
obj.color = line.material.color._value;
return obj;
}
setStyle() {}
remove() {
if (this.polygon) {
this.state = 0;
this.viewer.entities.remove(this.polygon);
this.polygon = null;
}
}
setVisible(vis) {
this.polygon.show = vis;
}
forbidDrawWorld(isForbid) {
this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
}
destroy() {
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
}
if (this.polygon) {
this.viewer.entities.remove(this.polygon);
this.polygon = null;
}
if (this.polyline) {
this.viewer.entities.remove(this.polyline);
this.polyline = null;
}
this.positions = [];
this.style = null;
if (this.modifyPoint) {
this.viewer.entities.remove(this.modifyPoint);
this.modifyPoint = null;
}
for (var i = 0; i < this.gonPointArr.length; i++) {
var point = this.gonPointArr[i];
this.viewer.entities.remove(point);
}
this.gonPointArr = [];
this.state = 0;
if (this.prompt) this.prompt.destroy();
if (this.polyline) {
this.polyline = null;
this.viewer.entities.remove(this.polyline);
}
}
getCatesian3FromPX(px, viewer, entitys) {
var picks = viewer.scene.drillPick(px);
this.viewer.scene.render();
var cartesian;
var isOn3dtiles = false;
for (var i = 0; i < picks.length; i++) {
var isContinue = false;
for (var step = 0; step < entitys.length; step++) {
if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
isContinue = true;
break;
}
}
if (isContinue) continue;
if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
isOn3dtiles = true;
}
}
if (isOn3dtiles) {
cartesian = viewer.scene.pickPosition(px);
} else {
var ray = viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
return cartesian;
}
}
\ No newline at end of file
import movePrompt from './MovePrompt';
import addCompany from './addCompany';
export default class CreatePolyline {
constructor(viewer, style) {
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = viewer;
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.polyline = null;
this.positions = [];
this.style = style;
this.floatPoint = null;
this.linePointArr = [];
this.modifyPoint = null;
this.state = 0;
//初始化鼠标提示框
this.prompt = new movePrompt.movePrompt(viewer);
// this.prompt.updatePrompt({x: 495, y: 407}, "单击开始绘制");
}
start(callBack) {
var that = this;
this.handler.setInputAction(function (evt) { //单机开始绘制
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polyline]);
if (that.positions.length == 0) {
that.positions.push(cartesian.clone());
that.floatPoint = addCompany.createPoint.call(that, {position: cartesian.clone()});
}
that.positions.push(cartesian);
var point = addCompany.createPoint.call(that, {position: cartesian});
point.wz = that.linePointArr.length;
that.linePointArr.push(point);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
this.handler.setInputAction(function (evt) { //移动时绘制线
if (that.positions.length < 1) {
that.prompt.updatePrompt(evt.endPosition, "单击开始绘制");
return;
}
that.prompt.updatePrompt(evt.endPosition, "单击新增,右键结束");
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.polyline]);
if (that.floatPoint) that.floatPoint.position.setValue(cartesian);
if (that.positions.length == 2) {
if (!Cesium.defined(that.polyline)) {
that.polyline = addCompany.createPolyline.call(that);
}
}
if (that.polyline) {
that.positions.pop();
that.positions.push(cartesian);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.handler.setInputAction(function (evt) { //单机开始绘制
if (!that.polyline) {
return;
}
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polyline]);
that.state = 1;
that.handler.destroy();
if (that.floatPoint) {
if (that.floatPoint) that.floatPoint.show = false;
that.floatPoint = null;
}
that.positions.pop();
that.positions.push(cartesian);
var point = addCompany.createPoint.call(that, {position: cartesian});
point.wz = that.linePointArr.length;
that.linePointArr.push(point);
if(that.prompt){
that.prompt.destroy();
that.prompt = null;
}
if (callBack) callBack(that.polyline);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}
startModify(callback) {
if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
var that = this;
for (var i = 0; i < that.linePointArr.length; i++) {
var point = that.linePointArr[i];
if (point) point.show = true;
}
this.modifyHandler.setInputAction(function (evt) {
if(!that.polyline) return ;
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
if (!pick.id.objId)
that.modifyPoint = pick.id;
that.forbidDrawWorld(true);
} else {
for (var i = 0; i < that.linePointArr.length; i++) {
var point = that.linePointArr[i];
if (point) point.show = false;
}
if (that.modifyHandler) {
that.modifyHandler.destroy();
that.modifyHandler = null;
if(callback) callback(that.polyline);
}
that.state = 2;
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
this.modifyHandler.setInputAction(function (evt) {
if (that.positions.length < 1 || !that.modifyPoint) return;
//that.modifyPrompt.updatePrompt(evt.endPosition, "鼠标拖动修改");
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.polyline, that.modifyPoint]);
if (cartesian) {
that.modifyPoint.position.setValue(cartesian);
that.positions[that.modifyPoint.wz] = cartesian;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.modifyHandler.setInputAction(function (evt) {
if (!that.modifyPoint) return;
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, [that.polyline, that.modifyPoint]);
that.modifyPoint.position.setValue(cartesian);
that.positions[that.modifyPoint.wz] = cartesian;
that.modifyPoint = null;
that.forbidDrawWorld(false);
}, Cesium.ScreenSpaceEventType.LEFT_UP);
}
endModify(callback) {
for (var i = 0; i < this.linePointArr.length; i++) {
var point = this.linePointArr[i];
if (point) point.show = false;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
if(callback) callback(this.polyline);
}
this.state = 2;
}
getPositions() {
return this.positions;
}
getAttr() {
if (!this.polyline) return;
var obj = {};
var line = this.polyline.polyline;
obj.width = line.width._value;
obj.clampToGround = line.clampToGround._value;
obj.color = line.material.color._value;
obj.lineType = "solid";
return obj;
}
setStyle(obj) {}
remove() {
if (this.polyline) {
this.state = 0;
this.viewer.entities.remove(this.polyline);
this.polyline = null;
}
}
setVisible(vis) {
this.polyline.show = vis;
}
forbidDrawWorld(isForbid) {
this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
}
destroy() {
this.linePointArr = [];
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
}
if (this.polyline) {
this.viewer.entities.remove(this.polyline);
this.polyline = null;
}
if (this.floatPoint) {
this.viewer.entities.remove(this.floatPoint);
this.floatPoint = null;
}
this.positions = [];
this.style = null;
for (var i = 0; i < this.linePointArr.length; i++) {
var point = this.linePointArr[i];
this.viewer.entities.remove(point);
}
this.linePointArr = [];
this.modifyPoint = null;
if (this.prompt) this.prompt.destroy();
//if (this.modifyPrompt) this.modifyPrompt.destroy();
}
getCatesian3FromPX(px, viewer, entitys) {
var picks = viewer.scene.drillPick(px);
this.viewer.scene.render();
var cartesian;
var isOn3dtiles = false;
for (var i = 0; i < picks.length; i++) {
var isContinue = false;
for (var step = 0; step < entitys.length; step++) {
if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
isContinue = true;
break;
}
}
if (isContinue) continue;
if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
isOn3dtiles = true;
}
}
if (isOn3dtiles) {
cartesian = viewer.scene.pickPosition(px);
} else {
var ray = viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
return cartesian;
}
}
\ No newline at end of file
import movePrompt from './MovePrompt';
import addCompany from './addCompany';
export default class CreateRectangle {
constructor(viewer, style) {
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = viewer;
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.rectangle = null;
this.screenSpaceCameraController = [];
this.style = style;
this.rightdownPoint = null;
this.leftupPoint = null;
this.leftup = null;
this.rightdown = null;
this.radius = 0;
this.modifyPoint = null;
this.state = 0;
this.pointArr = [];
this.prompt = new movePrompt.movePrompt(viewer);
}
start(callBack) {
var that = this;
this.handler.setInputAction(function (evt) { //单机开始绘制
var cartesian = that.getCatesian3FromPX(evt.position, that.viewer, []);
if (!that.leftupPoint) {
that.leftup = cartesian;
that.leftupPoint = addCompany.createPoint.call(that, {position: cartesian});
that.leftupPoint.typeAttr = "leftup";
that.rightdownPoint = addCompany.createPoint.call(that, {position: cartesian.clone()});
that.rightdown = cartesian.clone();
that.rightdownPoint.typeAttr = "rightdown";
that.rectangle = addCompany.createRectangle.call(that);
} else {
return;
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
this.handler.setInputAction(function (evt) { //移动时绘制线
if (!that.leftupPoint) {
that.prompt.updatePrompt(evt.endPosition, "单击开始绘制");
return;
}
that.prompt.updatePrompt(evt.endPosition, "右键结束");
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, []);
if (that.rightdownPoint) {
that.rightdownPoint.position.setValue(cartesian);
that.rightdown = cartesian.clone();
}
that.radius = Cesium.Cartesian3.distance(cartesian, that.leftup);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.handler.setInputAction(function () { //单机开始绘制
if (!that.rectangle) {
return;
}
that.state = 1;
that.handler.destroy();
if (that.rightdownPoint) that.rightdownPoint.show = false;
if (that.leftupPoint) that.leftupPoint.show = false;
if (that.prompt) {
that.prompt.destroy();
that.prompt = null;
}
if (callBack) callBack(that.rectangle);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}
startModify(callback) {
if (this.state != 2 && this.state != 1) return; //表示还没绘制完成
if (!this.modifyHandler) this.modifyHandler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
var that = this;
if (that.rightdownPoint) that.rightdownPoint.show = true;
if (that.leftupPoint) that.leftupPoint.show = true;
this.modifyHandler.setInputAction(function (evt) {
if (!that.rectangle) return;
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
if (!pick.id.objId)
that.modifyPoint = pick.id;
that.forbidDrawWorld(true);
} else {
if (that.rightdownPoint) that.rightdownPoint.show = false;
if (that.leftupPoint) that.leftupPoint.show = false;
if (that.modifyHandler) {
that.modifyHandler.destroy();
that.modifyHandler = null;
if (callback) callback(that.rectangle);
}
that.state = 2;
}
}, Cesium.ScreenSpaceEventType.LEFT_DOWN);
this.modifyHandler.setInputAction(function (evt) {
if (!that.modifyPoint) return;
var cartesian = that.getCatesian3FromPX(evt.endPosition, that.viewer, [that.rectangle, that.modifyPoint]);
if (!cartesian) {
return;
}
if (that.modifyPoint.typeAttr == "leftup") {
that.leftup = cartesian
that.leftupPoint.position.setValue(that.leftup);
that.rectangle.position.setValue(that.leftup);
} else {
that.rightdown = cartesian
that.rightdownPoint.position.setValue(that.rightdown);
}
that.radius = Cesium.Cartesian3.distance(that.rightdown, that.leftup);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.modifyHandler.setInputAction(function (evt) {
if (!that.modifyPoint) return;
that.modifyPoint = null;
that.forbidDrawWorld(false);
}, Cesium.ScreenSpaceEventType.LEFT_UP);
}
endModify(callback) {
if (this.rightdownPoint) this.rightdownPoint.show = false;
if (this.leftupPoint) this.leftupPoint.show = false;
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
if (callback) callback(this.rectangle);
}
this.state = 2;
}
getPositions() {
return [this.leftup, this.rightdown]
}
getAttr() {
return obj;
}
setStyle(obj) {}
remove() {
if (this.rectangle) {
this.state = 0;
this.viewer.entities.remove(this.rectangle);
this.rectangle = null;
}
}
setVisible(vis) {
this.rectangle.show = vis;
}
forbidDrawWorld(isForbid) {
this.viewer.scene.screenSpaceCameraController.enableRotate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTilt = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableTranslate = !isForbid;
this.viewer.scene.screenSpaceCameraController.enableInputs = !isForbid;
}
destroy() {
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this.modifyHandler) {
this.modifyHandler.destroy();
this.modifyHandler = null;
}
if (this.rectangle) {
this.viewer.entities.remove(this.rectangle);
this.rectangle = null;
}
if (this.rightdownPoint) {
this.viewer.entities.remove(this.rightdownPoint);
this.rightdownPoint = null;
}
if (this.leftupPoint) {
this.viewer.entities.remove(this.leftupPoint);
this.leftupPoint = null;
}
this.style = null;
this.modifyPoint = null;
if (this.prompt) this.prompt.destroy();
}
getCatesian3FromPX(px, viewer, entitys) {
var picks = viewer.scene.drillPick(px);
this.viewer.scene.render();
var cartesian;
var isOn3dtiles = false;
for (var i = 0; i < picks.length; i++) {
var isContinue = false;
for (var step = 0; step < entitys.length; step++) {
if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
isContinue = true;
break;
}
}
if (isContinue) continue;
if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
isOn3dtiles = true;
}
}
if (isOn3dtiles) {
cartesian = viewer.scene.pickPosition(px);
} else {
var ray = viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
return cartesian;
}
}
\ No newline at end of file
import createBillboard from './createBillboard';
import createPolyline from './createPolyline';
import createPolygon from './createPolygon';
import createCircle from './createCircle';
import createRectangle from './createRectangle';
export default {
drawTool: class DrawTool {
constructor(obj) {
if (!obj.viewer || !obj) {
console.warn("缺少必要参数!--viewer");
return;
}
this.viewer = obj.viewer;
this.hasEdit = obj.hasEdit;
this.toolArr = [];
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.show = obj.drawEndShow;
// this.lastSelectEntity = null;
}
startDraw(opt) {
var that = this;
if (opt.type == "polyline") {
var polyline = new createPolyline(this.viewer, opt.style);
polyline.start(function (evt) {
if (that.hasEdit) {
that.unbindEdit();
polyline.startModify(opt.modifySuccess);
that.lastSelectEntity = polyline;
}
if (opt.success) opt.success(evt);
if (that.show == false) polyline.setVisible(false);
});
this.toolArr.push(polyline);
}
if (opt.type == "polygon") {
var polygon = new createPolygon(this.viewer, opt.style);
polygon.start(function () {
if (that.hasEdit) {
that.unbindEdit();
polygon.startModify();
that.lastSelectEntity = polygon;
}
if (opt.success) opt.success(polygon);
if (that.show == false) polygon.setVisible(false);
});
this.toolArr.push(polygon);
}
if (opt.type == "billboard") {
var billboard = new createBillboard(this.viewer, opt.style);
billboard.start(function () {
if (that.hasEdit) {
that.unbindEdit();
billboard.startModify();
that.lastSelectEntity = billboard;
}
if (opt.success) opt.success(billboard);
if (that.show == false) billboard.setVisible(false);
});
this.toolArr.push(billboard);
}
if (opt.type == "circle") {
var circle = new createCircle(this.viewer, opt.style);
circle.start(function () {
if (that.hasEdit) {
that.unbindEdit();
circle.startModify();
that.lastSelectEntity = circle;
}
if (opt.success) opt.success(circle);
if (that.show == false) circle.setVisible(false);
});
this.toolArr.push(circle);
}
if (opt.type == "rectangle") {
var rectangle = new createRectangle(this.viewer, opt.style);
rectangle.start(function () {
if (that.hasEdit) {
that.unbindEdit();
rectangle.startModify();
that.lastSelectEntity = rectangle;
}
if (opt.success) opt.success(rectangle);
if (that.show == false) rectangle.setVisible(false);
});
this.toolArr.push(rectangle);
}
//重写材质
if (opt.type == "flowPolyline") {
var polyline = new CreatePolyline(this.viewer, opt.style);
polyline.start(function () {
if (that.hasEdit) {
that.unbindEdit();
polyline.startModify();
}
if (opt.success) opt.success(polyline);
});
this.toolArr.push(polyline);
}
}
createByPositions(opt) {
if (this.hasEdit) {
this.bindEdit();
}
if (!opt) opt = {};
if (opt.type == "polyline") {
var polyline = new CreatePolyline(this.viewer, opt.style);
polyline.createByPositions(opt.positions, opt.success);
this.toolArr.push(polyline);
}
if (opt.type == "polygon") {
var polygon = new CreatePolygon(this.viewer, opt.style);
polygon.createByPositions(opt.positions, opt.success);
this.toolArr.push(polygon);
}
if (opt.type == "billboard") {
var billboard = new CreateBillboard(this.viewer, opt.style);
billboard.createByPositions(opt.positions, function(){
if(opt.success) opt.success(billboard)
import { loadModules } from "esri-loader";
import mapManage from './towMapObjects';
export default class DrawTool {
static getInstance() {
mapManage.drawTool || (mapManage.drawTool = new this());
}
constructor() {
this.view = mapManage.mapView;
this.map = mapManage.mapView.map;
this.active = !1;
this.polygon = null;
this.guids = [];
loadModules(["esri/symbols/PictureMarkerSymbol", "esri/layers/GraphicsLayer", "esri/views/draw/Draw"]).then(([w, z, d]) => {
this.options1 || (this.options1 = {}, this.options1.pm = new w({
url: "", width: "", height: "", xoffset: 0, yoffset: 0
}));
this.map.add(this.graphicsLayer = new z({ id: "drawtool" }));
this.draw = new Draw({ view: this.view });
});
}
activate(c, b) {
this.active = !0;
this.drawType = c.toUpperCase();
this.callback = b;
this.guids = [];
this.downCount = 0;
this.map.reorder(this.graphicsLayer, this.map.allLayers.length - 1);
switch (this.drawType) {
case "POINT1":
loadModules(["esri/Graphic"]).then(([h, f]) => {
this.downCount = 0;
this.view.container.addEventListener('mousedown', b => {
var a = new h(b.offsetX, b.offsetY), a = this.view.toMap(a);
console.log(a);
// this.graphic = new f(a, this.options1.pm, null);
// this.graphicsLayer.add(this.graphic);
// console.log('OKOKOK');
// b.stopPropagation()
});
this.toolArr.push(billboard);
}
}
destroy() {
for (var i = 0; i < this.toolArr.length; i++) {
var obj = this.toolArr[i];
obj.destroy();
}
}
bindEdit() {
var that = this;
this.handler.setInputAction(function (evt) { //单机开始绘制
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
for (var i = 0; i < that.toolArr.length; i++) {
if (pick.id.objId == that.toolArr[i].objId && (that.toolArr[i].state == 1||that.toolArr[i].state == 2)) {
if (that.lastSelectEntity) {
that.lastSelectEntity.endModify();
}
that.toolArr[i].startModify();
that.lastSelectEntity = that.toolArr[i];
break;
}
}
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}
unbindEdit() {
for (var i = 0; i < this.toolArr.length; i++) {
this.toolArr[i].endModify();
}
}
getCatesian3FromPX(px, viewer, entitys) {
var picks = viewer.scene.drillPick(px);
this.viewer.scene.render();
var cartesian;
var isOn3dtiles = false;
for (var i = 0; i < picks.length; i++) {
var isContinue = false;
for (var step = 0; step < entitys.length; step++) {
if (entitys[step] && picks[i].id && entitys[step].objId == picks[i].id.objId) {
isContinue = true;
break;
}
}
if (isContinue) continue;
if ((picks[i] && picks[i].primitive) || picks[i] instanceof Cesium.Cesium3DTileFeature) { //模型上拾取
isOn3dtiles = true;
}
}
if (isOn3dtiles) {
cartesian = viewer.scene.pickPosition(px);
} else {
var ray = viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = viewer.scene.globe.pick(ray, viewer.scene);
}
return cartesian;
});
break;
}
}
deactivate() {
this.active = !1;
this.drawType = "";
this.downCount = 0;
}
}
\ No newline at end of file
......
export default {
map: undefined
viewer: undefined
}
\ No newline at end of file
......
export default {
pageIndex: '',
pageSize: '',
id: 't0101_4028d839708bbb6d0170946760781016',
data: undefined
}
\ No newline at end of file
import objectManage from './maputils';
export default class shadow {
constructor() {
constructor(opt) {
this.points = [];
this.shadowQuery = new Cesium.ShadowQueryPoints(objectManage.viewer.scene);
this.shadowQuery.build();
// this.options = opt;
this.setCurrentTime();
this.init();
}
setCurrentTime() {
let d = new Date();
d.setHours(20)
objectManage.viewer.clock.currentTime = Cesium.JulianDate.fromDate(d);
objectManage.viewer.clock.currentTime = Cesium.JulianDate.fromDate(new Date());
objectManage.viewer.clock.multiplier = 1;
objectManage.viewer.clock.shouldAnimate = true;
}
......@@ -45,24 +44,24 @@ export default class shadow {
}
//设置分析对象的开始结束时间
// var dateValue = $("#selDate").val();
var startTime = new Date();
startTime.setHours(8);
this.shadowQuery.startTime = Cesium.JulianDate.fromDate(startTime);
// var startTime = new Date();
// startTime.setHours(18);
this.shadowQuery.startTime = Cesium.JulianDate.fromDate(this.anslysisTime);
var endTime = new Date();
endTime.setHours(22);
endTime.setHours(0);
this.shadowQuery.endTime = Cesium.JulianDate.fromDate(endTime);
this.setCurrentTime();
// this.setCurrentTime();
this.shadowQuery.spacing = 10;
this.shadowQuery.timeInterval = 60;
//设置分析区域、底部高程和拉伸高度
var bh = 20, eh = 20;
// var bh = 20, eh = 20;
this.shadowQuery.qureyRegion({
position : this.points,
bottom : bh,
extend : eh
bottom: this.bottomHeight,
extend: this.extrudeHeight
});
});
}
......
export default {
attributes: {
drawPolt: class DrawPolt {
constructor(arg) {
this.viewer = arg.viewer;
this.type = {};
this._billboardArr = [];
this._lineArr = [];
this._gonArr = [];
this.handler = null;
}
get billboardArr() {
return this._billboardArr;
}
get polylineArr() {
return this._lineArr;
}
get polygonArr() {
return this._gonArr;
}
create(e) {
this.type[e].startCreate();
}
clearAll() {
for (var i = 0; i < this._lineArr.length; i++) {
var line = this._lineArr[i];
line.destroy();
}
this._lineArr = [];
for (var j = 0; j < this._gonArr.length; j++) {
var gon = this._gonArr[j];
gon.destroy();
}
this._gonArr = [];
for (var k = 0; k < this._billboardArr.length; k++) {
var billboard = this._billboardArr[k];
billboard.destroy();
}
this._billboardArr = [];
}
clearOne() {
if (!this.handler) {
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
}
var that = this;
this.handler.setInputAction(function (evt) {
var pick = that.viewer.scene.pick(evt.position);
if (Cesium.defined(pick) && pick.id) {
that.viewer.entities.remove(pick.id);
that.handler.destroy();
that.handler = null;
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}
},
polygon: class DrawPolygon {
constructor(arg) {
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = arg.viewer;
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this._polygon = null;
this._polyline = null;
this._positions = [];
}
get polygon() {
return this._polygon;
}
get positions() {
return this._positions;
}
startCreate(func) {
var $this = this;
this.handler.setInputAction(function (evt) { //单机开始绘制
var cartesian = $this.getCatesian3FromPX(evt.position);
if ($this._positions.length == 0) {
$this._positions.push(cartesian.clone());
}
$this._positions.push(cartesian);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
this.handler.setInputAction(function (evt) { //移动时绘制面
if ($this._positions.length < 1) return;
var cartesian = $this.getCatesian3FromPX(evt.endPosition);
if ($this._positions.length == 2) {
if (!Cesium.defined($this._polyline)) {
$this._polyline = $this.createPolyline();
}
}
if ($this._positions.length == 3) {
if ($this._polyline){
$this.viewer.entities.remove($this._polyline);
$this._polyline = null;
}
if (!Cesium.defined($this._polygon)) {
$this._polygon = $this.createPolygon();
$this._polygon.objId = $this.objId;
}
}
$this._positions.pop();
$this._positions.push(cartesian);
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.handler.setInputAction(function (evt) {
if (!$this._polygon) return;
var cartesian = $this.getCatesian3FromPX(evt.position);
$this.handler.destroy();
$this._positions.pop();
$this._positions.push(cartesian);
func && func($this._positions);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}
createPolygon(obj) {
var $this = this;
return this.viewer.entities.add({
polygon: {
hierarchy: new Cesium.CallbackProperty(function () {
return new Cesium.PolygonHierarchy($this._positions);
}, false),
// clampToGround: true,
// show: true,
// fill: false,
// material: Cesium.Color.RED,
// width: 3,
material: new Cesium.Color.fromCssColorString("#FFD700").withAlpha(.2),
perPositionHeight: true,
outlineColor: Cesium.Color.BLACK,
outlineWidth: 3,
outline: true
}
});
}
createPolyline() {
var $this = this;
return this.viewer.entities.add({
polyline: {
positions: new Cesium.CallbackProperty(function () {
return $this._positions
}, false),
clampToGround: true,
material: Cesium.Color.YELLOW,
width: 5
}
});
}
getCatesian3FromPX(px) {
var cartesian;
var ray = this.viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene);
return cartesian;
}
destroy() {
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this._polygon) {
this.viewer.entities.remove(this._polygon);
this._polygon = null;
}
if (this._polyline) {
this.viewer.entities.remove(this._polyline);
this._polyline = null;
}
this._positions = [];
}
},
point: class DrawBillboard {
constructor(arg) {
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = arg.viewer;
this._position = null;
this._billboard = null;
}
get billboard() {
return this._billboard;
}
get position() {
return this._position;
}
startCreate() {
var $this = this;
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this.handler.setInputAction(evt => { //单机开始绘制
var cartesian = $this.getCatesian3FromPX(evt.position);
// if(!Cesium.defined($this._billboard)){
// $this._billboard = $this.createBillboard(cartesian);
// $this.handler.destroy();
// }
this.handler.destroy();
this.handler = undefined;
this.createBillboard(cartesian);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
}
createBillboard(cartesian) {
var billboard = this.viewer.entities.add({
position: cartesian,
point: {
color: Cesium.Color.SKYBLUE,
pixelSize: 10,
outlineColor: Cesium.Color.YELLOW,
outlineWidth: 3,
disableDepthTestDistance: Number.POSITIVE_INFINITY
}
});
billboard.objId = this.objId;
return billboard;
}
destroy() {
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this._billboard) {
this.viewer.entities.remove(this._billboard);
this._billboard = null;
}
this._position = null;
}
getCatesian3FromPX(px) {
var cartesian;
var ray = this.viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene);
return cartesian;
}
},
polyline: class DrawPolyline {
constructor(arg) {
//设置唯一id 备用
this.objId = Number((new Date()).getTime() + "" + Number(Math.random() * 1000).toFixed(0));
this.viewer = arg.viewer;
//事件
this.handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
this._polyline = null;
this._positions = [];
}
//获取线
get line(){
return this._polyline;
}
//获取线的坐标数组
get positions(){
return this._positions;
}
//开始创建
startCreate() {
var $this = this;
this.handler.setInputAction(function (evt) { //单机开始绘制
//屏幕坐标转地形上坐标
var cartesian = $this.getCatesian3FromPX(evt.position);
if ($this._positions.length == 0) {
$this._positions.push(cartesian.clone());
}
$this._positions.push(cartesian);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
this.handler.setInputAction(function (evt) { //移动时绘制线
if ($this._positions.length < 1) return;
var cartesian = $this.getCatesian3FromPX(evt.endPosition);
if ($this._positions.length == 2) {
if (!Cesium.defined($this._polyline)) {
$this._polyline = $this.createPolyline();
}
}
if ($this._polyline) {
$this._positions.pop();
$this._positions.push(cartesian);
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
this.handler.setInputAction(function (evt) { //单机开始绘制
if (!$this._polyline) return;
var cartesian = $this.getCatesian3FromPX(evt.position);
$this.handler.destroy();
$this._positions.pop();
$this._positions.push(cartesian);
}, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
}
createPolyline(obj) {
if (!obj) obj = {};
var $this = this;
var polyline = this.viewer.entities.add({
polyline: {
//使用cesium的peoperty
positions: new Cesium.CallbackProperty(function () {
return $this._positions
}, false),
show: true,
material: Cesium.Color.YELLOW,
width:5 ,
clampToGround:true
}
});
polyline.objId = this.objId;
return polyline;
}
destroy() {
this.linePointArr = [];
if (this.handler) {
this.handler.destroy();
this.handler = null;
}
if (this._polyline) {
this.viewer.entities.remove(this._polyline);
this._polyline = null;
}
this._positions = [];
}
getCatesian3FromPX(px) {
var cartesian;
var ray = this.viewer.camera.getPickRay(px);
if (!ray) return null;
cartesian = this.viewer.scene.globe.pick(ray, this.viewer.scene);
return cartesian;
}
}
}
}
export default {
mapView: undefined
}
\ No newline at end of file