123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- function getCirclePoint(x, y, radius) {
- var pointArr = []
- for (var i = 0; i < 361; i++) {
- if (i < 360) {
- pointArr.push({
- x: x + radius * Math.cos(i * 2 * Math.PI / 360),
- y: y + radius * Math.sin(i * 2 * Math.PI / 360)
- })
- } else {
- pointArr.push({
- x: x + radius * Math.cos(0 * 2 * Math.PI / 360),
- y: y + radius * Math.sin(0 * 2 * Math.PI / 360)
- })
- }
- }
- return pointArr; //x - y
- };
- function addCircleToPolygon(options, allCirclePoint, extrudes) {
- var altitudes = [];
- var guid = [];
- var guidArr = [];
- for (var n = 0; n < allCirclePoint.length; n++) {
- var curExtrude = extrudes[n];
- altitudes = [];
- for (var j = 0; j < allCirclePoint[n].length; j++) {
- altitudes.push(curExtrude);
- }
- if (n == 0) {
- if (options.display.show2D) {
- map2DViewer.polygon({
- action: 'add',
- groupId:options.groupId,
- geojson: {
- "type": "Feature",
- "properties": {
- title: options.properties.title,
- color: options.properties.color,
- weight: options.properties.weight,
- fillColor: options.properties.fillColor,
- opacity: options.properties.opacity,
- fillOpacity: options.properties.fillOpacity,
- popupContent: '',
- extrude: 0, //拉伸高度
- altitude: altitudes, //点海拔高度
- altitudeMode: 0 //海拔模式
- },
- "geometry": {
- "type": "Polygon",
- "coordinates": [
- allCirclePoint[n]
- ]
- }
- }
- })
- }
- if (options.altitudeMode === 1) {
- if (options.display.show3D) {
- map3DViewer.polyline({
- action: 'add',
- groupId:options.groupId,
- geojson: {
- "type": "Feature",
- "properties": {
- title: options.properties.title,
- color: options.properties.color,
- weight: options.properties.weight,
- fillColor: options.properties.fillColor,
- opacity: options.properties.opacity,
- popupContent: '',
- extrude: 0, //拉伸高度
- altitude: altitudes, //点海拔高度
- altitudeMode: 0 //海拔模式
- },
- "geometry": {
- "type": "Polyline",
- "coordinates": allCirclePoint[n]
- }
- }
- })
- }
- }
- } else {
- if (options.display.show3D) {
- map3DViewer.polyline({
- action: 'add',
- groupId:options.groupId,
- geojson: {
- "type": "Feature",
- "properties": {
- title: options.properties.title,
- color: options.properties.color,
- weight: options.properties.weight,
- fillColor: options.properties.fillColor,
- opacity: options.properties.opacity,
- popupContent: '',
- extrude: 0, //拉伸高度
- altitude: altitudes, //点海拔高度
- altitudeMode: 1 //海拔模式
- },
- "geometry": {
- "type": "Polyline",
- "coordinates": allCirclePoint[n]
- }
- }
- })
- }
- }
- }
- };
- L.addLD = function(options) {
- //圆心
- var allCirclePoint = [];
- var center_lat = options.center.lat;
- var center_lon = options.center.lng;
- //半径
- var radius = options.radius; //米
- //计算圆心到极点的距离
- if (center_lat < 0) {
- var centerToPole = new L.LatLng(center_lat, center_lon).distanceTo(new L.LatLng(-90, center_lon));
- } else {
- var centerToPole = new L.LatLng(center_lat, center_lon).distanceTo(new L.LatLng(90, center_lon));
- }
- //转换定义 核心
- var epsg_4326 = "+proj=longlat +datum=WGS84 +no_defs "
- var esri_102016 = "+proj=aeqd +lat_0=90 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs"
- var self_defined = "+proj=aeqd +lat_0=" + center_lat + "+lon_0=" + center_lon + "+x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m no_defs"
- var circleTangle = options.circleTangle || 5;
- var extrudes = [];
- var minExtrudes = map23DUtil.getLDCircleExtrude(radius);
- for (var i = 0; i <= 90; i += circleTangle) {
- if (i == 90) {
- var curHeight = radius;
- } else {
- var ral = (i * Math.PI) / 180;
- var curHeight = radius * Math.sin(ral);
- }
- if (i != 0) {
- if (curHeight < minExtrudes) {
- curHeight = minExtrudes;
- }
- }
- var curBRedius = Math.sqrt(Math.pow(radius, 2) - Math.pow(curHeight, 2));
- //生成圆平面点;
- var pointArr = getCirclePoint(0, 0, curBRedius);
- //圆的轮廓点转换为经纬度,当做GeoJSON来使用。
- var circlePoints = [];
- extrudes.push(curHeight);
- for (var k = 0; k < pointArr.length; k++) {
- var item = pointArr[k];
- //核心 将平面坐标转经纬度坐标
- var xy = proj4(self_defined, epsg_4326, [item.x, item.y]);
- circlePoints.push([
- xy[0],
- xy[1]
- ])
- }
- if (i == 0) { //二维雷达显示坐标处理
- if (curBRedius >= centerToPole) {
- if (center_lat < 0) {
- circlePoints = map23DUtil.southHeightLatLD(map23DUtil.southHeightLatLD(map23DUtil.lnglatsToDateLineLnglats(circlePoints)));
- circlePoints.push([circlePoints[circlePoints.length - 1][0], -90])
- circlePoints[circlePoints.length - 2] = [circlePoints[circlePoints.length - 3][0], -90];
- } else {
- circlePoints = map23DUtil.northHeightLatLD(map23DUtil.northHeightLatLD(map23DUtil.lnglatsToDateLineLnglats(circlePoints)));
- circlePoints.push([circlePoints[circlePoints.length - 1][0], 90])
- circlePoints[circlePoints.length - 2] = [circlePoints[circlePoints.length - 3][0], 90];
- }
- } else {
- circlePoints = map23DUtil.lnglatsToDateLineLnglats(circlePoints);
- }
- } else { //三维雷达显示坐标处理
- if (curBRedius > centerToPole) {
- //判断中心点是在南半球还是北半球
- if (center_lat < 0) {
- circlePoints = map23DUtil.southHeightLatLD(map23DUtil.southHeightLatLD(map23DUtil.lnglatsToDateLineLnglats(circlePoints)))
- } else {
- circlePoints = map23DUtil.northHeightLatLD(map23DUtil.northHeightLatLD(map23DUtil.lnglatsToDateLineLnglats(circlePoints)))
- }
- }
- }
- allCirclePoint.push(circlePoints)
- if (i == 90) {
- addCircleToPolygon(options, allCirclePoint, extrudes);
- }
- }
- };
|