123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- import proj4 from "proj4";
- import { Notification, MessageBox, Message, Loading } from "element-ui";
- import { tansParams, blobValidate } from "@/utils/ruoyi";
- const CTservice = axios.create({
- // 超时
- timeout: 60000,
- });
- // 响应拦截器
- CTservice.interceptors.response.use(
- (res) => {
- // 未设置状态码则默认成功状态
- const code = res.data.code || 200;
- // 二进制数据则直接返回
- if (
- res.request.responseType === "blob" ||
- res.request.responseType === "arraybuffer"
- ) {
- return res.data;
- }
- if (code !== 200) {
- console.log("err:模型服务获取失败,请检查服务!!" + error);
- // Message({
- // message: "模型服务获取失败,请检查服务",
- // type: "warning",
- // });
- return null;
- } else {
- return res;
- }
- },
- (error) => {
- console.log("err:模型服务获取失败,请检查服务!!" + error);
- // Message({
- // message: "模型服务获取失败,请检查服务",
- // type: "warning",
- // });
- return null;
- }
- );
- export const mapQuery = async (url, queryObj) => {
- let response = await CTservice.post(url, queryObj);
- if (response && response.data.featureCount > 0) {
- return response.data;
- } else {
- return null;
- }
- };
- export const mapanalyzePost = async (url, queryObj) => {
- let response = await CTservice.post(url, queryObj);
- if (response && response.data) {
- return response.data;
- } else {
- return null;
- }
- };
- export const mapanalyze = async (url, params) => {
- let response = await CTservice({
- url: url,
- method: "get",
- params: params,
- });
- if (response && response.data) {
- return response.data;
- } else {
- return null;
- }
- };
- /**
- * 获取面积
- * @param {Array} points [
- { x: 109.513901747847, y: 18.3138227456355 },
- { x: 109.513756340215, y: 18.313823538585 },
- { x: 109.513301924234, y: 18.3138260150956 },
- { x: 109.513159896168, y: 18.313962267038 },
- { x: 109.513158251941, y: 18.3151722832427 },
- { x: 109.513299913524, y: 18.3153069903435 },
- { x: 109.513907590019, y: 18.3153036780715 },
- { x: 109.513901747847, y: 18.3138227456355 },
- ]
- * @returns Number
- */
- export const mapArea = async (points) => {
- if (!points) {
- return 0;
- }
- let response = await CTservice({
- url:
- window.supermapIServerUrl +
- "/iserver/services/geometry/restjsr/v1/geometry/area",
- method: "get",
- params: {
- point2Ds: JSON.stringify(points),
- unit: window.unit || "METER",
- prjCoordSys: "{ epsgcode: " + (window.epsgcode || "4490") + " }",
- },
- });
- if (response && response.area) {
- return response.area;
- } else {
- return 0;
- }
- };
- /**
- * 墨卡托转经纬度
- * @author
- * @param {*} x
- * @param {*} y
- * @returns [x,y]
- */
- export const mercator2lonLat = (x, y) => {
- var obj = proj4(proj4("EPSG:3857"), proj4("EPSG:4326"), [x, y]);
- return obj;
- };
- /**
- * 经纬度转墨卡托
- * @author
- * @param {*} x
- * @param {*} y
- * @returns [x,y]
- */
- export const lonLat2Mercator = (x, y) => {
- var obj = proj4(proj4("EPSG:4326"), proj4("EPSG:3857"), [x, y]);
- return obj;
- };
- /**
- * 笛卡尔坐标系转WGS84坐标系(经纬度)
- * @author
- * @param {object} point 点,笛卡尔坐标{x:x,y:y,z:z}
- * @returns {object} -lat: lat, lng: lng, alt: alt
- */
- export const cartesian3ToWGS84 = (point) => {
- var cartesian3 = new Cesium.Cartesian3(point.x, point.y, point.z);
- var cartographic = Cesium.Cartographic.fromCartesian(cartesian3);
- var lat = Cesium.Math.toDegrees(cartographic.latitude);
- var lng = Cesium.Math.toDegrees(cartographic.longitude);
- var alt = cartographic.height;
- return {
- lat: lat,
- lng: lng,
- alt: alt,
- };
- };
- /**
- * 对象数组扁平化
- * @param {array} arr 数组
- * @param {string} children
- * @returns
- */
- export const flatten = (arr, children = "children") => {
- return arr.reduce((result, item) => {
- return result.concat(
- item,
- Array.isArray(item[children]) ? flatten(item[children], children) : []
- );
- }, []);
- };
- /**
- * @author
- * @description 设置地下模式状态
- * @param {*} state
- */
- export const undergroundMode = (state) => {
- if (state) {
- viewer.scene.globe.globeAlpha = window.Layeralpha;
- } else {
- viewer.scene.globe.globeAlpha = 1;
- }
- // this.scene.undergroundMode = state; //设置开启地下场景
- };
- /**
- * @namespace 名称:getGroundPoint
- * @description 作用:根据经纬度(或者墨卡托)获取地面三维坐标
- * @param {*} lng 经度,
- * @param {*} lat 纬度,
- * @returns {Cartesian3} 返回笛卡尔坐标
- */
- export const getGroundPoint = async (lng, lat, completed) => {
- if (!lng || !lat) return null;
- try {
- let positions = [Cesium.Cartographic.fromDegrees(lng, lat)];
- //如果有dem高程,则取dem高程,如果没有,则地图面高度为0
- if (viewer.terrainProvider) {
- var promise = Cesium.sampleTerrainMostDetailed(
- viewer.terrainProvider,
- positions
- );
- const resultP = await Promise.resolve(promise);
- if (resultP && resultP.length > 0) {
- let myP = new Cesium.Cartesian3.fromDegrees(
- lng,
- lat,
- resultP[0].height
- );
- return myP;
- }
- }
- } catch (error) {
- return null;
- }
- let myP = Cesium.Cartesian3.fromDegrees(lng, lat, 0);
- return myP;
- };
- /**
- * @namespace 名称:getGroundPoint
- * @description 作用:根据经纬度(或者墨卡托)获取地面三维坐标
- * @param {Array} Points 经纬度,
- * @returns {Cartesian3} 返回经纬度
- */
- export const getXYZPoint = async (Points) => {
- if (!Points && Points.length > 0) return [];
- try {
- var positions = [];
- for (var index = 0; index < Points.length; index++) {
- var position = Points[index];
- positions.push(Cesium.Cartographic.fromDegrees(position[0], position[1]));
- }
- //如果有dem高程,则取dem高程,如果没有,则地图面高度为0
- if (viewer.terrainProvider) {
- var promise = Cesium.sampleTerrainMostDetailed(
- viewer.terrainProvider,
- positions
- );
- var resultPs = await Promise.resolve(promise);
- if (resultPs && resultPs.length > 0) {
- var xyzs = [];
- for (var index = 0; index < resultPs.length; index++) {
- var resultP = resultPs[index];
- var longitude = Cesium.Math.toDegrees(resultP.longitude);
- var latitude = Cesium.Math.toDegrees(resultP.latitude);
- xyzs.push({ x: longitude, y: latitude, z: resultP.height });
- }
- return xyzs;
- }
- } else {
- for (var index = 0; index < Points.length; index++) {
- var Point = Points[index];
- Point = { x: Point[0], y: Point[1], z: 0 };
- }
- return Points;
- }
- } catch (error) {
- return [];
- }
- };
|