import axios from "axios";
|
import mapConfig from "./mapConfig";
|
import * as turf from "@turf/turf";
|
import mapServer from "./mapServer";
|
import { getToken } from "../../../utils/auth";
|
import modelLayer from "./modelLayer";
|
import {
|
getPublickey,
|
getQueryEentity,
|
getSettingPublickey,
|
getQueryEentity2
|
} from "../../../api/modelBase.js";
|
import { nextTick } from "vue";
|
import JSEncrypt from "jsencrypt";
|
const layerJson = {
|
layerData: null,
|
url: null,
|
coord: null,
|
rectangularSensor: null,
|
init(url) {
|
this.url = url;
|
this.getJsonLayer();
|
},
|
getJsonLayer() {
|
const that = this;
|
Cesium.GeoJsonDataSource.load(this.url, {
|
stroke: Cesium.Color.fromCssColorString("#FFFFFF"), //多边形或线的颜色
|
fill: Cesium.Color.fromCssColorString("#FFFFFF"), //多边形或线的颜色
|
strokeWidth: 1, //多边形或线 宽度
|
clampToGround: true //多边形或线 固定在地面上true/false
|
}).then((dataSource) => {
|
const entities = dataSource.entities.values;
|
that.layerData = dataSource;
|
entities.map((item) => {
|
item.polygon.heightReference =
|
Cesium.HeightReference.RELATIVE_TO_GROUND; // 贴地
|
item.polygon.height = 0; // 距地高度0米
|
item.polygon.extrudedHeightReference =
|
Cesium.HeightReference.RELATIVE_TO_GROUND; //拉伸
|
item.polygon.extrudedHeight = item.properties["ELEVATION"]; // 拉伸高度
|
var polyPositions = item.polygon.hierarchy.getValue().positions;
|
var polyCenter = Cesium.BoundingSphere.fromPoints(polyPositions).center; //中心点
|
polyCenter = Cesium.Ellipsoid.WGS84.scaleToGeodeticSurface(polyCenter);
|
item.position = polyCenter;
|
if (item.id == "965") {
|
that.coord = {
|
lon: item.properties["lon"]._value,
|
lat: item.properties["lat"]._value
|
};
|
}
|
item.label = {
|
text: "",
|
font: "500 20px Helvetica",
|
scale: 1,
|
style: Cesium.LabelStyle.FILL,
|
fillColor: Cesium.Color.WHITE,
|
|
eyeOffset: new Cesium.Cartesian3(
|
0.0,
|
item.polygon.extrudedHeight + 1,
|
-(item.polygon.extrudedHeight + 1)
|
),
|
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
showBackground: true,
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
|
50.0,
|
500.0
|
),
|
backgroundColor: new Cesium.Color(26 / 255, 196 / 255, 228 / 255, 1.0) //背景顔色
|
};
|
});
|
Viewer.dataSources.add(dataSource);
|
});
|
},
|
setQyeryData(res) {
|
this.setTitleSetRest();
|
if (res.indexOf("海军陆战队") > -1) {
|
this.setQueryExtent2();
|
} else if (res.indexOf("军事目标") > -1) {
|
this.setQueryByFiled("军事目标", "#409EFF", false);
|
} else if (res.indexOf("民宅") > -1) {
|
this.setQueryByFiled("民宅", "#808080", false);
|
} else if (res.indexOf("经济目标") > -1) {
|
this.setQueryByFiled("经济目标", "#FFFF00", true);
|
} else if (res.indexOf("堤丰") > -1) {
|
// this.setQueryTF("SubicBayWeapon_wfs", "weapons", "堤丰系统");
|
this.setQueryTF2("堤丰系统");
|
}
|
},
|
|
getPublickey(res) {
|
const encrypt = new JSEncrypt();
|
encrypt.setPublicKey(modelLayer.publickey + "");
|
return encrypt.encrypt(res);
|
},
|
setQueryTF2(name) {
|
const obj = "weaponname = '" + name + "'" + "";
|
const filed = this.getPublickey(obj);
|
const layer = modelLayer.layers.filter((item) => {
|
if (item.name == "武器点") {
|
return item;
|
}
|
});
|
if (layer.length <= 0) return;
|
getQueryEentity({
|
token: getToken(),
|
start: 1,
|
count: 0,
|
containCount: true,
|
layerid: layer[0].id,
|
dbid: modelLayer.dbid,
|
where: filed
|
}).then((response) => {
|
if (response.code != 200) return;
|
const geom = response.data.items[0];
|
const position = [geom._x, geom._y, 0];
|
const cylinder = {
|
radius: 1000, //半径
|
angle: 30, //扫描角度(可选)
|
speed: 5, //倍速(可选)
|
stackPartitions: 80, //横向网格数(可选)
|
slicePartitions: 80, //纵向网格数(可选)
|
wallColor: "rgba(255,255,255,0)" //扫描墙颜色(可选)
|
};
|
this.rectangularSensor = earthCtrl.factory.createRectangularSensor(
|
position,
|
cylinder
|
);
|
Viewer.zoomTo(this.rectangularSensor.item);
|
});
|
},
|
setQueryByFiled(name, color, label) {
|
const obj = "targettype = '" + name + "'" + "";
|
const filed = this.getPublickey(obj);
|
var objItem = mapServer.listData.filter((item) => {
|
if (item.type === "Tileset") {
|
return item;
|
}
|
});
|
if (objItem.length <= 0) return;
|
var tileset = objItem[0];
|
getQueryEentity({
|
token: getToken(),
|
start: 1,
|
count: 0,
|
containCount: true,
|
layerid: tileset.layerId,
|
dbid: modelLayer.dbid,
|
where: filed
|
}).then((response) => {
|
if (response.code != 200) return;
|
var std = [];
|
const items = response.data.items;
|
items.map((item) => {
|
if (item.targettype == name) {
|
std.push(item.seid);
|
}
|
});
|
nextTick(() => {
|
if (std.length <= 0) return;
|
this.setTilesetColorChange(tileset, std, color);
|
});
|
});
|
},
|
setTitleSetRest() {
|
if (this.rectangularSensor) {
|
this.rectangularSensor.wall.forEach((wall) => {
|
Viewer.entities.remove(wall);
|
});
|
Viewer.entities.remove(this.rectangularSensor.item);
|
this.rectangularSensor = null;
|
}
|
var objItem = mapServer.listData.filter((item) => {
|
if (item.type === "Tileset") {
|
return item;
|
}
|
});
|
if (objItem.length <= 0) return;
|
var tileset = objItem[0].layer;
|
tileset.style = new Cesium.Cesium3DTileStyle({
|
color: {
|
evaluateColor: (feature) => {
|
return new Cesium.Color.fromCssColorString("#FFFFFF");
|
}
|
}
|
});
|
},
|
setTilesetColorChange(model, ids, color) {
|
var tileset = model.layer;
|
tileset.style = new Cesium.Cesium3DTileStyle({
|
color: {
|
evaluateColor: (feature) => {
|
const id = feature.getProperty("id");
|
if (ids.indexOf(id) > -1) {
|
return new SmartEarth.Cesium.Color.fromCssColorString(color);
|
} else {
|
return new SmartEarth.Cesium.Color.fromCssColorString("#FFFFFF");
|
}
|
}
|
}
|
});
|
},
|
getTileSet() {
|
var objItem = mapServer.listData.filter((item) => {
|
if (item.type === "Tileset") {
|
return item;
|
}
|
});
|
if (objItem.length <= 0) {
|
return null;
|
}
|
return objItem[0];
|
},
|
setQueryExtent2() {
|
const tileset = this.getTileSet();
|
if (!tileset) {
|
return;
|
}
|
const obj = "ejfl like '%空军基地%'";
|
const filed = this.getPublickey(obj);
|
getQueryEentity({
|
token: getToken(),
|
start: 1,
|
count: 0,
|
containCount: true,
|
layerid: tileset.layerId,
|
dbid: modelLayer.dbid,
|
where: filed
|
}).then((response) => {
|
if (response.code != 200) return;
|
const items = response.data.items[0];
|
|
this.getQueryGeomExtent(items, tileset.layerId);
|
});
|
},
|
getQueryGeomExtent(items, layerid) {
|
var geom = mapConfig.setPointToCrical(items.lon, items.lat, 1);
|
const token = getToken();
|
const url =
|
config.modelBase.url +
|
config.modelBase.geo +
|
"/entitydbdata/query/entity";
|
|
axios
|
.post(
|
url,
|
{
|
layerid: layerid,
|
dbid: modelLayer.dbid,
|
geometry: JSON.stringify(geom.geometry),
|
returnCountOnly: true,
|
token: token
|
},
|
{
|
headers: {
|
Authorization: token,
|
"Content-Type": "application/x-www-form-urlencoded"
|
// 'Cookie': "token=" + token,
|
// 'Token': token
|
}
|
}
|
)
|
.then((response) => {
|
this.getLayerModelList(url, response.data.data, geom.geometry, layerid);
|
});
|
},
|
getLayerModelList(url, count, geom, layerid) {
|
const token = getToken();
|
|
axios
|
.post(
|
url,
|
{
|
token: token,
|
dbid: modelLayer.dbid,
|
layerid: layerid,
|
start: 1,
|
count: count,
|
containCount: true,
|
geometry: JSON.stringify(geom)
|
},
|
{
|
headers: {
|
Authorization: token,
|
"Content-Type": "application/x-www-form-urlencoded"
|
}
|
}
|
)
|
.then((response) => {
|
var std = [];
|
const items = response.data.data.items;
|
items.map((val) => {
|
std.push(val.seid);
|
});
|
|
nextTick(() => {
|
var objItem = mapServer.listData.filter((item) => {
|
if (item.type === "Tileset") {
|
return item;
|
}
|
});
|
if (objItem.length <= 0) return;
|
var tileset = objItem[0];
|
if (std.length <= 0) return;
|
this.setTilesetColorChange(tileset, std, "#FF0000");
|
});
|
});
|
},
|
setQueryExtent(res) {
|
const geom = mapConfig.setPointToCrical(res.lon, res.lat, 5000);
|
var arr = [];
|
const coord = geom.geometry.coordinates[0];
|
coord.map((item) => {
|
if (arr.length == 0) {
|
arr = item;
|
} else {
|
arr = [...arr, ...item];
|
}
|
});
|
arr = arr.toString().replaceAll(",", " ");
|
this.getQuery(this.url, arr, this.layerData);
|
},
|
getQuery(url, area, layer) {
|
const entity = layer.entities.values;
|
entity.filter((rs) => {
|
rs.polygon.material = new Cesium.Color.fromCssColorString("#FFFFFF");
|
});
|
axios
|
.get(url, {
|
params: {
|
version: "1.3.0",
|
request: "GetFeature",
|
typename: "GeoEntity",
|
propertyname: "*",
|
format: "json",
|
filter: `<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc"><ogc:Intersects><ogc:PropertyName /><gml:Polygon xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326"><gml:exterior><gml:LinearRing><gml:posList>${area}</gml:posList></gml:LinearRing></gml:exterior></gml:Polygon></ogc:Intersects></ogc:Filter>`
|
}
|
})
|
.then((res) => {
|
const obj = res.data.features;
|
obj.filter((item) => {
|
entity.filter((rs) => {
|
if (item.id == rs.id) {
|
rs.polygon.material = Cesium.Color.RED;
|
}
|
});
|
});
|
});
|
},
|
setQueryTF(content, layer, name) {
|
const url = this.getQueryUrl(content, layer);
|
axios.get(url).then((res) => {
|
const data = res.data.features;
|
const obj = data.filter((item) => {
|
if (item.properties.weaponname == name) {
|
return item;
|
}
|
});
|
if (obj.length <= 0) return;
|
var centroid = turf.centroid(obj[0]);
|
const geom = centroid.geometry.coordinates;
|
const position = [geom[0], geom[1], 0];
|
const cylinder = {
|
radius: 1000, //半径
|
angle: 30, //扫描角度(可选)
|
speed: 5, //倍速(可选)
|
stackPartitions: 80, //横向网格数(可选)
|
slicePartitions: 80, //纵向网格数(可选)
|
wallColor: "rgba(255,255,255,0)" //扫描墙颜色(可选)
|
};
|
const item = earthCtrl.factory.createRectangularSensor(
|
position,
|
cylinder
|
);
|
Viewer.zoomTo(item.item);
|
});
|
},
|
getQueryUrl(content, layer) {
|
return (
|
"https://cim.smartearth.cn/SEserver/wfsserver/" +
|
content +
|
"?version=1.1.0&request=GetFeature&format=json&typename=" +
|
layer
|
);
|
}
|
};
|
export default layerJson;
|