gisviewer-vue3-arcgis
Version:
在应用中引入私服的包, 项目根目录下 新建文件 .npmrc 在 .npmrc 中对包源进行配置:
203 lines (202 loc) • 5.43 kB
JavaScript
import { Polygon as h } from "@arcgis/core/geometry";
import * as n from "@arcgis/core/geometry/geometryEngine.js";
import m from "@arcgis/core/Graphic";
import k from "@arcgis/core/layers/GraphicsLayer";
import g from "axios";
import { toRaw as L } from "vue";
import E from "../../stores/index.mjs";
import f from "./common-utils.mjs";
class R {
constructor(o) {
this.view = o, this.maskLayer = new k({
id: "police-jurisdiction"
}), this.view.map.add(this.maskLayer);
const t = E.useAppDataStore, r = L(t.mapConfig);
this.geoServer = r.geoServer;
}
async showJurisdiction(o) {
return this.geoServer ? o.type.toLowerCase() === "zd" ? await this.showZD(o.id) : o.type.toLowerCase() === "dd" ? await this.showDD(o.id) : { status: 0, message: "ok" } : { status: -1, message: "未配置GeoServer" };
}
/**
* 显示支队辖区
* @param zdCode
*/
async showZD(o) {
let t = await g.get(`${this.geoServer}/zd_edpass/wms`, {
params: {
service: "WFS",
version: "1.1.0",
request: "GetFeature",
typename: "zd_edpass:VIEW_SH_ZD",
outputFormat: "application/json",
CQL_FILTER: `ZD_CODE = ${o}`
}
});
if (t.status !== 200)
return { status: -1, message: t.status + " " + t.statusText };
const { features: r } = t.data;
if (!r || r.length === 0)
return { status: -1, message: "未查询到数据" };
this.maskLayer.removeAll();
const l = r[0].geometry.coordinates, s = [];
l.forEach((e) => {
const i = new h({
rings: e
});
s.push(i);
});
const p = s[0].centroid, u = n.geodesicBuffer(
p,
500,
"kilometers"
);
let a = n.difference(
u,
s[0]
);
for (let e = 1; e < s.length; e++)
a = n.difference(
a,
s[e]
);
const y = new m({
geometry: a,
symbol: {
type: "simple-fill",
color: [100, 100, 100, 0.8],
outline: {
width: 0
}
},
attributes: { type: "mask" }
});
this.maskLayer.add(y);
const d = s.map((e) => new m({
geometry: e,
symbol: {
type: "simple-line",
style: "solid",
color: [240, 156, 69],
width: 2
}
}));
if (this.maskLayer.addMany(d), await f.viewGoto(this.view, d), t = await g.get(`${this.geoServer}/zd_edpass/wms`, {
params: {
service: "WFS",
version: "1.1.0",
request: "GetFeature",
typename: "zd_edpass:VW_DWD_GEO_SH_DD",
outputFormat: "application/json",
CQL_FILTER: `ZD_CODE = ${o}`
}
}), t.status === 200) {
const { features: e } = t.data;
if (e && e.length > 0) {
const i = [];
e.forEach((c) => {
c.geometry.coordinates.forEach((_) => {
const v = new h({
rings: _
}), G = new m({
geometry: v,
symbol: {
type: "simple-line",
style: "dash",
color: [240, 156, 69],
width: 1
}
});
i.push(G);
});
const w = c.properties.DD_NAME, D = new m({
geometry: {
type: "point",
longitude: c.properties.CENTER_X,
latitude: c.properties.CENTER_Y
},
symbol: {
type: "text",
color: [240, 156, 69],
haloColor: [255, 255, 255],
haloSize: "2px",
text: w,
font: {
size: "14px",
weight: "bold",
family: "msyh"
}
}
});
i.push(D);
}), this.maskLayer.addMany(i);
}
}
return { status: 0, message: "ok" };
}
async showDD(o) {
this.maskLayer.removeAll();
const t = await g.get(`${this.geoServer}/zd_edpass/wms`, {
params: {
service: "WFS",
version: "1.1.0",
request: "GetFeature",
typename: "zd_edpass:VW_DWD_GEO_SH_DD",
outputFormat: "application/json",
CQL_FILTER: `DD_CODE = ${o}`
}
});
if (console.log(t), t.status !== 200)
return { status: -1, message: t.status + " " + t.statusText };
const { features: r } = t.data;
if (!r || r.length === 0)
return { status: -1, message: "未查询到数据" };
const l = r[0].geometry.coordinates, s = [];
l.forEach((e) => {
const i = new h({
rings: e
});
s.push(i);
});
const p = s[0].centroid, u = n.geodesicBuffer(
p,
100,
"kilometers"
);
let a = n.difference(
u,
s[0]
);
for (let e = 1; e < s.length; e++)
a = n.difference(
a,
s[e]
);
const y = new m({
geometry: a,
symbol: {
type: "simple-fill",
color: [100, 100, 100, 0.8],
outline: {
width: 0
}
}
});
this.maskLayer.add(y);
const d = s.map((e) => new m({
geometry: e,
symbol: {
type: "simple-line",
style: "dash",
color: [240, 156, 69],
width: 1
}
}));
return this.maskLayer.addMany(d), await f.viewGoto(this.view, d), { status: 0, message: "ok" };
}
clearJurisdiction() {
this.maskLayer.removeAll();
}
}
export {
R as default
};