Commit 938daa57 by 前端

修改区域查车交互

1 parent cb472f67

19.4 KB | W: | H:

515 Bytes | W: | H:

src/assets/images/icon_car.png
src/assets/images/icon_car.png
src/assets/images/icon_car.png
src/assets/images/icon_car.png
  • 2-up
  • Swipe
  • Onion skin
<template>
<v-full-layout ref="vFullLayout">
<template slot="main">
<div
ref="map"
id="map"
class="map-container"
v-loading="mapLoading"
></div>
<div class="row_box_hide" v-if="hideRowBox" @click="onShow">
<glsx-image src="car.png" class="img img_normal" />
<glsx-image src="car_hover.png" class="img img_hover" />
<!-- <img src="@/assets/images/car.png" class="img img_normal" alt="" />
<img src="@/assets/images/car_hover.png" class="img img_hover" alt="" /> -->
</div>
<div class="row_box" v-else>
<div class="hide_icon" @click="onShow">
<!-- <img src="@/assets/images/hide.png" class="img" alt="" /> -->
<glsx-image src="hide.png" class="img" />
</div>
<div class="row_head">
<div
class="cell"
:class="menuId == item.id ? 'active' : ''"
v-for="(item, index) in menus"
:key="`menu_${index}`"
@click="menuEvent(item)"
>
{{ item.name }}
</div>
</div>
<div class="row_content">
<el-form
ref="form"
:model="form"
class="el_form"
label-position="top"
>
<div v-show="menuId == 1">
<el-form-item label="行政区域">
<CitySelect
ref="citySelect"
v-model="form.area"
class="el_select"
@change="onChange"
/>
</el-form-item>
<el-form-item label="详细地址">
<el-input v-model="form.address" placeholder="请输入详细地址" />
</el-form-item>
</div>
<div v-show="menuId == 2">
<el-form-item label="设备号">
<div class="device_label" slot="label">
<span>设备号</span>
<el-tooltip
content="请先设备号精准搜索设备定位后,再进行“选择区域”操作"
placement="top"
>
<i class="el-icon-warning-outline"></i>
</el-tooltip>
</div>
<div class="device_item">
<el-input
v-model="form.sn"
placeholder="请输入您要查询的设备号"
/>
<el-button
type="primary"
class="btn"
:disabled="!form.sn"
@click="getLocation"
>搜索</el-button
>
</div>
</el-form-item>
</div>
<el-form-item label="">
<div>
<el-button class="area_btn" @click="chooseArea"
>选择区域</el-button
>
<span class="clear_link" @click="onClear">清除</span>
</div>
</el-form-item>
<div class="tips_info">
<span
>长度:<i>{{ rectangleWidth || "--" }}</i
>m</span
>
<span
>宽度:<i>{{ rectangleHeight || "--" }}</i
>m</span
>
</div>
<div class="btn_group">
<el-button
type="primary"
class="search_btn"
:loading="loading"
:disabled="!rectangle"
@click="getAreaLocation"
>查询</el-button
>
</div>
</el-form>
</div>
</div>
<!-- 底部 开始 -->
<div class="bottom_list_hide" v-if="hideFooter" @click="onHide">
<i class="el-icon-arrow-up"></i>
<span>显示</span>
</div>
<div class="bottom_list" :style="`height:${bHeight}px;`" v-else>
<div class="head">
<div class="left">
<span>已查询到设备共计</span>
<span class="cred">{{ deviceList.length }}</span>
<span>条</span>
<el-button
class="btn"
:loading="dloading"
:disabled="!deviceList || deviceList.length <= 0"
@click="downloadExcel"
>导出</el-button
>
</div>
<div class="right">
<a href="javascript:void(0)" class="link" @click="unfold">展开</a>
<a href="javascript:void(0)" class="link" @click="packUp">收起</a>
<a href="javascript:void(0)" class="link" @click="onHide">隐藏</a>
</div>
</div>
<div class="content">
<!-- <vxe-grid
:columns="columns"
ref="xGrid"
max-height="100%"
:data="deviceList"
size="small"
show-overflow
v-if="drawDone"
>
</vxe-grid> -->
<!-- <el-table :data="deviceList" size="small">
<el-table-column
label="业务工单号"
prop="workOrderNo"
show-overflow-tooltip
/>
<el-table-column
label="店面名称"
prop="shopName"
show-overflow-tooltip
/>
<el-table-column
label="姓名"
prop="ownerName"
show-overflow-tooltip
/>
<el-table-column label="车架号" prop="vin" show-overflow-tooltip />
<el-table-column label="设备号" prop="sn" show-overflow-tooltip />
<el-table-column
label="激活时间"
prop="activeDate"
show-overflow-tooltip
/>
<el-table-column
label="设备类型"
prop="deviceTypeStr"
show-overflow-tooltip
/>
<el-table-column
label="最后GPS定位时间"
prop="finalGpsTime"
show-overflow-tooltip
/>
</el-table> -->
</div>
</div>
<!-- 底部 end -->
</template>
</v-full-layout>
</template>
<script>
import mapService from "@/utils/mapService.js";
import "@/utils/mapEvent.js";
import AMapLoader from "@amap/amap-jsapi-loader";
import { CONSTANT } from "@/constant";
import CitySelect from "@/components/area";
import {
GER_REGIONAL_SEARCH,
GER_REGIONAL_EXPORT,
} from "@/api/services/zooneCar";
import { GET_DEVICEINFO_BYSNS } from "@/api/services/monitor";
import EventBus from "@/event-bus";
import { showToast, deepClone } from "@/utils/utils.js";
import moment from "moment";
export default {
components: {
CitySelect,
},
data() {
return {
menus: [
{ name: "区域查车", id: 1 },
{ name: "设备号查车", id: 2 },
],
menuId: 1,
map: null,
mapLoading: true,
form: {},
rectangle: null,
rectangleEditor: null,
rectangleWidth: 0, // 矩形宽度
rectangleHeight: 0, // 矩形高度
bHeight: 313,
hInterval: null,
hideRowBox: false,
hideFooter: true,
//rectangleInfo:{}, // 矩形坐标点信息
deviceList: [],
loading: false,
dloading: false,
autoOpenLastInfoWindow: false,
columns: [
{ type: "seq", title: "序号", width: "55px" },
{ field: "workOrderNo", title: "业务工单号" },
{ field: "shopName", title: "店面名称" },
{ field: "ownerName", title: "姓名" },
{ field: "vin", title: "车架号" },
{ field: "sn", title: "设备号" },
{ field: "activeDate", title: "激活时间" },
{ field: "deviceTypeStr", title: "设备类型" },
{ field: "finalGpsTime", title: "最后GPS定位时间" },
{ field: "finalGpsAddress", title: "最后GPS定位地址", width: "300px" },
],
drawDone: false,
location: {}, // 设备维度查询的位置点
};
},
mounted() {
this.initMap();
},
methods: {
// 地图初始化
initMap() {
let _this = this;
let plugins = CONSTANT.MAP_PLUGINS.concat([
"AMap.LngLat",
"AMap.Rectangle",
"AMap.RectangleEditor",
"AMap.LabelsLayer",
"AMap.LabelMarker",
]);
if (window.AMap) {
window.AMap = null;
}
AMapLoader.reset();
AMapLoader.load({
key: CONSTANT.MAP_KEY, // 申请好的Web端开发者Key,首次调用 load 时必填
version: "2.0", // 指定要加载的 JSAPI 的版本,缺省时默认为 1.4.15
plugins: plugins, // 需要使用的的插件列表,如比例尺'AMap.Scale'等
})
.then((AMap) => {
_this.mapLoading = false;
window.AMap = AMap;
_this.map = mapService.init("map");
})
.catch((error) => {
console.log(error);
window.location.reload();
});
},
// 画矩形
drawRectangle(lnglat) {
let _this = this;
let lng = lnglat.southWest.lng;
let lat = lnglat.southWest.lat;
let nlng = lnglat.northEast.lng;
let nlat = lnglat.northEast.lat;
let southWest = new AMap.LngLat(lng, lat);
let northEast = new AMap.LngLat(nlng, nlat);
let rectangle = this.rectangle;
let rectangleEditor = this.rectangleEditor;
// if (rectangle || rectangleEditor) {
// //rectangleEditor.close();
// // this.map.remove([rectangle, rectangleEditor]);
// this.clearMap();
// }
this.clearMap();
let bounds = new AMap.Bounds(southWest, northEast);
rectangle = new AMap.Rectangle({
bounds: bounds,
strokeColor: "#f00",
strokeWeight: 3,
strokeOpacity: 1,
strokeDasharray: [30, 10],
// strokeStyle还支持 solid
strokeStyle: "dashed",
fillColor: "blue",
fillOpacity: 0.2,
cursor: "pointer",
zIndex: 50,
});
rectangleEditor = new AMap.RectangleEditor(this.map, rectangle);
rectangleEditor.open();
rectangleEditor.on("adjust", function (event) {
_this.calculateWidthHeight(event.bounds);
});
this.map.add(rectangle);
this.map.setFitView(rectangle);
// rectangle.on("dragend", function (event) {
// console.log("拖动:", event);
// });
this.rectangleEditor = rectangleEditor;
this.rectangle = rectangle;
this.rectangleHeight = 500;
this.rectangleWidth = 500;
this.map.setZooms([12, 30]);
},
/**
* 计算对应点的位置
* lng:中心点经度 lat:中心点维度 距离默认500m
* 垂直距离lath(所求点在已知点上方(北方)为正,否则为负)
* 水平距离longw(所求点在已知点右方(东方)为正,否则为负)
* lat = latitude + lath / (ARC * math.pi / 180);
* lng = longitude + longw / (ARC * math.cos(latitude) * math.pi / 180);
*/
getLngLat(lng, lat, w) {
let ARC = 6371.393 * 1000;
let pi = Math.PI;
let num = w ? w / 2 : 500 / 2;
// 中心点-左边点的经纬度
let leftLng = lng - num / ((ARC * Math.cos(lat) * pi) / 180);
// let leftLat = lat;
// 中心点-下边点的经纬度
// let bottomLng = lng;
let bottomLat = lat - num / ((ARC * pi) / 180);
// 中心点-右边点经纬度
let rightLng = lng + num / ((ARC * Math.cos(lat) * pi) / 180);
// let rightLat = lat;
// 中心点-上边点经纬度
// let topLng = lng;
let topLat = lat + num / ((ARC * pi) / 180);
// 左下角 经纬度 leftLng bottomLat
let southWest = { lng: leftLng, lat: bottomLat };
// 右上角 经纬度 rightLng topLat
let northEast = { lng: rightLng, lat: topLat };
let lnglats = { southWest, northEast };
return lnglats;
},
// 第二种算法
/**
* 距离dis的单位是米(默认500M),deg是方位角,需要化为弧度。lon1,lat1是起始点经纬度信息
* 左侧开始,角度0,逆时针方向360度
* long1 + dis*math.sin(deg)/(arc*math.cos(lati1)*2*math.pi/360)
* lati1 + dis*math.cos(deg)/(arc*2*math.pi/360)
*/
getLngLat2(lng, lat, w) {
let arc = 6371.393 * 1000;
let pi = Math.PI;
let num = w ? w / 2 : 500 / 2;
// 中心点-左边点的经纬度
let leftLng = lng + (num * Math.sin(180)) / ((arc * Math.cos(lat) * 2 * pi) / 360);
// let leftLat = lat;
// 中心点-下边点的经纬度
// let bottomLng = lng;
let bottomLat = lat + (num * Math.cos(270)) / ((arc * 2 * pi) / 360);
// 中心点-右边点经纬度
let rightLng =
lng + (num * Math.sin(0)) / ((arc * Math.cos(lat) * 2 * pi) / 360);
// let rightLat = lat;
// 中心点-上边点经纬度
// let topLng = lng;
let topLat = lat + (num * Math.cos(90)) / ((arc * 2 * pi) / 360);
// 左下角 经纬度 leftLng bottomLat
let southWest = { lng: leftLng, lat: bottomLat };
// 右上角 经纬度 rightLng topLat
let northEast = { lng: rightLng, lat: topLat };
let lnglats = { southWest, northEast };
return lnglats;
},
// 根据地址获取经纬度
getAddressLngLat(address) {
return new Promise((resolve) => {
AMap.plugin("AMap.Geocoder", function () {
var geocoder = new AMap.Geocoder();
geocoder.getLocation(address, function (status, result) {
resolve({ status, result });
});
});
});
},
// 选择区域
async chooseArea() {
let _type = this.menuId;
let o = this.form;
let location = {};
if (_type == 1) {
let address = `${o.name || ""}${o.address || ""}`;
let { status, result } = await this.getAddressLngLat(address);
if (status === "complete" && result.info === "OK") {
// 以解析出来经纬度为中心点来画矩形
let arr = result.geocodes ? result.geocodes : [];
location = arr[0] ? arr[0].location : {};
}
} else {
location = this.location;
}
// 如果location 不存在,则以地图中心点来画矩形
if (!location.lng || !location.lat) {
location = this.map.getCenter();
}
console.log(location);
let lnglats = this.getLngLat(location.lng, location.lat);
console.log(lnglats)
console.log(this.getLngLat2(location.lng, location.lat))
this.drawRectangle(lnglats);
},
// 计算矩形宽度、高度
calculateWidthHeight(lnglats) {
if (!lnglats) {
return {};
}
// 左下角点坐标
let southWest = lnglats.southWest || {};
// 右上角点坐标
let northEast = lnglats.northEast || {};
// 计算高度
let _height = AMap.GeometryUtil.distance(
[southWest.lng, southWest.lat],
[southWest.lng, northEast.lat]
);
// 计算宽度
let _width = AMap.GeometryUtil.distance(
[southWest.lng, southWest.lat],
[northEast.lng, southWest.lat]
);
this.rectangleHeight = _height.toFixed(0);
this.rectangleWidth = _width.toFixed(0);
},
// 清空地图覆盖物
clearMap() {
let rectangle = this.rectangle;
let rectangleEditor = this.rectangleEditor;
if (rectangle || rectangleEditor) {
rectangleEditor.close();
}
if (this.map) {
this.map.clearMap();
}
this.rectangleHeight = 0;
this.rectangleWidth = 0;
this.rectangle = null;
this.rectangleEditor = null;
this.map.setZooms([2, 30]);
},
// 清空筛选条件
onClear() {
this.clearMap();
this.rectangleHeight = 0;
this.rectangleWidth = 0;
this.form = {};
this.deviceList = [];
this.$refs.citySelect.reset();
},
// 展开
unfold() {
let _this = this;
let h = this.bHeight;
let m = Number(this.$refs.map.offsetHeight);
let max = (m * 0.8).toFixed(0);
if (_this.hInterval) {
clearInterval(_this.hInterval);
}
_this.hInterval = setInterval(function () {
if (h >= max) {
clearInterval(_this.hInterval);
return false;
}
h += 30;
_this.bHeight = h;
}, 10);
},
// 收起
packUp() {
let _this = this;
let min = 313;
if (_this.hInterval) {
clearInterval(_this.hInterval);
}
_this.hInterval = setInterval(function () {
let h = _this.bHeight;
if (h <= min) {
clearInterval(_this.hInterval);
return false;
}
h -= 30;
_this.bHeight = h;
}, 10);
},
// 隐藏
onHide() {
this.hideFooter = !this.hideFooter;
},
// 展开
onShow() {
this.hideRowBox = !this.hideRowBox;
},
// 添加位置点
addLocation(row, showInfoWindow) {
let drawData = row;
EventBus.$emit("uiMap.monitor.drawMaker", drawData, showInfoWindow);
},
// 获取参数
getParams() {
if (!this.rectangle) {
return {};
}
let params = {};
let o = this.rectangle.getOptions();
let bounds = o.bounds || {};
params.leftLngLat = `${bounds.southWest.lng},${bounds.southWest.lat}`;
params.rightLngLat = `${bounds.northEast.lng},${bounds.northEast.lat}`;
return params;
},
// 导出excel
async downloadExcel() {
let params = this.getParams();
this.dloading = true;
let res = await GER_REGIONAL_EXPORT(params);
this.dloading = false;
if (res.code != 200) {
showToast({
message: res.message,
});
return false;
}
if (res.data) {
window.location.href = res.data;
}
},
// 监听地区选择
onChange(e) {
console.log(e);
let code = e.code;
let o = e.name;
let str = o[0] + o[1] + o[2];
this.$set(this.form, "name", str);
this.drawDistrict(code);
},
// 切换类型
menuEvent(row) {
this.menuId = row.id;
},
// 设备号查车
async getLocation() {
let params = {};
this.clearMap();
params.sns = this.form.sn;
params.deviceCode = "gps";
let res = await GET_DEVICEINFO_BYSNS(params);
let list = res.data || [];
if (list.length <= 0) {
showToast({
message: "暂无车辆",
});
return false;
}
let arr = [];
list.forEach((item) => {
let o = deepClone(item || {});
let m = o.gpsLocation || {};
o.lng = m.elng;
o.lat = m.elat;
o.address = m.address;
o.type = 2;
o.time = m.dateTime;
o.standNo = item.standNo || item.vin;
o.isSource = item.source;
arr.push(o);
// this.autoOpenLastInfoWindow = true;
// if (this.autoOpenLastInfoWindow) {
// this.autoOpenLastInfoWindow = false;
// }
//this.addLocation(o, this.autoOpenLastInfoWindow);
this.location = o;
});
this.addMarkers(arr);
},
// 区域查车
async getAreaLocation() {
let _this = this;
let params = this.getParams();
if (!_this.rectangle) {
showToast({
message: "请先划定区域",
});
return false;
}
_this.loading = true;
let res = await GER_REGIONAL_SEARCH(params);
_this.loading = false;
if (res.code != 200) {
showToast({
message: res.message,
});
return false;
}
let list = res.data || [];
_this.deviceList = list;
_this.hideFooter = false;
_this.addMarkers(list);
},
// 在地图上画行政区域
drawDistrict(areaCode) {
EventBus.$emit("uiMap.fence.drawDistrict", areaCode);
},
// 添加海量点
addMarkers(arr) {
console.log(arr);
let _this = this;
let markers = [];
let icon = {
type: "image",
image: require("images/icon_car.png"),
size: [24, 15],
anchor: "bottom-center",
};
this.drawDone = false;
var layer = new AMap.LabelsLayer({
zooms: [0, 20],
zIndex: 1000,
collision: false,
});
this.map.add(layer);
for (let i = 0, len = arr.length; i < len; i++) {
let k = arr[i];
let curData = {
position: [k.lng, k.lat],
icon,
//extData: k,
};
let labelMarker = new AMap.LabelMarker(curData);
labelMarker.on("click", function (e) {
console.log(labelMarker.getExtData());
let _position = labelMarker.getExtData();
let infoWindow = mapService.createAraeInfowindow(_position);
infoWindow.open(_this.map);
});
markers.push(labelMarker);
}
layer.add(markers);
console.log("画点结束", new Date().getTime());
this.drawDone = true;
this.map.setFitView();
},
},
};
</script>
<style lang="scss" scoped>
@import "../../assets/scss/zoneCar.scss";
</style>
\ No newline at end of file \ No newline at end of file
...@@ -10,12 +10,9 @@ ...@@ -10,12 +10,9 @@
<div class="row_box_hide" v-if="hideRowBox" @click="onShow"> <div class="row_box_hide" v-if="hideRowBox" @click="onShow">
<glsx-image src="car.png" class="img img_normal" /> <glsx-image src="car.png" class="img img_normal" />
<glsx-image src="car_hover.png" class="img img_hover" /> <glsx-image src="car_hover.png" class="img img_hover" />
<!-- <img src="@/assets/images/car.png" class="img img_normal" alt="" />
<img src="@/assets/images/car_hover.png" class="img img_hover" alt="" /> -->
</div> </div>
<div class="row_box" v-else> <div class="row_box" v-else>
<div class="hide_icon" @click="onShow"> <div class="hide_icon" @click="onShow">
<!-- <img src="@/assets/images/hide.png" class="img" alt="" /> -->
<glsx-image src="hide.png" class="img" /> <glsx-image src="hide.png" class="img" />
</div> </div>
<div class="row_head"> <div class="row_head">
...@@ -37,16 +34,12 @@ ...@@ -37,16 +34,12 @@
label-position="top" label-position="top"
> >
<div v-show="menuId == 1"> <div v-show="menuId == 1">
<el-form-item label="行政区域">
<CitySelect
ref="citySelect"
v-model="form.area"
class="el_select"
@change="onChange"
/>
</el-form-item>
<el-form-item label="详细地址"> <el-form-item label="详细地址">
<el-input v-model="form.address" placeholder="请输入详细地址" /> <el-input
v-model="form.address"
id="tipInput"
placeholder="请输入详细地址"
/>
</el-form-item> </el-form-item>
</div> </div>
<div v-show="menuId == 2"> <div v-show="menuId == 2">
...@@ -78,7 +71,7 @@ ...@@ -78,7 +71,7 @@
<el-form-item label=""> <el-form-item label="">
<div> <div>
<el-button class="area_btn" @click="chooseArea" <el-button class="area_btn" @click="chooseArea"
>选择区域</el-button >划定区域</el-button
> >
<span class="clear_link" @click="onClear">清除</span> <span class="clear_link" @click="onClear">清除</span>
</div> </div>
...@@ -143,40 +136,6 @@ ...@@ -143,40 +136,6 @@
v-if="drawDone" v-if="drawDone"
> >
</vxe-grid> </vxe-grid>
<!-- <el-table :data="deviceList" size="small">
<el-table-column
label="业务工单号"
prop="workOrderNo"
show-overflow-tooltip
/>
<el-table-column
label="店面名称"
prop="shopName"
show-overflow-tooltip
/>
<el-table-column
label="姓名"
prop="ownerName"
show-overflow-tooltip
/>
<el-table-column label="车架号" prop="vin" show-overflow-tooltip />
<el-table-column label="设备号" prop="sn" show-overflow-tooltip />
<el-table-column
label="激活时间"
prop="activeDate"
show-overflow-tooltip
/>
<el-table-column
label="设备类型"
prop="deviceTypeStr"
show-overflow-tooltip
/>
<el-table-column
label="最后GPS定位时间"
prop="finalGpsTime"
show-overflow-tooltip
/>
</el-table> -->
</div> </div>
</div> </div>
<!-- 底部 end --> <!-- 底部 end -->
...@@ -237,7 +196,8 @@ export default { ...@@ -237,7 +196,8 @@ export default {
{ field: "finalGpsAddress", title: "最后GPS定位地址", width: "300px" }, { field: "finalGpsAddress", title: "最后GPS定位地址", width: "300px" },
], ],
drawDone: false, drawDone: false,
location:{} , // 设备维度查询的位置点 location: {}, // 设备维度查询的位置点
autoCenterMarker:null
}; };
}, },
mounted() { mounted() {
...@@ -250,9 +210,9 @@ export default { ...@@ -250,9 +210,9 @@ export default {
let plugins = CONSTANT.MAP_PLUGINS.concat([ let plugins = CONSTANT.MAP_PLUGINS.concat([
"AMap.LngLat", "AMap.LngLat",
"AMap.Rectangle", "AMap.Rectangle",
"AMap.RectangleEditor",
"AMap.LabelsLayer", "AMap.LabelsLayer",
"AMap.LabelMarker", "AMap.LabelMarker",
"AMap.AutoComplete",
]); ]);
if (window.AMap) { if (window.AMap) {
window.AMap = null; window.AMap = null;
...@@ -266,7 +226,19 @@ export default { ...@@ -266,7 +226,19 @@ export default {
.then((AMap) => { .then((AMap) => {
_this.mapLoading = false; _this.mapLoading = false;
window.AMap = AMap; window.AMap = AMap;
_this.map = mapService.init("map"); _this.map = mapService.init("map", { zoom: 12 });
var autoComplete = new AMap.AutoComplete({
input: "tipInput",
});
autoComplete.on("select", function (e) {
console.log(e);
let poi = e.poi || {};
if (poi && poi.location) {
_this.autoCenterMarker = mapService.createMarker(poi.location)
_this.map.setFitView();
_this.map.add(_this.autoCenterMarker);
}
});
}) })
.catch((error) => { .catch((error) => {
console.log(error); console.log(error);
...@@ -274,132 +246,38 @@ export default { ...@@ -274,132 +246,38 @@ export default {
}); });
}, },
// 画矩形 // 选择区域
drawRectangle(lnglat) { async chooseArea() {
let _this = this; let _this = this;
let lng = lnglat.southWest.lng; let _map = this.map;
let lat = lnglat.southWest.lat; let _zoom = _map.getZoom();
let nlng = lnglat.northEast.lng; if (_this.rectangle) {
let nlat = lnglat.northEast.lat; showToast({
let southWest = new AMap.LngLat(lng, lat); message: "地图上已有矩形,请先清除再画",
let northEast = new AMap.LngLat(nlng, nlat); });
let rectangle = this.rectangle; return false;
let rectangleEditor = this.rectangleEditor; }
// if (rectangle || rectangleEditor) { console.log(_zoom);
// //rectangleEditor.close(); if (_zoom < 13) {
// // this.map.remove([rectangle, rectangleEditor]); _this.map.setZoom(13);
// this.clearMap(); }
// } _this.map.setZooms([13, 30]);
this.clearMap(); var mouseTool = new AMap.MouseTool(_map);
mouseTool.rectangle({
let bounds = new AMap.Bounds(southWest, northEast); fillColor: "#00b0ff",
rectangle = new AMap.Rectangle({ strokeColor: "#80d8ff",
bounds: bounds,
strokeColor: "#f00",
strokeWeight: 3,
strokeOpacity: 1,
strokeDasharray: [30, 10],
// strokeStyle还支持 solid
strokeStyle: "dashed",
fillColor: "blue",
fillOpacity: 0.2, fillOpacity: 0.2,
cursor: "pointer", draggable: true,
zIndex: 50,
});
rectangleEditor = new AMap.RectangleEditor(this.map, rectangle);
rectangleEditor.open();
rectangleEditor.on("adjust", function (event) {
_this.calculateWidthHeight(event.bounds);
}); });
this.map.add(rectangle); mouseTool.on("draw", function (e) {
this.map.setFitView(rectangle); let rectangle = e.obj;
mouseTool.close();
// rectangle.on("dragend", function (event) { _this.rectangle = rectangle;
// console.log("拖动:", event); _this.calculateWidthHeight(rectangle.getOptions().bounds);
// });
this.rectangleEditor = rectangleEditor;
this.rectangle = rectangle;
this.rectangleHeight = 500;
this.rectangleWidth = 500;
this.map.setZooms([12, 30]);
},
/**
* 计算对应点的位置
* lng:中心点经度 lat:中心点维度 距离默认500m
* 垂直距离lath(所求点在已知点上方(北方)为正,否则为负)
* 水平距离longw(所求点在已知点右方(东方)为正,否则为负)
* lat = latitude + lath / (ARC * math.pi / 180);
* lng = longitude + longw / (ARC * math.cos(latitude) * math.pi / 180);
*/
getLngLat(lng, lat, w) {
let ARC = 6371.393 * 1000;
let pi = Math.PI;
let num = w ? w / 2 : 500 / 2;
// 中心点-左边点的经纬度
let leftLng = lng - num / ((ARC * Math.cos(lat) * pi) / 180);
// let leftLat = lat;
// 中心点-下边点的经纬度
// let bottomLng = lng;
let bottomLat = lat - num / ((ARC * pi) / 180);
// 中心点-右边点经纬度
let rightLng = lng + num / ((ARC * Math.cos(lat) * pi) / 180);
// let rightLat = lat;
// 中心点-上边点经纬度
// let topLng = lng;
let topLat = lat + num / ((ARC * pi) / 180);
// 左下角 经纬度 leftLng bottomLat
let southWest = { lng: leftLng, lat: bottomLat };
// 右上角 经纬度 rightLng topLat
let northEast = { lng: rightLng, lat: topLat };
let lnglats = { southWest, northEast };
return lnglats;
},
// 根据地址获取经纬度
getAddressLngLat(address) {
return new Promise((resolve) => {
AMap.plugin("AMap.Geocoder", function () {
var geocoder = new AMap.Geocoder();
geocoder.getLocation(address, function (status, result) {
resolve({ status, result });
});
});
}); });
}, },
// 选择区域
async chooseArea() {
let _type = this.menuId;
let o = this.form;
let location = {};
if (_type == 1) {
let address = `${o.name || ""}${o.address || ""}`;
let { status, result } = await this.getAddressLngLat(address);
if (status === "complete" && result.info === "OK") {
// 以解析出来经纬度为中心点来画矩形
let arr = result.geocodes ? result.geocodes : [];
location = arr[0] ? arr[0].location : {};
} else {
// 如果解析不出来经纬度,则以地图中心点来画矩形
location = this.map.getCenter();
}
}else{
location = this.location
}
console.log(location)
let lnglats = this.getLngLat(location.lng, location.lat);
this.drawRectangle(lnglats);
},
// 计算矩形宽度、高度 // 计算矩形宽度、高度
calculateWidthHeight(lnglats) { calculateWidthHeight(lnglats) {
if (!lnglats) { if (!lnglats) {
...@@ -427,18 +305,12 @@ export default { ...@@ -427,18 +305,12 @@ export default {
// 清空地图覆盖物 // 清空地图覆盖物
clearMap() { clearMap() {
let rectangle = this.rectangle;
let rectangleEditor = this.rectangleEditor;
if (rectangle || rectangleEditor) {
rectangleEditor.close();
}
if (this.map) { if (this.map) {
this.map.clearMap(); this.map.clearMap();
} }
this.rectangleHeight = 0; this.rectangleHeight = 0;
this.rectangleWidth = 0; this.rectangleWidth = 0;
this.rectangle = null; this.rectangle = null;
this.rectangleEditor = null;
this.map.setZooms([2, 30]); this.map.setZooms([2, 30]);
}, },
...@@ -449,7 +321,6 @@ export default { ...@@ -449,7 +321,6 @@ export default {
this.rectangleWidth = 0; this.rectangleWidth = 0;
this.form = {}; this.form = {};
this.deviceList = []; this.deviceList = [];
this.$refs.citySelect.reset();
}, },
// 展开 // 展开
...@@ -636,7 +507,9 @@ export default { ...@@ -636,7 +507,9 @@ export default {
collision: false, collision: false,
}); });
this.map.add(layer); this.map.add(layer);
arr.map((k) => {
for (let i = 0, len = arr.length; i < len; i++) {
let k = arr[i];
let curData = { let curData = {
position: [k.lng, k.lat], position: [k.lng, k.lat],
icon, icon,
...@@ -651,9 +524,10 @@ export default { ...@@ -651,9 +524,10 @@ export default {
infoWindow.open(_this.map); infoWindow.open(_this.map);
}); });
markers.push(labelMarker); markers.push(labelMarker);
}); }
layer.add(markers); layer.add(markers);
console.log("画点结束", new Date().getTime()); console.log("画点结束", new Date().getTime());
this.drawDone = true; this.drawDone = true;
this.map.setFitView(); this.map.setFitView();
......
...@@ -20,14 +20,15 @@ function MapService() { ...@@ -20,14 +20,15 @@ function MapService() {
var zhongliType = sessionStorage.getItem('zhongliType');//获取是否仲利账号状态,从本地内存中拿取数据 var zhongliType = sessionStorage.getItem('zhongliType');//获取是否仲利账号状态,从本地内存中拿取数据
MapService.prototype = { MapService.prototype = {
init: function (id) { init: function (id,options) {
var self = this; var self = this;
let params = options||{}
if(self.map){ if(self.map){
self.map.destroy() self.map.destroy()
} }
var map = new AMap.Map(id, { var map = new AMap.Map(id, {
resizeEnable: true, resizeEnable: true,
zoom: 11 zoom: params.zoom||11
}); });
// 添加比例尺 // 添加比例尺
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!