车辆轮询

main
许宏杰 6 months ago
parent 17077ffb91
commit 0c51154f47

@ -37,8 +37,8 @@
type="text/javascript" type="text/javascript"
></script> ></script>
<script src="./lib/localforage.js" type="text/javascript"></script> <!-- <script src="./lib/localforage.js" type="text/javascript"></script>
<script src="./lib/CesiumNetworkPlug.js" type="text/javascript"></script> <script src="./lib/CesiumNetworkPlug.js" type="text/javascript"></script> -->
<title><%= webpackConfig.name %></title> <title><%= webpackConfig.name %></title>
<!--[if lt IE 11 <!--[if lt IE 11

@ -1,6 +1,5 @@
import request from "@/utils/request-yunkun.js"; import request from "@/utils/request-yunkun.js";
const sessionId = localStorage.getItem("SESSION_ID"); const sessionId = localStorage.getItem("SESSION_ID");
// 登录 // 登录
export function lgoin(query) { export function lgoin(query) {
return request({ return request({
@ -20,3 +19,14 @@ export function getCarList(query) {
params: query, params: query,
}); });
} }
//车辆点位查询
export function getCarPoint(query) {
query.sessionId = sessionId;
return request({
url: "/get_gps_r.jsp",
method: "GET",
params: query,
});
}

@ -40,22 +40,29 @@
</template> </template>
<script> <script>
import carJSON from "@/api/carrRealtimeLocation.json";
import MarsMap from "@/components/mars-map"; import MarsMap from "@/components/mars-map";
// import grids from "@/components/grids.vue"; // import grids from "@/components/grids.vue";
import { lgoin, getCarList } from "@/api/yunkun/yunkun.js"; import { getCarPoint } from "@/api/yunkun/yunkun.js";
export default { export default {
data() { data() {
const basePathUrl = window.basePathUrl || ""; const basePathUrl = window.basePathUrl || "";
return { return {
list: [],
multipleList: ["营运线路", "维护线路", "临时任务"], multipleList: ["营运线路", "维护线路", "临时任务"],
selectedItems: [], selectedItems: [],
graphicLayer: null, graphicLayer: null,
baseUrl: basePathUrl + "lib/geoJson/tileset.json", baseUrl: basePathUrl + "lib/geoJson/tileset.json",
carUrl: basePathUrl + "lib/car.gltf", carUrl: basePathUrl + "lib/qiche.gltf",
map: null, map: null,
options: { options: {
scene: { scene: {
// center: {
// lat: 31.754913,
// lng: 117.248572,
// alt: 6220,
// heading: 357,
// pitch: -31,
// },
center: { center: {
lat: 31.212805, lat: 31.212805,
lng: 120.607156, lng: 120.607156,
@ -63,24 +70,35 @@ export default {
heading: 357.9, heading: 357.9,
pitch: -31.5, pitch: -31.5,
}, },
fog: false,
fxaa: false,
removeDblClick: true,
requestRenderMode: false,
scene3DOnly: false,
sceneMode: 3,
shadows: false,
showMoon: false,
showSkyAtmosphere: false,
showSkyBox: false,
showSun: false,
}, },
control: { control: {
contextmenu: { preventDefault: false, hasDefault: false }, contextmenu: { preventDefault: false, hasDefault: false },
}, },
basemaps: [ basemaps: [
{ // {
name: "mapbox影像图", // name: "mapbox",
icon: "img/basemaps/mapboxSatellite.png", // icon: "img/basemaps/mapboxSatellite.png",
type: "mapbox", // type: "mapbox",
username: "sharealex", // username: "sharealex",
styleId: "cly5i21fn00e901prgq643t4r", // styleId: "cly5i21fn00e901prgq643t4r",
token: // token:
"pk.eyJ1Ijoic2hhcmVhbGV4IiwiYSI6ImNsaXNhZmRjbTFhbnczZmxib3h1OW05YXYifQ.PhlKv60ar3K359d8x2yBPw", // "pk.eyJ1Ijoic2hhcmVhbGV4IiwiYSI6ImNsaXNhZmRjbTFhbnczZmxib3h1OW05YXYifQ.PhlKv60ar3K359d8x2yBPw",
tilesize: 256, // tilesize: 256,
scaleFactor: false, // scaleFactor: false,
show: true, // show: false,
}, // },
], ],
}, },
show: false, show: false,
@ -96,60 +114,42 @@ export default {
mounted() { mounted() {
// mounted // mounted
document.addEventListener("click", this.handleClickOutside); document.addEventListener("click", this.handleClickOutside);
this.getCarList();
}, },
methods: { methods: {
async getCarList() { async getCarPoint() {
let res = await getCarList(); this.list = await this.carPoint();
// console.log(res, "ss"); this.createCar();
}, },
async getlogin() { async carPoint() {
const data = { let res = await getCarPoint({
userId: "99999", // carIds: "23,78",
password: "6d0fd76ab81325588d8065ec1036fdd3", });
loginType: "user", res.list = res.list.filter(
}; (item) =>
let res = await lgoin(); item.carPlate.includes("苏E") ||
console.log(res, "登录数据"); (item.carPlate.includes("苏U") && item.stateCn.includes("在线-行驶"))
}, );
return res.list.slice(0, 100);
//
getCarLocation() {
this.createCar(carJSON.list);
}, },
/** /**
* 创建车辆图标 * 创建车辆图标
*/ */
createCar(list) { createCar() {
let _this = this; this.graphicLayer.clear();
list.map((item, index) => { this.graphicLayer.enabledEvent = false; // addGraphic
//
for (let i = 0; i < this.list.length; i++) {
let item = this.list[i];
const graphic = new mars3d.graphic.ModelPrimitive({ const graphic = new mars3d.graphic.ModelPrimitive({
id: `car${item.carId}`, id: item.carId,
position: [parseFloat(item.lng), parseFloat(item.lat)],
style: { style: {
heading: parseInt(item.drct), // heading: parseInt(item.drct),
//url: _this.carUrl, url: this.carUrl,
url: "//data.mars3d.cn/gltf/imap/ce2fddca7bac436d8d318bcd4fdf2d69/gltf/gltf2.gltf", scale: 3,
scale: 1, minimumPixelSize: 20,
minimumPixelSize: 40,
silhouette: true,
silhouetteColor: "#025CC1",
silhouetteSize: 2,
// type:'click'openHighlightcloseHighlight
highlight: {
type: mars3d.EventType.click,
silhouette: true,
silhouetteColor: "#FAAC51",
silhouetteSize: 2,
label: {
outlineColor: "#FAAC51",
},
},
label: { label: {
// label
text: item.carName, text: item.carName,
font_size: 14, font_size: 14,
color: "#ffffff", color: "#ffffff",
@ -160,68 +160,66 @@ export default {
distanceDisplayCondition_far: 50000, distanceDisplayCondition_far: 50000,
distanceDisplayCondition_near: 0, distanceDisplayCondition_near: 0,
}, },
clampToGround: true,
}, },
// forwardExtrapolationType: Cesium.ExtrapolationType.NONE, // frameRateHeight: 30, //
attr: { index: index, remark: "Model示例" },
}); });
graphic.on(mars3d.EventType.click, function (e) {
_this.$router.push({ path: "/carInfo" });
});
this.graphicLayer.addGraphic(graphic); this.graphicLayer.addGraphic(graphic);
}); this.graphicLayer.enabledEvent = true; //
// graphic.bindHighlight({
// type: mars3d.EventType.click,
// silhouette: true,
// silhouetteColor: "#FAAC51",
// silhouetteSize: 2,
// label: {
// outlineColor: "#FAAC51",
// },
// });
// graphic.on(mars3d.EventType.click, function (e) {
// _this.$router.push({ path: "/carInfo" });
// });
}
this.changePosition(0);
// setInterval
const interval = 10;
this.changePosition(interval);
this.time = setInterval(() => {
this.changePosition(interval);
}, interval * 1000);
}, },
/** //
* 生成车辆实时点位 async changePosition(interval) {
*/ let list = await this.carPoint();
// createCar(list) { this.graphicLayer.eachGraphic((graphic) => {
// let _this = this; for (let i = 0; i < list.length; i++) {
// console.log(list); let item = list[i];
// for (let i = 0; i < list.length; i++) { if (graphic.id == item.carId) {
// let item = list[i]; // graphic.setOptions({
// style: {
// const graphic = new mars3d.graphic.DivGraphic({ // heading: parseInt(item.drct),
// id: "car" + i, // },
// position: [parseFloat(item.lng), parseFloat(item.lat)], // });
// style: { let position = Cesium.Cartesian3.fromDegrees(
// className: `carIcon`, parseFloat(item.lng),
// html: `<div> parseFloat(item.lat),
// <div class="car-name">${item.carName}</div> 30
// </div>`, );
// color: "#fff", graphic.addDynamicPosition(position, interval); // time
// horizontalOrigin: Cesium.HorizontalOrigin.CENTER, // }
// verticalOrigin: Cesium.VerticalOrigin.BOTTOM, }
// distanceDisplayCondition: false, });
// clampToGround: true, },
// highlight: {
// type: "click",
// className: `carIconActive`,
// },
// },
// attr: {
// index: i,
// id: "car" + i,
// },
// });
// graphic.on(mars3d.EventType.highlightOpen, function (event) {
// _this.$router.push("/carInfo");
// });
// this.graphicLayer.addGraphic(graphic);
// }
// // this.changePosition(0); //
randomPoint() {
const jd = this.random(117.207666 * 1000, 117.287241 * 1000) / 1000;
const wd = this.random(31.817099 * 1000, 31.876848 * 1000) / 1000;
return Cesium.Cartesian3.fromDegrees(jd, wd, 30);
},
// // setInterval random(min, max) {
// // const interval = 30; return Math.floor(Math.random() * (max - min + 1) + min);
// // this.changePosition(interval); },
// // this.timer = setInterval(() => {
// // _this.changePosition(interval);
// // }, interval * 1000);
// },
handleClickOutside(event) { handleClickOutside(event) {
// //
@ -248,27 +246,8 @@ export default {
this.map = map; this.map = map;
this.graphicLayer = new mars3d.layer.GraphicLayer(); this.graphicLayer = new mars3d.layer.GraphicLayer();
map.addLayer(this.graphicLayer); map.addLayer(this.graphicLayer);
this.initTilesetLayer(); // this.initTilesetLayer();
}, // this.getCarPoint();
//
changePosition(time) {
let _this = this;
this.graphicLayer.eachGraphic((graphic) => {
if (graphic.isPrivate) {
return;
}
graphic.addDynamicPosition(_this.randomPoint(), time); // time
});
},
//
randomPoint() {
const jd = this.random(120.5265 * 1000, 120.7177 * 1000) / 1000;
const wd = this.random(31.2783 * 1000, 31.4647 * 1000) / 1000;
return Cesium.Cartesian3.fromDegrees(jd, wd);
},
random(min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}, },
/** /**

Loading…
Cancel
Save