问题
1.期望 实现 实时显示经纬度、⾼度,做电⼦围栏报警判断
2.第⼀步就是要,获取实时运⾏的经纬度信息、⾼度信息,然后通过算法做电⼦围栏判断
3.使⽤了参数getOverPositions,发现返回的不是经纬度
相关链接
http://mars3d.cn//editor-vue.html?id=graphic/roam/dynamicRoamLine
代码
import * as mars3d from "mars3d"
export let map // mars3d.Map三维地图对象
export let graphicLayer // ⽮量图层对象
// 需要覆盖config.json中地图属性参数(当前示例框架中⾃动处理合并)
export const mapOptions = {
scene: {
center: { lat: 31.773622, lng: 117.077444, alt: 5441, heading: 359, p
itch: -57 }
}
}
export const eventTarget = new mars3d.BaseClass()
/**
* 初始化地图业务,⽣命周期钩⼦函数(必须)
* 框架在地图初始化完成后⾃动调⽤该函数
* @param {mars3d.Map} mapInstance 地图对象
* @returns {void} ⽆
*/
export function onMounted(mapInstance) {
map = mapInstance // 记录map
// 演示数据的时间
map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2020-11-2
5 10:10:00"))
// 加载⻋辆
mars3d.Util.fetchJson({
url: "//data.mars3d.cn/file/apidemo/car-list.json"
})
.then(function (res) {
const tableData = res.data
eventTarget.fire("carList", { tableData })
showCarList(tableData)
})
.catch(function () {
globalMsg("查询信息失败")
})
}
/**
* 释放当前地图业务的⽣命周期函数
* @returns {void} ⽆
*/
export function onUnmounted() {
map = null
}
const colors = [
"rgb(40, 40, 255)",
"rgb(0, 88, 176)",
"rgb(0, 128, 255)",
"rgb(0, 217, 0)",
"rgb(0, 151, 0)",
"rgb(255, 199, 83)",
"rgb(255, 144, 30)",
"rgb(202, 101, 0)",
"rgb(255, 0, 0)"
]
function showCarList(arr) {
console.log("加载" + arr.length + "条")
// 创建⽮量数据图层
graphicLayer = new mars3d.layer.GraphicLayer()
map.addLayer(graphicLayer)
// ⿏标移⼊提示信息
graphicLayer.bindTooltip(function (event) {
const data = event.graphic.options
return "⻋辆编号:" + data.id + "<br />⻋牌号码:" + data.name
})
// 单击地图空⽩处
map.on(mars3d.EventType.clickMap, function (event) {
if (lastClickCar) {
lastClickCar.removeShading("circle")
lastClickCar = null
}
})
// 绑定点击事件
graphicLayer.on(mars3d.EventType.click, (event, position) => {
const car = event.graphic
console.log("单击了⻋辆", car)
if (lastClickCar) {
if (lastClickCar === car) {
return
} // 重复单击,跳出
lastClickCar.removeShading("circle")
lastClickCar = null
}
car.addShading({
type: "circle",
materialType: mars3d.MaterialType.CircleWave,
speed: 10,
count: 3,
gradient: 0.1,
radius: 50,
color: "#ffff00",
opacity: 0.3,
show: true
})
lastClickCar = car
// 视⻆定位下
// car.flyToPoint({ radius: 1000 })
})
let lastClickCar
for (let i = 0; i < arr.length; i++) {
const item = arr[i]
item.show = true
let modelParam
switch (item.type) {
case 1:
modelParam = {
scale: 2,
url: "//data.mars3d.cn/gltf/mars/car/tufangche.glb"
}
break
case 2:
modelParam = {
scale: 1,
url: "//data.mars3d.cn/gltf/mars/car/wajueji.glb"
}
break
default:
}
const car = new mars3d.graphic.DynamicRoamLine({
id: item.id,
name: item.name,
model: {
clampToGround: true,
show: true,
...modelParam
},
shadow: [
{
type: "polyline",
color: colors[i],
width: 2,
clampToGround: true,
maxDistance: 500,
show: true
}
]
})
car.on(mars3d.EventType.change, (event) => {
console.log(event);
})
graphicLayer.addGraphic(car)
}
// 定时获取卡⻋和铲⻋的列表数据
createPath()
}
// 取轨迹数据的时间间隔(单位:秒)
const timeStep = 10
let lastTime
// ⾸次获取并创建轨迹
function createPath() {
// 取数据的时间范围,结束时间
const date = Cesium.JulianDate.toDate(map.clock.currentTime)
const endTime = mars3d.Util.formatDate(date, "yyyy-MM-dd HH:mm:ss")
// 修改当前时间回退⼀分钟,因为数据永远是当前时间之前的。
date.setSeconds(date.getSeconds() - 60)
map.clock.currentTime = window.Cesium.JulianDate.fromDate(date)
// 取数据的时间范围,开始时间
date.setMinutes(date.getMinutes() - 10) // 初次取⼀定时间内的数据
const beginTime = mars3d.Util.formatDate(date, "yyyy-MM-dd HH:mm:ss")
// 记录最后⼀次读取数据的时间
lastTime = endTime
// 取数据
getPathList(beginTime, endTime)
解决⽅案: change事件中可以拿到position属性
issue: https://gitee.com/marsgis/mars3d/issues/I5CCL8?from=project-issue
// 定时更新
setInterval(() => {
updatePath()
}, timeStep * 1000)
}
export let map // mars3d.Map三维地图对象
export let graphicLayer // ⽮量图层对象
// 需要覆盖config.json中地图属性参数(当前示例框架中⾃动处理合并)
export const mapOptions = {
scene: {
center: { lat: 31.773622, lng: 117.077444, alt: 5441, heading: 359, p
itch: -57 }
}
}
export const eventTarget = new mars3d.BaseClass()
/**
* 初始化地图业务,⽣命周期钩⼦函数(必须)
* 框架在地图初始化完成后⾃动调⽤该函数
* @param {mars3d.Map} mapInstance 地图对象
* @returns {void} ⽆
*/
export function onMounted(mapInstance) {
map = mapInstance // 记录map
// 演示数据的时间
map.clock.currentTime = Cesium.JulianDate.fromDate(new Date("2020-11-2
5 10:10:00"))
// 加载⻋辆
mars3d.Util.fetchJson({
url: "//data.mars3d.cn/file/apidemo/car-list.json"
})
.then(function (res) {
const tableData = res.data
eventTarget.fire("carList", { tableData })
showCarList(tableData)
})
.catch(function () {
globalMsg("查询信息失败")
})
}
/**
* 释放当前地图业务的⽣命周期函数
* @returns {void} ⽆
*/
export function onUnmounted() {
map = null
}
const colors = [
"rgb(40, 40, 255)",
"rgb(0, 88, 176)",
"rgb(0, 128, 255)",
"rgb(0, 217, 0)",
"rgb(0, 151, 0)",
"rgb(255, 199, 83)",
"rgb(255, 144, 30)",
"rgb(202, 101, 0)",
"rgb(255, 0, 0)"
]
function showCarList(arr) {
console.log("加载" + arr.length + "条")
// 创建⽮量数据图层
graphicLayer = new mars3d.layer.GraphicLayer()
map.addLayer(graphicLayer)
// ⿏标移⼊提示信息
graphicLayer.bindTooltip(function (event) {
const data = event.graphic.options
return "⻋辆编号:" + data.id + "<br />⻋牌号码:" + data.name
})
// 单击地图空⽩处
map.on(mars3d.EventType.clickMap, function (event) {
if (lastClickCar) {
lastClickCar.removeShading("circle")
lastClickCar = null
}
})
// 绑定点击事件
graphicLayer.on(mars3d.EventType.click, (event, position) => {
const car = event.graphic
console.log("单击了⻋辆", car)
if (lastClickCar) {
if (lastClickCar === car) {
return
} // 重复单击,跳出
lastClickCar.removeShading("circle")
lastClickCar = null
}
car.addShading({
type: "circle",
materialType: mars3d.MaterialType.CircleWave,
speed: 10,
count: 3,
gradient: 0.1,
radius: 50,
color: "#ffff00",
opacity: 0.3,
show: true
})
lastClickCar = car
// 视⻆定位下
// car.flyToPoint({ radius: 1000 })
})
let lastClickCar
for (let i = 0; i < arr.length; i++) {
const item = arr[i]
item.show = true
let modelParam
switch (item.type) {
case 1:
modelParam = {
scale: 2,
url: "//data.mars3d.cn/gltf/mars/car/tufangche.glb"
}
break
case 2:
modelParam = {
scale: 1,
url: "//data.mars3d.cn/gltf/mars/car/wajueji.glb"
}
break
default:
}
const car = new mars3d.graphic.DynamicRoamLine({
id: item.id,
name: item.name,
model: {
clampToGround: true,
show: true,
...modelParam
},
shadow: [
{
type: "polyline",
color: colors[i],
width: 2,
clampToGround: true,
maxDistance: 500,
show: true
}
]
})
car.on(mars3d.EventType.change, (event) => {
console.log(event);
})
graphicLayer.addGraphic(car)
}
// 定时获取卡⻋和铲⻋的列表数据
createPath()
}
// 取轨迹数据的时间间隔(单位:秒)
const timeStep = 10
let lastTime
// ⾸次获取并创建轨迹
function createPath() {
// 取数据的时间范围,结束时间
const date = Cesium.JulianDate.toDate(map.clock.currentTime)
const endTime = mars3d.Util.formatDate(date, "yyyy-MM-dd HH:mm:ss")
// 修改当前时间回退⼀分钟,因为数据永远是当前时间之前的。
date.setSeconds(date.getSeconds() - 60)
map.clock.currentTime = window.Cesium.JulianDate.fromDate(date)
// 取数据的时间范围,开始时间
date.setMinutes(date.getMinutes() - 10) // 初次取⼀定时间内的数据
const beginTime = mars3d.Util.formatDate(date, "yyyy-MM-dd HH:mm:ss")
// 记录最后⼀次读取数据的时间
lastTime = endTime
// 取数据
getPathList(beginTime, endTime)
解决⽅案: change事件中可以拿到position属性
issue: https://gitee.com/marsgis/mars3d/issues/I5CCL8?from=project-issue
// 定时更新
setInterval(() => {
updatePath()
}, timeStep * 1000)
}
解决⽅案:
change事件中可以拿到position属性
issue:
https://gitee.com/marsgis/mars3d/issues/I5CCL8?from=project-issue