gisviewer-vue3-arcgis
Version:
在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:
101 lines (100 loc) • 2.64 kB
JavaScript
import * as c from "@turf/helpers";
import { convex as m, buffer as u } from "@turf/turf";
import f from "ol/Feature";
import { Polygon as y } from "ol/geom";
import p from "ol/layer/Vector";
import w from "ol/source/Vector";
import { Style as a, Stroke as g } from "ol/style";
class I {
constructor(r) {
this.map = r, this.source = new w(), this.districtLayer = new p({
source: this.source,
style: this.createDistrictStyle()
}), this.districtLayer.set("id", "district-layer"), this.map.addLayer(this.districtLayer);
}
createDistrictStyle() {
return [
// 下层:蓝色半透明实线
new a({
stroke: new g({
color: "rgba(111, 100, 255, 0.4)",
width: 2
})
}),
// 上层:蓝色虚线
new a({
stroke: new g({
color: "rgba(111, 100, 255, 1)",
width: 2,
lineDash: [8, 6]
})
})
];
}
addDistricts(r) {
var o;
this.source.clear();
const s = [];
for (const t of r) {
const e = t.getAllSignalCoordinates();
let n = null;
if (e.length >= 2)
if (e.length === 2)
n = c.lineString(e);
else {
const l = c.featureCollection(
e.map((i) => c.point(i))
);
n = m(l), n || (n = c.lineString(e));
}
else if (e.length === 1)
n = c.point(e[0]);
else
continue;
const d = u(n.geometry, 200, {
units: "meters"
});
if (d) {
const l = d.geometry.coordinates, i = new f({
geometry: new y(l)
});
i.set("districtId", t.id), i.set("name", t.name), i.set("type", "district"), this.source.addFeature(i);
const h = (o = i.getGeometry()) == null ? void 0 : o.getExtent();
h && s.push(h);
}
}
if (s.length > 0) {
const t = [...s[0]];
return s.slice(1).forEach((e) => {
t[0] = Math.min(t[0], e[0]), t[1] = Math.min(t[1], e[1]), t[2] = Math.max(t[2], e[2]), t[3] = Math.max(t[3], e[3]);
}), t;
} else
return;
}
setVisible(r) {
this.districtLayer.setVisible(r);
}
clear() {
this.source.clear();
}
highlight(r) {
const s = r.id;
let o = null;
if (this.source.getFeatures().forEach((t) => {
t.get("districtId") === s ? (t.setStyle(void 0), o = t) : t.setStyle(new a({}));
}), o) {
const t = o.getGeometry();
if (t)
return t.getExtent();
}
return null;
}
clearHighlight() {
this.source.getFeatures().forEach((r) => {
r.setStyle(void 0);
});
}
}
export {
I as default
};