UNPKG

gisviewer-vue3-arcgis

Version:

在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:

265 lines (264 loc) 6.79 kB
import { Point as d, Polyline as l } from "@arcgis/core/geometry"; import * as u from "@arcgis/core/geometry/geometryEngineAsync"; import * as y from "@arcgis/core/geometry/support/webMercatorUtils"; import h from "@turf/bearing"; import p from "@turf/destination"; import * as f from "@turf/helpers"; import L from "@turf/length"; import O from "@turf/line-slice-along"; import w from "pako"; import P from "proj4"; class o { /** * 得到某个点在一定方向、距离之外的另一个点 * @param point * @param angel * @param distance * @returns */ static destinationWithPoint(t, e, n) { const r = f.point([t.x, t.y]), i = p(r, n, e, { units: "meters" }); return new d({ x: i.geometry.coordinates[0], y: i.geometry.coordinates[1] }); } /** * 线段与正北方向夹角 * @param line * @returns */ static angleOfLine(t) { const e = t.paths[0], n = f.point(e[0]), r = f.point(e[e.length - 1]); return h(n, r); } /** * 在头尾两个方向上延长折线 * @param line * @param distance */ static extendLineInTowDir(t, e) { const n = t.paths[0], r = f.point(n[0]), i = f.point(n[1]), a = h(i, r), c = p(r, e, a, { units: "meters" }), g = a > 0 ? a - 180 : a + 180, s = p(i, e, g, { units: "meters" }); return new l({ paths: [ [c.geometry.coordinates, s.geometry.coordinates] ] }); } /** * 两条线的交点 * @param line1 * @param line2 * @returns */ static async getIntersectPointOfTwoLines(t, e) { const n = await u.intersectLinesToPoints( t, e ); if (n.length) return n[0]; } /** * 获取停止线与车道面的交点 * @param stopLine * @param lanePolygon * @param offsetDistances * @returns */ static async getIntersectPointsOfStopLineAndLane(t, e, n) { let r = await o.getIntersectPointOfLineAndPolygon( t, e ); if (await o.pointDistance(r) < 3 && n) { for (const i of n) if (r = await o.getIntersectPointOfLineAndPolygon( t, e, i ), await o.pointDistance(r) > 2.5) { const a = new l({ paths: [r] }); return (await o.getOffsetLine( a, -i )).paths[0]; } } else return r; return []; } /** * 两个点之间的距离 * @param points * @returns */ static async pointDistance(t) { if (t.length < 2) return 0; const e = new l({ paths: [t] }); return await u.geodesicLength(e, "meters"); } /** * 线按一定距离平移之后,与面相交的两个端点 * @param line * @param polygon * @param offsetDistance 线平移的距离 * @returns 线面交线的头尾端点 */ static async getIntersectPointOfLineAndPolygon(t, e, n = 0) { n !== 0 && (t = await o.getOffsetLine(t, n)); const r = await u.intersect(t, e); if (r instanceof l) { const i = r.paths[0], a = i[0], c = i[i.length - 1]; return [a, c]; } return []; } /** * 对polyline做平移 * @param line * @param offsetDistance * @returns 平移后的polyline */ static async getOffsetLine(t, e) { const n = y.geographicToWebMercator(t), r = await u.offset( n, e, "meters" ); return y.webMercatorToGeographic( r, !1 ); } /** * 解压 * @param key * @returns */ static unzip(t) { try { const e = [], n = t.split(""); for (let i = 0; i < n.length; i++) { const a = n[i]; e.push(a.charCodeAt(0)); } const r = new Uint8Array(e); return w.inflate(r, { to: "string" }); } catch { console.log(`非压缩内容: ${t}`); } } static getStdVecEntries(t, e = !1) { const n = new Array(t.size()); for (let r = 0; r < t.size(); r++) n[r] = t.get(r); return e && t.delete(), n; } static getStdMapEntries(t) { const e = []; for (const n of o.getStdMapKeys(t)) e.push([n, t.get(n)]); return e; } static getStdMapKeys(t, e = !1) { const n = [], r = t.keys(); for (let i = 0; i < r.size(); i++) n.push(r.get(i)); return r.delete(), e && t.delete(), n; } static setGeoData(t, e, n) { o.geoReference = t, o.xOffset = e, o.yOffset = n; } /** * OpenDrive坐标转换为WGS84坐标 * @param line * @returns */ static transformLineProjection(t) { try { return t.map( (e) => P(o.geoReference).inverse([ e[0] - o.xOffset, e[1] - o.yOffset ]) ); } catch { return console.error( "OpenDrive坐标转换为WGS84坐标失败", o.geoReference ), t; } } static transformPointProjection(t) { try { return P(o.geoReference).inverse([ t[0] - o.xOffset, t[1] - o.yOffset ]); } catch { return console.error( "OpenDrive坐标转换为WGS84坐标失败", o.geoReference ), t; } } static pointsEqual(t, e) { return Math.abs(t[0] - e[0]) < Number.EPSILON && Math.abs(t[1] - e[1]) < Number.EPSILON; } static getExtensionLine(t, e, n) { const r = f.point(t), i = f.point(e), a = h(r, i); return p(i, n, a, { units: "meters" }).geometry.coordinates; } static isCoordinateValid(t) { return typeof t.latitude == "string" && (t.latitude = Number(t.latitude)), typeof t.longitude == "string" && (t.longitude = Number(t.longitude)), t.latitude !== null && t.longitude !== null && !isNaN(t.latitude) && !isNaN(t.longitude) && t.latitude !== 0 && t.longitude !== 0; } /** * 获取折线中点 * @param line * @returns */ static getCenterPointInLine(t) { const e = f.lineString(t), n = L(e, { units: "meters" }) / 2, r = O(e, 0, n, { units: "meters" }); return r.geometry.coordinates[r.geometry.coordinates.length - 1]; } static async viewGoto(t, e, n = !0) { var a, c; const i = localStorage.getItem("gpu") !== "Unknown"; if (!n) { if (e.length > 0) { const g = e.map((s) => s.geometry).filter((s) => s); if (g.length > 0) { let s = (a = await u.union(g)) == null ? void 0 : a.extent; s && (s = s.expand(1.3), i ? await t.goTo(s.center, { duration: 1e3 }) : t.center = s.center); } } return; } if (i) await t.goTo(e, { duration: 1e3 }); else if (e.length > 0) { const g = e.map((s) => s.geometry).filter((s) => s); if (g.length > 0) { let s = (c = await u.union(g)) == null ? void 0 : c.extent; s && (s = s.expand(1.3), t.extent = s); } } } } export { o as default };