gisviewer-vue3-arcgis
Version:
在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:
252 lines (251 loc) • 6.38 kB
JavaScript
import { Point as L, Polyline as g } from "@arcgis/core/geometry";
import * as f from "@arcgis/core/geometry/geometryEngineAsync";
import * as l from "@arcgis/core/geometry/support/webMercatorUtils";
import p from "@turf/bearing";
import u from "@turf/destination";
import * as c from "@turf/helpers";
import d from "@turf/length";
import O from "@turf/line-slice-along";
import w from "pako";
import h from "proj4";
class s {
/**
* 得到某个点在一定方向、距离之外的另一个点
* @param point
* @param angel
* @param distance
* @returns
*/
static destinationWithPoint(t, e, n) {
const r = c.point([t.x, t.y]), i = u(r, n, e, {
units: "meters"
});
return new L({
x: i.geometry.coordinates[0],
y: i.geometry.coordinates[1]
});
}
/**
* 线段与正北方向夹角
* @param line
* @returns
*/
static angleOfLine(t) {
const e = t.paths[0], n = c.point(e[0]), r = c.point(e[e.length - 1]);
return p(n, r);
}
/**
* 在头尾两个方向上延长折线
* @param line
* @param distance
*/
static extendLineInTowDir(t, e) {
const n = t.paths[0], r = c.point(n[0]), i = c.point(n[1]), o = p(i, r), a = u(r, e, o, {
units: "meters"
}), y = o > 0 ? o - 180 : o + 180, P = u(i, e, y, {
units: "meters"
});
return new g({
paths: [
[a.geometry.coordinates, P.geometry.coordinates]
]
});
}
/**
* 两条线的交点
* @param line1
* @param line2
* @returns
*/
static async getIntersectPointOfTwoLines(t, e) {
const n = await f.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 s.getIntersectPointOfLineAndPolygon(
t,
e
);
if (await s.pointDistance(r) < 3 && n) {
for (const i of n)
if (r = await s.getIntersectPointOfLineAndPolygon(
t,
e,
i
), await s.pointDistance(r) > 2.5) {
const o = new g({ paths: [r] });
return (await s.getOffsetLine(
o,
-i
)).paths[0];
}
} else
return r;
return [];
}
/**
* 两个点之间的距离
* @param points
* @returns
*/
static async pointDistance(t) {
if (t.length < 2)
return 0;
const e = new g({ paths: [t] });
return await f.geodesicLength(e, "meters");
}
/**
* 线按一定距离平移之后,与面相交的两个端点
* @param line
* @param polygon
* @param offsetDistance 线平移的距离
* @returns 线面交线的头尾端点
*/
static async getIntersectPointOfLineAndPolygon(t, e, n = 0) {
n !== 0 && (t = await s.getOffsetLine(t, n));
const r = await f.intersect(t, e);
if (r instanceof g) {
const i = r.paths[0], o = i[0], a = i[i.length - 1];
return [o, a];
}
return [];
}
/**
* 对polyline做平移
* @param line
* @param offsetDistance
* @returns 平移后的polyline
*/
static async getOffsetLine(t, e) {
const n = l.geographicToWebMercator(t), r = await f.offset(
n,
e,
"meters"
);
return l.webMercatorToGeographic(
r,
!1
);
}
/**
* 解压
* @param key
* @returns
*/
static unzip(t) {
try {
const e = [], n = t.split("");
for (let i = 0; i < n.length; i++) {
const o = n[i];
e.push(o.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 s.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) {
s.geoReference = t, s.xOffset = e, s.yOffset = n;
}
/**
* OpenDrive坐标转换为WGS84坐标
* @param line
* @returns
*/
static transformLineProjection(t) {
try {
return t.map(
(e) => h(s.geoReference).inverse([
e[0] - s.xOffset,
e[1] - s.yOffset
])
);
} catch {
return console.error(
"OpenDrive坐标转换为WGS84坐标失败",
s.geoReference
), t;
}
}
static transformPointProjection(t) {
try {
return h(s.geoReference).inverse([
t[0] - s.xOffset,
t[1] - s.yOffset
]);
} catch {
return console.error(
"OpenDrive坐标转换为WGS84坐标失败",
s.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 = c.point(t), i = c.point(e), o = p(r, i);
return u(i, n, o, { 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 = c.lineString(t), n = d(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) {
var i;
if (localStorage.getItem("gpu") !== "Unknown")
await t.goTo(e, {
duration: 1e3
});
else if (e.length > 0) {
const o = e.map((a) => a.geometry).filter((a) => a);
if (o.length > 0) {
const a = (i = await f.union(o)) == null ? void 0 : i.extent;
a && (t.extent = a);
}
}
}
}
export {
s as default
};