Commit 6f074792 by 冒粤蓉

commit special shp map

1 parent f75a3f23
......@@ -10,6 +10,7 @@
},
"dependencies": {
"axios": "^0.20.0",
"clipboard": "^2.0.4",
"core-js": "^3.6.5",
"element-ui": "^2.13.2",
"vue": "^2.6.11",
......@@ -46,4 +47,4 @@
"last 2 versions",
"not dead"
]
}
\ No newline at end of file
}
.icon {display: inline-block;background-image: url('./sprite.png');background-size: 119px 97px; vertical-align: middle;}
.icon-battery_empty { width: 42px; height: 20px; background-position: 0px 0px; }
.icon-battery_enough { width: 42px; height: 20px; background-position: 0px -20px; }
.icon-fullsize.active { width: 18px; height: 18px; background-position: 0px -79px; }
.icon-fullsize:active { width: 18px; height: 18px; background-position: 0px -79px; }
.icon-fullsize:hover { background-position: 0px -79px; }
.icon-fullsize { width: 18px; height: 18px; background-position: -18px -79px; }
.icon-icon_zoom_out.active { width: 18px; height: 18px; background-position: -36px -79px; }
.icon-icon_zoom_out:active { width: 18px; height: 18px; background-position: -36px -79px; }
.icon-icon_zoom_out:hover { background-position: -36px -79px; }
.icon-icon_zoom_out { width: 18px; height: 18px; background-position: -54px -79px; }
.icon-info_copy.active { width: 16px; height: 16px; background-position: -101px -36px; }
.icon-info_copy:active { width: 16px; height: 16px; background-position: -101px -36px; }
.icon-info_copy:hover { background-position: -101px -36px; }
.icon-info_copy { width: 16px; height: 16px; background-position: -101px -52px; }
.icon-info_device_alarm { width: 20px; height: 20px; background-position: -42px 0px; }
.icon-info_device_status { width: 20px; height: 20px; background-position: -42px -20px; }
.icon-info_device { width: 20px; height: 20px; background-position: 0px -40px; }
.icon-info_location { width: 20px; height: 20px; background-position: -20px -40px; }
.icon-info_stop { width: 20px; height: 20px; background-position: -40px -40px; }
.icon-info_time { width: 20px; height: 20px; background-position: -62px 0px; }
.icon-info_type { width: 20px; height: 20px; background-position: -62px -20px; }
.icon-locate.active { width: 19px; height: 19px; background-position: -62px -40px; }
.icon-locate:active { width: 19px; height: 19px; background-position: -62px -40px; }
.icon-locate:hover { background-position: -62px -40px; }
.icon-locate { width: 19px; height: 19px; background-position: 0px -60px; }
.icon-minisize.active { width: 18px; height: 19px; background-position: -82px -19px; }
.icon-minisize:active { width: 18px; height: 19px; background-position: -82px -19px; }
.icon-minisize:hover { background-position: -82px -19px; }
.icon-minisize { width: 18px; height: 18px; background-position: -72px -79px; }
.icon-refresh.active { width: 18px; height: 19px; background-position: -82px -38px; }
.icon-refresh:active { width: 18px; height: 19px; background-position: -82px -38px; }
.icon-refresh:hover { background-position: -82px -38px; }
.icon-refresh { width: 18px; height: 19px; background-position: -82px -57px; }
.icon-ruler.active { width: 19px; height: 19px; background-position: -19px -60px; }
.icon-ruler:active { width: 19px; height: 19px; background-position: -19px -60px; }
.icon-ruler:hover { background-position: -19px -60px; }
.icon-ruler { width: 19px; height: 19px; background-position: -38px -60px; }
.icon-satellite.active { width: 18px; height: 18px; background-position: -101px 0px; }
.icon-satellite:active { width: 18px; height: 18px; background-position: -101px 0px; }
.icon-satellite:hover { background-position: -101px 0px; }
.icon-satellite { width: 18px; height: 18px; background-position: -101px -18px; }
.icon-zoom_in.active { width: 19px; height: 19px; background-position: -57px -60px; }
.icon-zoom_in:active { width: 19px; height: 19px; background-position: -57px -60px; }
.icon-zoom_in:hover { background-position: -57px -60px; }
.icon-zoom_in { width: 19px; height: 19px; background-position: -82px 0px; }
\ No newline at end of file
/*
Stylus variables are information about icon's compiled state, stored under its original file name
.icon-home {
width: $icon_home_width;
}
The large array-like variables contain all information about a single icon
$icon_home = x y offset_x offset_y width height total_width total_height image_path;
At the bottom of this section, we provide information about the spritesheet itself
$spritesheet = width height image $spritesheet_sprites;
*/
$icon_fullsize_active_name = 'icon_fullsize_active';
$icon_fullsize_active_x = 54px;
$icon_fullsize_active_y = 57px;
$icon_fullsize_active_offset_x = -54px;
$icon_fullsize_active_offset_y = -57px;
$icon_fullsize_active_width = 18px;
$icon_fullsize_active_height = 18px;
$icon_fullsize_active_total_width = 76px;
$icon_fullsize_active_total_height = 75px;
$icon_fullsize_active_image = '~sprite.png';
$icon_fullsize_active = 54px 57px -54px -57px 18px 18px 76px 75px '~sprite.png' 'icon_fullsize_active';
$icon_fullsize_name = 'icon_fullsize';
$icon_fullsize_x = 0px;
$icon_fullsize_y = 57px;
$icon_fullsize_offset_x = 0px;
$icon_fullsize_offset_y = -57px;
$icon_fullsize_width = 18px;
$icon_fullsize_height = 18px;
$icon_fullsize_total_width = 76px;
$icon_fullsize_total_height = 75px;
$icon_fullsize_image = '~sprite.png';
$icon_fullsize = 0px 57px 0px -57px 18px 18px 76px 75px '~sprite.png' 'icon_fullsize';
$icon_locate_active_name = 'icon_locate_active';
$icon_locate_active_x = 19px;
$icon_locate_active_y = 0px;
$icon_locate_active_offset_x = -19px;
$icon_locate_active_offset_y = 0px;
$icon_locate_active_width = 19px;
$icon_locate_active_height = 19px;
$icon_locate_active_total_width = 76px;
$icon_locate_active_total_height = 75px;
$icon_locate_active_image = '~sprite.png';
$icon_locate_active = 19px 0px -19px 0px 19px 19px 76px 75px '~sprite.png' 'icon_locate_active';
$icon_locate_name = 'icon_locate';
$icon_locate_x = 0px;
$icon_locate_y = 19px;
$icon_locate_offset_x = 0px;
$icon_locate_offset_y = -19px;
$icon_locate_width = 19px;
$icon_locate_height = 19px;
$icon_locate_total_width = 76px;
$icon_locate_total_height = 75px;
$icon_locate_image = '~sprite.png';
$icon_locate = 0px 19px 0px -19px 19px 19px 76px 75px '~sprite.png' 'icon_locate';
$icon_minisize_active_name = 'icon_minisize_active';
$icon_minisize_active_x = 36px;
$icon_minisize_active_y = 38px;
$icon_minisize_active_offset_x = -36px;
$icon_minisize_active_offset_y = -38px;
$icon_minisize_active_width = 18px;
$icon_minisize_active_height = 19px;
$icon_minisize_active_total_width = 76px;
$icon_minisize_active_total_height = 75px;
$icon_minisize_active_image = '~sprite.png';
$icon_minisize_active = 36px 38px -36px -38px 18px 19px 76px 75px '~sprite.png' 'icon_minisize_active';
$icon_minisize_name = 'icon_minisize';
$icon_minisize_x = 18px;
$icon_minisize_y = 57px;
$icon_minisize_offset_x = -18px;
$icon_minisize_offset_y = -57px;
$icon_minisize_width = 18px;
$icon_minisize_height = 18px;
$icon_minisize_total_width = 76px;
$icon_minisize_total_height = 75px;
$icon_minisize_image = '~sprite.png';
$icon_minisize = 18px 57px -18px -57px 18px 18px 76px 75px '~sprite.png' 'icon_minisize';
$icon_refresh_active_name = 'icon_refresh_active';
$icon_refresh_active_x = 0px;
$icon_refresh_active_y = 38px;
$icon_refresh_active_offset_x = 0px;
$icon_refresh_active_offset_y = -38px;
$icon_refresh_active_width = 18px;
$icon_refresh_active_height = 19px;
$icon_refresh_active_total_width = 76px;
$icon_refresh_active_total_height = 75px;
$icon_refresh_active_image = '~sprite.png';
$icon_refresh_active = 0px 38px 0px -38px 18px 19px 76px 75px '~sprite.png' 'icon_refresh_active';
$icon_refresh_name = 'icon_refresh';
$icon_refresh_x = 18px;
$icon_refresh_y = 38px;
$icon_refresh_offset_x = -18px;
$icon_refresh_offset_y = -38px;
$icon_refresh_width = 18px;
$icon_refresh_height = 19px;
$icon_refresh_total_width = 76px;
$icon_refresh_total_height = 75px;
$icon_refresh_image = '~sprite.png';
$icon_refresh = 18px 38px -18px -38px 18px 19px 76px 75px '~sprite.png' 'icon_refresh';
$icon_ruler_active_name = 'icon_ruler_active';
$icon_ruler_active_x = 0px;
$icon_ruler_active_y = 0px;
$icon_ruler_active_offset_x = 0px;
$icon_ruler_active_offset_y = 0px;
$icon_ruler_active_width = 19px;
$icon_ruler_active_height = 19px;
$icon_ruler_active_total_width = 76px;
$icon_ruler_active_total_height = 75px;
$icon_ruler_active_image = '~sprite.png';
$icon_ruler_active = 0px 0px 0px 0px 19px 19px 76px 75px '~sprite.png' 'icon_ruler_active';
$icon_ruler_name = 'icon_ruler';
$icon_ruler_x = 38px;
$icon_ruler_y = 19px;
$icon_ruler_offset_x = -38px;
$icon_ruler_offset_y = -19px;
$icon_ruler_width = 19px;
$icon_ruler_height = 19px;
$icon_ruler_total_width = 76px;
$icon_ruler_total_height = 75px;
$icon_ruler_image = '~sprite.png';
$icon_ruler = 38px 19px -38px -19px 19px 19px 76px 75px '~sprite.png' 'icon_ruler';
$icon_satellite_active_name = 'icon_satellite_active';
$icon_satellite_active_x = 57px;
$icon_satellite_active_y = 37px;
$icon_satellite_active_offset_x = -57px;
$icon_satellite_active_offset_y = -37px;
$icon_satellite_active_width = 18px;
$icon_satellite_active_height = 18px;
$icon_satellite_active_total_width = 76px;
$icon_satellite_active_total_height = 75px;
$icon_satellite_active_image = '~sprite.png';
$icon_satellite_active = 57px 37px -57px -37px 18px 18px 76px 75px '~sprite.png' 'icon_satellite_active';
$icon_satellite_name = 'icon_satellite';
$icon_satellite_x = 57px;
$icon_satellite_y = 18px;
$icon_satellite_offset_x = -57px;
$icon_satellite_offset_y = -18px;
$icon_satellite_width = 18px;
$icon_satellite_height = 19px;
$icon_satellite_total_width = 76px;
$icon_satellite_total_height = 75px;
$icon_satellite_image = '~sprite.png';
$icon_satellite = 57px 18px -57px -18px 18px 19px 76px 75px '~sprite.png' 'icon_satellite';
$icon_zoom_in_active_name = 'icon_zoom_in_active';
$icon_zoom_in_active_x = 38px;
$icon_zoom_in_active_y = 0px;
$icon_zoom_in_active_offset_x = -38px;
$icon_zoom_in_active_offset_y = 0px;
$icon_zoom_in_active_width = 19px;
$icon_zoom_in_active_height = 19px;
$icon_zoom_in_active_total_width = 76px;
$icon_zoom_in_active_total_height = 75px;
$icon_zoom_in_active_image = '~sprite.png';
$icon_zoom_in_active = 38px 0px -38px 0px 19px 19px 76px 75px '~sprite.png' 'icon_zoom_in_active';
$icon_zoom_in_name = 'icon_zoom_in';
$icon_zoom_in_x = 19px;
$icon_zoom_in_y = 19px;
$icon_zoom_in_offset_x = -19px;
$icon_zoom_in_offset_y = -19px;
$icon_zoom_in_width = 19px;
$icon_zoom_in_height = 19px;
$icon_zoom_in_total_width = 76px;
$icon_zoom_in_total_height = 75px;
$icon_zoom_in_image = '~sprite.png';
$icon_zoom_in = 19px 19px -19px -19px 19px 19px 76px 75px '~sprite.png' 'icon_zoom_in';
$icon_zoom_out_active_name = 'icon_zoom_out_active';
$icon_zoom_out_active_x = 36px;
$icon_zoom_out_active_y = 57px;
$icon_zoom_out_active_offset_x = -36px;
$icon_zoom_out_active_offset_y = -57px;
$icon_zoom_out_active_width = 18px;
$icon_zoom_out_active_height = 18px;
$icon_zoom_out_active_total_width = 76px;
$icon_zoom_out_active_total_height = 75px;
$icon_zoom_out_active_image = '~sprite.png';
$icon_zoom_out_active = 36px 57px -36px -57px 18px 18px 76px 75px '~sprite.png' 'icon_zoom_out_active';
$icon_zoom_out_name = 'icon_zoom_out';
$icon_zoom_out_x = 57px;
$icon_zoom_out_y = 0px;
$icon_zoom_out_offset_x = -57px;
$icon_zoom_out_offset_y = 0px;
$icon_zoom_out_width = 19px;
$icon_zoom_out_height = 18px;
$icon_zoom_out_total_width = 76px;
$icon_zoom_out_total_height = 75px;
$icon_zoom_out_image = '~sprite.png';
$icon_zoom_out = 57px 0px -57px 0px 19px 18px 76px 75px '~sprite.png' 'icon_zoom_out';
$spritesheet_width = 76px;
$spritesheet_height = 75px;
$spritesheet_image = '~sprite.png';
$spritesheet_sprites = $icon_fullsize_active $icon_fullsize $icon_locate_active $icon_locate $icon_minisize_active $icon_minisize $icon_refresh_active $icon_refresh $icon_ruler_active $icon_ruler $icon_satellite_active $icon_satellite $icon_zoom_in_active $icon_zoom_in $icon_zoom_out_active $icon_zoom_out;
$spritesheet = 76px 75px '~sprite.png' $spritesheet_sprites;
/*
The provided mixins are intended to be used with the array-like variables
.icon-home {
spriteWidth($icon_home)
}
.icon-email {
sprite($icon_email)
}
Example usage in HTML:
`display: block` sprite:
<div class="icon-home"></div>
To change `display` (e.g. `display: inline-block;`), we suggest using a common CSS class:
// CSS
.icon {
display: inline-block;
}
// HTML
<i class="icon icon-home"></i>
*/
spriteWidth($sprite) {
width: $sprite[4];
}
spriteHeight($sprite) {
height: $sprite[5];
}
spritePosition($sprite) {
background-position: $sprite[2] $sprite[3];
}
spriteImage($sprite) {
background-image: url($sprite[8]);
}
sprite($sprite) {
spriteImage($sprite)
spritePosition($sprite)
spriteWidth($sprite)
spriteHeight($sprite)
}
/*
The `sprites` mixin generates identical output to the CSS template
but can be overridden inside of Stylus
This must be run when you have at least 2 sprites.
If run with a single sprite, then there will be reference errors.
sprites($spritesheet_sprites);
*/
sprites($sprites) {
for $sprite in $sprites {
$sprite_name = $sprite[9];
.{$sprite_name} {
sprite($sprite);
}
}
}
<template>
<!-- 围栏调用地图弹框 -->
<!-- <el-dialog id="fenceMapModal1" :visible="fenceMapModalVisible" @open="openDialog" @close="closeDialog" append-to-body width="1200px" top="10vh"> -->
<!-- <div class="dialog-header" slot="title">
<h2 class="header-title">地图引用</h2>
</div> -->
<div class="fence-map" :visible="fenceMapModalVisible" v-loading="mapLoading">
<!-- <el-form :model="form" ref="fenceMapForm" :rules="rules" :inline="true" size="mini" >
<el-form-item label="经度" prop="lng">
<el-input v-model="form.lng" style="width:100px" @change="transfer"></el-input>
</el-form-item>
<el-form-item label="纬度" prop="lat">
<el-input v-model="form.lat" style="width:100px" @change="transfer"></el-input>
</el-form-item>
<el-form-item label="经纬度解析" prop="transferAddr">
<el-input v-model="form.transferAddr" disabled placeholder="自动生成" style="width: 410px;"></el-input>
</el-form-item>
<el-form-item label="监控范围" prop="radius">
<el-input v-model="form.radius" style="width:160px" maxlength="10">
<template slot="append">KM</template>
</el-input>
</el-form-item>
<el-form-item><el-button type="primary" @click="updateFence">更新围栏</el-button></el-form-item>
</el-form>-->
<div id="mapContainer" class="map-container"></div>
<fence-map-controll @onRefreshMap="refreshMap" :isModalMap="true"></fence-map-controll>
<div class="map-seacrh-wrap">
<!-- <input type="text" id="fenceMapSearch"> -->
<el-input placeholder="请输入位置" id="fenceMapSearch" size="small" v-model="fenceMapSearch">
<template slot="prepend">搜索</template>
<!-- <el-button slot="append" icon="el-icon-search" @click="search"></el-button> -->
</el-input>
</div>
</div>
<!-- <div slot="footer" class="dialog-footer">
<el-button type="primary" @click="sure" size="small">确认</el-button>
<el-button @click="$emit('onFenceMapModalChange', false)" size="small">关闭</el-button>
</div> -->
<!-- </el-dialog> -->
<!-- 围栏调用地图弹框 /-->
</template>
<script>
import remoteLoad from '@/utils/remoteLoad.js'
import mapService from '@/utils/mapService.js'
import FenceMapControll from './fenceMapControll'
import Constants from '@/utils/constants'
export default{
props: ['init'],
data(){
return {
fenceMapSearch: '',
geolocation: null,
circleEditor: null,
areaCodeMap:"",
polygons:[],
polygonEditor:null,
autoCenterMarker:null,
marke:null,
fenceMapModalVisible:false,
polygon:null,
mapDot:true,
circle: null,
tableData:[],
transferTimeoutId: undefined,
geocoder: null,
transferFlag: null,
opts : {
subdistrict: 1, //返回下一级行政区
showbiz:false //最后一级返回街道信息
},
mapObj: null,
fenceType: 'polygon', //'area' 'polygon'
lng: '',
lat: '',
radius: '',
fenceCircle: null,
fenceCenter: null,
areaCode: '',
isFenceInit: false,
mapLoading: false,
polygonPath: [
/* [116.403322, 39.920255],
[116.410703, 39.897555],
[116.402292, 39.892353],
[116.389846, 39.891365] */
]
}
},
mounted(){
},
watch: {
lng(newVal){
//this.transfer()
},
lat(newVal){
//this.transfer()
},
/* mapData(newVal){
const fenceData = newVal;
this.initMapPromise.then(()=>{console.log(fenceData)
if(fenceData.fenceType === 'circle'){
this.drawFence(fenceData)
}
})
} */
},
async created () {
if(window.AMap){
this.initMap()
}else{
await remoteLoad(`${Constants.AMAP_URL}`, true);
this.initMap()
}
},
methods: {
initMap(){
this.initMapPromise = new Promise((resolve, reject)=>{
let check = ()=>{
this.checkMapLoaded && window.clearTimeout(this.checkMapLoaded);
return setTimeout(()=>{
if('AMap' in window && typeof AMap.Map == 'function' && !this.mapObj){
window.AMap = AMap;
this.mapObj = mapService.init('mapContainer');
this.bindContextMenu();
this.bindSearch();
resolve()
}else{
this.checkMapLoaded = check()
}
}, 100)
}
this.checkMapLoaded = check();
})
},
bindSearch(){
const self = this;
this.auto = new AMap.Autocomplete({
input: 'fenceMapSearch'
});
this.autoCenterMarker = new AMap.Marker({
icon: require('@/assets/images/auto-center-marker.gif'),
map: this.mapObj,
offset: new AMap.Pixel(-12,-12),
visible: false
});
this.autoCenterMarker.on('rightclick', (e)=> {
if(self.mapObj.getAllOverlays('circle').length){
window.mapMenu.contextMenu.open(self.mapObj, e.lnglat);
self.contextMenuPositon = e.lnglat; //右键菜单位置
}
});
AMap.event.addListener(this.auto, 'select', (e)=>{
if(e.poi && e.poi.location){
this.mapObj.setCenter(e.poi.location);
this.autoCenterMarker.setPosition(e.poi.location);
/*for(var i = 0, l = this.polygons.length; i < l; i++) {
this.polygons[i].setMap(null);
}*/
this.autoCenterMarker.show();
this.mapObj.add(this.autoCenterMarker);
//this.form.lng = e.poi.location.lng;
//this.form.lat = e.poi.location.lat;
//this.contextMenuPositon = e.poi.location
//window.mapMenu.contextMenu.open(this.mapObj, mapService.getLngLat(e.poi.location.lng, e.poi.location.lat))
}
this.mapObj.setZoom(14);
});
},
bindContextMenu(){
const self = this;
window.mapMenu = new ContextMenu(this.mapObj);//暴露mapMenu onclick要用
function ContextMenu(map) {
var me = this;
this.contextMenuPositon = null;
this.contextMenu = new AMap.ContextMenu({
isCustom: true,
content: `<div class="context_menu" >
<p onclick="mapMenu.moveCenter()"><span>设置围栏中心</span></p>
</div>`
});
map.on('rightclick', (e)=> {
if(self.mapObj.getAllOverlays('circle').length){
this.contextMenu.open(map, e.lnglat);
self.contextMenuPositon = e.lnglat; //右键菜单位置
}
});
}
ContextMenu.prototype.moveCenter = function addPOI() {
self.moveCenter()
this.contextMenu.close();
};
},
drawFence(){
if(!this.lng && !this.lat){
this.mapLoading = true;
this.getCurrentPosition().then((pos)=>{
this.lng = pos.lng;
this.lat = pos.lat;
this.radius = 1000;
this.drawFenceCircle(pos)
this.$emit('onUpdateMapData',{
lng: this.lng,
lat: this.lat,
radius: this.radius
});
this.mapLoading = false;
})
}else{
this.drawFenceCircle(mapService.getLngLat(this.lng, this.lat))
}
},
drawFenceCircle(fenceCenter){
const mapObj = this.mapObj;
if(this.fenceCircle){
this.fenceCircle.setCenter(mapService.getLngLat(this.lng, this.lat))
}else{
this.fenceCircle = new AMap.Circle({
map: mapObj,
center: fenceCenter,
radius: this.radius*1,
strokeColor: "#F33",
strokeOpacity: 1,
strokeWeight: 3,
fillColor: "ee2200",
fillOpacity: 0.35
});
mapObj.plugin(["AMap.CircleEditor"],()=>{
this.circleEditor = new AMap.CircleEditor(mapObj, this.fenceCircle);
AMap.event.addListener(this.circleEditor, 'adjust', (e)=>{
this.radius = e.radius/1;
this.$emit('onUpdateMapData',{
lng: this.lng,
lat: this.lat,
radius: this.radius
});
});
AMap.event.addListener(this.circleEditor, 'move', (e)=>{
this.lng = e.lnglat.lng;
this.lat = e.lnglat.lat;
this.$emit('onUpdateMapData',{
lng: this.lng,
lat: this.lat,
});
});
this.circleEditor.open();
});
}
mapService.setFitView()
mapObj.setZoom(14);
},
initFence(data){
this._mapPromiseTimeout && clearTimeout(this._mapPromiseTimeout)
if(this.initMapPromise){
if(data){
this.fenceType = data.fenceType
if(this.fenceType === 'circle'){
this.lng = data.lng;
this.lat = data.lat;
this.radius = data.radius;
}else if(this.fenceType === 'area'){
this.areaCode = data.areaCode
}else if(this.fenceType === 'polygon'){
if(data.polygonPath && data.polygonPath.length){
this.polygonPath = data.polygonPath
}
}
}
this.initMapPromise.then(()=>{
if(this.fenceType === 'circle'){
this.drawFence()
}else if(this.fenceType === 'area'){
this.drawArea()
}else if(this.fenceType === 'polygon'){
this.drawPolygon()
}
})
}else{
this._mapPromiseTimeout = setTimeout(() => {console.log('timeout')
this.initFence(data)
}, 100);
}
},
updateFence(data){
this.mapObj.clearMap()
this.fenceType = data.fenceType
this.polyEditor && this.polyEditor.close()
this.mouseTool && this.mouseTool.close()
if(this.fenceType === 'circle'){
this.fenceCircle = null;
if(data.lng){
this.lng = data.lng;
}
if(data.lat){
this.lat = data.lat;
}
if(data.radius){
this.radius = data.radius;
}
this.drawFence()
}else if(this.fenceType === 'area'){
if(data.areaCode){
this.areaCode = data.areaCode
}
if(this.areaCode){
this.drawArea()
}
}else if(this.fenceType === 'polygon'){
this.drawPolygon()
}
},
drawArea(){
let _this = this;
let areaCode = this.areaCode?this.areaCode.toString():'中国'
this.mapObj.clearMap()
for (var i = 0, l =this.polygons.length; i < l; i++) {
this.polygons[i].setMap(null);
}
let district,lng,lat
this.mapLoading = true;
AMap.service('AMap.DistrictSearch', function() {
var opts = {
subdistrict: 1, //返回下一级行政区
extensions: 'all',
showbiz:false //最后一级返回街道信息
};
areaCode === "中国"?delete opts.extensions :delete opts.showbiz
district = new AMap.DistrictSearch(opts);
district.setLevel('district');
district.search(areaCode, function(status, result) {
var bounds = result.districtList[0].boundaries;
lng = result.districtList[0].center.lng;
lat = result.districtList[0].center.lat;
if (bounds) {
for (var i = 0, l = bounds.length; i < l; i++) {
//生成行政区划polygon
let polygon = new AMap.Polygon({
map: _this.mapObj,
strokeWeight: 1,
path: bounds[i],
fillOpacity: 0.7,
fillColor: '#CCF3FF',
strokeColor: '#CC66CC',
});
_this.polygons.push(polygon);
}
lng = result.districtList[0].center.lng;
lat = result.districtList[0].center.lat;
let center = mapService.getLngLat(lng,lat);
mapService.setFitView();
//map.setZoom(10);
_this.mapLoading = false;
}
});
});
},
moveCenter(){
this.lng = this.contextMenuPositon.lng;
this.lat = this.contextMenuPositon.lat;
let center = mapService.getLngLat(this.lng, this.lat);
this.fenceCircle.setCenter(center);
this.$emit('onUpdateMapData', {
lng: this.lng,
lat: this.lat
})
},
getCurrentPosition(){
const mapObj = this.mapObj;
const self = this;
return new Promise((resolve, reject)=>{
mapObj.plugin('AMap.Geolocation', function(){
self.geolocation = new AMap.Geolocation();
self.geolocation.getCurrentPosition();
AMap.event.addListener(self.geolocation, 'complete', function(e){//返回定位信息
var lnglatXY = mapService.getLngLat(e.position.lng, e.position.lat);
resolve(lnglatXY)
});
AMap.event.addListener(self.geolocation, 'error', function(e){//返回定位出错信息
resolve(mapObj.getCenter())
});
});
})
},
drawPolygon(){
const mapObj = this.mapObj;
const self = this;
if(this.polygonPath.length){
self.polygon = new AMap.Polygon({
path: this.polygonPath,
strokeColor: "#FF33FF",
strokeWeight: 6,
strokeOpacity: 0.2,
fillOpacity: 0.4,
fillColor: '#1791fc',
zIndex: 50,
})
mapObj.add(self.polygon)
mapObj.setFitView([ self.polygon ])
self.polyEditor = new AMap.PolyEditor(mapObj, self.polygon)
self.polyEditor.open()
self.bindPolyEvent(self.polyEditor)
}else{
self.mouseTool = new AMap.MouseTool(mapObj)
self.mouseTool.polygon({
strokeColor: "#FF33FF",
strokeOpacity: 1,
strokeWeight: 6,
strokeOpacity: 0.2,
fillColor: '#1791fc',
fillOpacity: 0.4,
// 线样式还支持 'dashed'
strokeStyle: "solid",
// strokeStyle是dashed时有效
// strokeDasharray: [30,10],
})
self.mouseTool.on('draw', function(event) {
// event.obj 为绘制出来的覆盖物对象
self.polygon = event.obj;
self.polyEditor = new AMap.PolyEditor(mapObj, self.polygon)
self.polyEditor.open()
self.bindPolyEvent(self.polyEditor)
self.mouseTool.close()
self.emitPolyEvent()
})
}
},
emitPolyEvent(){
let pathArr = this.polygon.getPath()
let resultArr = pathArr.map((item)=>{
return [item.lng, item.lat]
})
this.polygonPath = resultArr
this.$emit('onUpdateMapData',{
polygonPath: this.polygonPath
});
console.log(resultArr.join('|'))
},
bindPolyEvent(polyEditor){
const self = this
polyEditor.on('addnode', function(event) {
console.log('触发事件:addnode')
self.emitPolyEvent()
})
polyEditor.on('adjust', function(event) {
console.log('触发事件:adjust')
self.emitPolyEvent()
})
polyEditor.on('removenode', function(event) {
console.log('触发事件:removenode')
self.emitPolyEvent()
})
polyEditor.on('end', function(event) {
console.log('触发事件: end')
self.emitPolyEvent()
// event.target 即为编辑后的多边形对象
})
},
transfer(){
this.transferTimeoutId && window.clearTimeout(this.transferTimeoutId);
this.transferTimeoutId = window.setTimeout(()=>{
const flag = new Date();
this.transferFlag = flag;
if(!this.geocoder){
mapService.getGeocoder().then((gc)=>{
this.geocoder = gc;
this.getAddress(flag);
});
}else{
this.getAddress(flag);
}
}, 500)
},
getAddress(flag){
const lnglatXY = [this.form.lng, this.form.lat];
this.transferAddr = '';
this.geocoder.getAddress(lnglatXY, (status, result)=>{
if(flag == this.transferFlag){
if (status === 'complete' && result.info === 'OK') {//获取地址成功
this.form.transferAddr = result.regeocode.formattedAddress;
this.$emit('onUpdateMapData',{
lng: this.form.lng,
lat: this.form.lat,
address: this.form.transferAddr,
radius: this.form.radius
});
}else{
this.form.transferAddr = '';
}
}
});
},
refreshMap() {
}
},
components:{
FenceMapControll
}
}
</script>
<style scoped>
.fence-map{
position: relative;
}
.fence-map .map-container{
width: 100%;
height: 500px;
}
.fence-map .map-seacrh-wrap{
position: absolute;
top: 40px;
left: 10px;
z-index: 1000;
}
.el-form-item{
margin: -20px 0 20px 10px;
}
</style>
<style lang="scss">
.context_menu{
min-width: 10em;
background-color: #fff;
padding: 10px;
border: 1px solid #efefef;
border-radius: 2px;
cursor: pointer;
&>p{
margin: 0;
i{
font-size: 18px;
color: #094;
margin-right: 5px;
}
i,span{
vertical-align: middle;
}
}
}
</style>
\ No newline at end of file
<template>
<ul class="map-control ng-scope" ui-map-control="">
<li><a title="卫星/地图切换" @click="toggleMapType"><i class="icon icon-satellite"></i></a></li>
<li><a title="测距" @click="toggleRuler" :class="isRulerOn?'active':''"><i class="icon icon-ruler"></i></a></li>
<li><a title="定位当前距离" @click="getLocation"><i class="icon icon-locate"></i></a></li>
<li><a title="放大" @click="zoomIn"><i class="icon icon-zoom_in"></i></a></li>
<li><a title="缩小" @click="zoomOut"><i class="icon icon-icon_zoom_out"></i></a></li>
<!-- <li v-if="!isModalMap"><a title="全屏切换" @click="toggleScreen">
<i class="icon icon-fullsize" :class="isFullscreen?'icon-minisize':'icon-fullsize'"></i>
</a></li> -->
<li v-if="!isModalMap"><a title="刷新" @click="$emit('onRefreshMap')"><i class="icon icon-refresh"></i></a></li></ul>
</template>
<script>
import '../../assets/spritesmith-generated/sprite.css'
import mapService from 'utils/mapService.js'
// import { mapGetters, mapActions } from 'vuex'
export default{
props: ['isModalMap'],
data(){
return {
isRulerOn: false,
isFullscreen: false
}
},
computed: {
// ...mapGetters([
// 'isCollapse'
// ])
},
methods:{
toggleMapType(){
mapService.toggleMapType();
},
toggleRuler(){
if(this.isRulerOn){
mapService.rulerTurnOff();
this.isRulerOn = false;
}else{
mapService.rulerTurnOn();
this.isRulerOn = true;
}
},
getLocation(){
mapService.getCurrentLocation();
},
zoomIn(){
mapService.zoomIn();
},
zoomOut(){
mapService.zoomOut();
},
toggleScreen(){
if(this.isFullscreen){
this.isFullscreen = false;
this.$emit('onToggleVisible', true)
// if(this.isCollapse){
// this.toggleCollapse()
// }
}else{
this.isFullscreen = true;
this.$emit('onToggleVisible', false)
// if(!this.isCollapse){
// this.toggleCollapse()
// }
}
},
refresh(){
},
// ...mapActions([
// 'toggleCollapse'
// ])
}
}
</script>
<style scoped>
ul.map-control{
position: absolute;
bottom: 260px;
right: 10px;
list-style: none;
padding: 5px;
margin: 0px;
background-color: rgba(0,0,0,0.1);
z-index: 102;
}
.map-control>li{
width: 30px;
height: 30px;
background-color: #fff;
}
.map-control a{
display: inline-block;
width: 30px;
height: 30px;
line-height: 30px;
text-align: center;
cursor: pointer;
}
i{
display: inline-block;
vertical-align: middle;
}
</style>
\ No newline at end of file
import Vue from 'vue';
const EventBus = new Vue();
export default EventBus;
\ No newline at end of file
const MAP_KEY = '75116f653f3b2e4568116dad8cd9b899';
const Constants = {
AMAP_URL: `https://webapi.amap.com/maps?v=1.4.2&key=${MAP_KEY}&plugin=AMap.PolyEditor,AMap.CircleEditor,AMap.DistrictSearch,AMap.Autocomplete,AMap.MarkerClusterer,AMap.MouseTool,AMap.Text`,
// 处理状态
DEAL_STATUS: {
'0': '未处理',
......
import ClipboardJS from 'clipboard'
window.ClipboardJS = ClipboardJS
import EventBus from '../event-bus'
import { Message } from "element-ui";
EventBus.$on('uiMap.copySuccess', (data)=>{
Message({
type: 'success',
message: '已复制内容至粘贴板'
});
});
function MapService(){
this.map = null;
this.restainLayer = null;
}
MapService.prototype = {
init: function(id){
var self = this;
self.map = new AMap.Map(id, {
resizeEnable: true,
zoom: 11
});
//距离测量
self.map.plugin(["AMap.RangingTool"],function(){
self.ruler = new AMap.RangingTool(self.map);
});
//定位
self.map.plugin('AMap.Geolocation', function(){
self.geolocation = new AMap.Geolocation();
});
return self.map;
},
toggleMapType: function(){
var self = this;
self.type = self.type?0:1; //0:使用2D地图,1:混合图
if(self.type === 1){
// 构造官方卫星、路网图层
self.mixLayers = [
new AMap.TileLayer.Satellite(),
new AMap.TileLayer.RoadNet()
];
let layers = self.mixLayers.concat(self.map.getLayers());
// 地图上设置图层
self.map.setLayers(layers);
}else{
// 地图上设置图层
self.map.remove(self.mixLayers);
/*self.map.plugin(["AMap.MapType"],function(){
//地图类型切换
var type = new window.AMap.MapType({
defaultType: self.type
});
self.map.addControl(type);
});*/
}
},
rulerTurnOn: function(){
this.ruler.turnOn();
},
rulerTurnOff: function(){
this.ruler.turnOff();
},
getCurrentLocation: function(){
var self = this;
self.geolocation.getCurrentPosition();
self.currentMarker && self.map.remove(self.currentMarker);
AMap.event.addListener(self.geolocation, 'complete', function(e){//返回定位信息
var lnglatXY = self.getLngLat(e.position.lng, e.position.lat);
self.currentMarker = self.createMarker(lnglatXY);
//self.map.setCenter(lnglatXY);
self.setFitView()
});
AMap.event.addListener(self.geolocation, 'error', function(e){//返回定位出错信息
});
},
createMarker: function (lnglatXY){
var marker = new AMap.Marker({
position: lnglatXY,
icon: require('@/assets/images/mapLocation.gif'),
map: this.map,
offset: new AMap.Pixel(-12,-12)
});
return marker;
},
createPointMarker: function (lnglatXY){
var marker = new AMap.Marker({
position: lnglatXY,
icon: require('@/assets/images/point.png'),
map: this.map,
offset: new AMap.Pixel(-9,-9)
});
return marker;
},
createConstantMarker: function (lnglatXY, map){
var marker = new AMap.Marker({
position: lnglatXY,
icon: require('@/assets/images/icon_constant.png'),
map: map,
offset: new AMap.Pixel(-12,-17)
});
return marker;
},
createCarMarker: function (lnglatXY, map){
var marker = new AMap.Marker({
position: lnglatXY,
icon: require('@/assets/images/icon_car.png'),
map: map,
autoRotation: true,
offset: new AMap.Pixel(-18,-11),
zIndex: 1020,
animation: 'AMAP_ANIMATION_DROP'
});
return marker;
},
createPOIMarker(lnglatXY, map){
var marker = new AMap.Marker({
position: lnglatXY,
content:`<span class="poi_marker"></span>`,
//icon: require('@/assets/images/poi-marker-default.png'),
map: map,
autoRotation: true,
offset: new AMap.Pixel(-20, -50),
zIndex: 1020,
animation: 'AMAP_ANIMATION_DROP'
});
return marker;
},
createPOIInfo(info){
return `<div class="poi_infowin">
<h3 class="map-infowindow-title">POI信息</h3>
<div class="map-infowindow-ct">
<p class="poi_item"><label>经度:</label><span>${info.lng}</span></p>
<p class="poi_item"><label>纬度:</label><span>${info.lat}</span></p>
<p class="poi_item"><label>自定义名称:</label><span>${info.poiName}</span></p>
<p class="poi_item"><label>解析地址:</label><span>${info.address}</span>
</div></div>`
},
bindPOIInfoWindow(marker, map, info){
var infoDiv = document.createElement('div');
infoDiv.innerHTML = this.createPOIInfo(info);
var infoWindow = new AMap.InfoWindow({
offset: new AMap.Pixel(0, -48),
content: infoDiv,
autoMove: true
});
marker.infoWindow = infoWindow;
marker.on('click', markerClick);
function markerClick(e){
//infoWindow.setContent(e.target.content);
infoWindow.open(map, e.target.getPosition());
}
return infoWindow;
},
setAlarmIcon(marker){
marker.setIcon(require('@/assets/images/icon_car_alarm.png'))
},
setDefaultIcon(marker){
marker.setIcon(require('@/assets/images/icon_car.png'))
},
createHistoryLocationMarker(lnglatXY, map){
var marker = new AMap.Marker({
position: lnglatXY,
icon: require('@/assets/images/icon_location.png'),
map: map,
autoRotation: true,
offset: new AMap.Pixel(-12,-17),
zIndex: 1020,
animation: 'AMAP_ANIMATION_DROP'
});
return marker;
},
createStartMarker: function(lnglatXY, map){
var marker = new AMap.Marker({
position: lnglatXY,
icon: require('@/assets/images/icon_start.png'),
map: map,
offset: new AMap.Pixel(-12,-34),
zIndex: 100
});
return marker;
},
createEndMarker: function(lnglatXY, map){
var marker = new AMap.Marker({
position: lnglatXY,
icon: require('@/assets/images/icon_end.png'),
map: map,
offset: new AMap.Pixel(-12,-34),
zIndex: 101
});
return marker;
},
createPolyline: function(map){
return new AMap.Polyline({
map: map,
strokeWeight: 2,
strokeColor: '#009944'
});
},
createCircle: function(lnglatXY, map, radius){
return new AMap.Circle({
map: map,
center: lnglatXY,
radius: radius,
strokeColor: '#094',
fillColor: '#094',
strokeWeight: 1,
strokeOpacity: 0.8,
fillOpacity: 0.1
});
},
createPoint: function(lnglatXY, map){
return new AMap.Circle({
map: map,
center: lnglatXY,
radius: 3,
strokeColor: '#094',
fillColor: '#094',
strokeWeight: 3,
strokeOpacity: 1,
fillOpacity: 1
});
},
createInfoWindow(marker, map, div, isInfoOpen, isInfoAutoMove){
var infoWindow = new AMap.InfoWindow({
offset: new AMap.Pixel(0, 0),
content: div,
autoMove: !!isInfoAutoMove
});
marker.infoWindow = infoWindow;
var clipboard = new ClipboardJS(div.querySelector('.copy-btn'));
clipboard.on('success', function(e) {
e.clearSelection();
EventBus.$emit('uiMap.copySuccess');
});
clipboard.on('error', function(e) {
console.error('Action:', e.action);
console.error('Trigger:', e.trigger);
});
if(isInfoOpen){
infoWindow.open(map, marker.getPosition());
}
//给Marker绑定单击事件
marker.on('click', markerClick);
function markerClick(e){
//infoWindow.setContent(e.target.content);
infoWindow.open(map, e.target.getPosition());
}
return infoWindow;
},
bindMonitorInfoWindow: function(marker, map, info, isInfoOpen, isInfoAutoMove){
var self = this;
var infoDiv = document.createElement('div');
infoDiv.innerHTML = self.createMonitorInfo(info);
let eLocation = info[info.eLocateType];
var statusArr = ['行驶中', '静止', '离线', '在线']
if(info.status === 2){
infoDiv.querySelector('[data-status]').textContent = `${statusArr[info.status]} | 已离线${info.deadline}`;
}else{
infoDiv.querySelector('[data-status]').textContent = statusArr[info.status];
}
infoDiv.querySelector('[data-time]').textContent = eLocation.time;
infoDiv.querySelector('[data-transferAddress]').textContent = eLocation.transferAddress;
infoDiv.querySelector('[data-clipboard-text').setAttribute('data-clipboard-text', eLocation.transferAddress);
if(info.battery){
infoDiv.querySelector('[data-battery]').classList.remove('hide');
infoDiv.querySelector('[data-battery-percentage]').style.width = info.battery;
infoDiv.querySelector('[data-battery-text]').textContent = info.battery;
}else{
infoDiv.querySelector('[data-battery]').classList.add('hide');
}
let gpsBtn = infoDiv.querySelector('[data-gps]')
let baseBtn = infoDiv.querySelector('[data-base]')
if(info.eLocateType === 'bsLocation'){
gpsBtn&&gpsBtn.classList.remove('el-button--primary');
baseBtn.classList.add('el-button--primary');
}else{
gpsBtn&&gpsBtn.classList.add('el-button--primary');
baseBtn&&baseBtn.classList.remove('el-button--primary');
}
baseBtn&&(baseBtn.onclick = function(e){console.log(info)
if(info.eLocateType === 'bsLocation') return;
info.eLocateType = 'bsLocation'
eLocation = info[info.eLocateType];
if(!eLocation.elng || !eLocation.elat) {
Message({
type: 'info',
message: '暂无基站数据'
});
return;
}
gpsBtn.classList.remove('el-button--primary');
baseBtn.classList.add('el-button--primary');
infoDiv.querySelector('[data-transferAddress]').textContent = eLocation.transferAddress;
infoDiv.querySelector('[data-time]').textContent = eLocation.time;
EventBus.$emit('uiMap.monitor.changeELocate', info)
})
gpsBtn&&(gpsBtn.onclick = function(e){
if(info.eLocateType === 'gpsLocation') return;
info.eLocateType = 'gpsLocation'
eLocation = info[info.eLocateType];
if(!eLocation.elng || !eLocation.elat) {
Message({
type: 'info',
message: '暂无GPS数据'
});
return;
}
gpsBtn.classList.add('el-button--primary');
baseBtn.classList.remove('el-button--primary');
infoDiv.querySelector('[data-transferAddress]').textContent = eLocation.transferAddress;
infoDiv.querySelector('[data-time]').textContent = eLocation.time;
EventBus.$emit('uiMap.monitor.changeELocate', info)
})
if(info.alarmModelList && info.alarmModelList.length){
let _html = '<i class="icon icon-info_device_alarm"></i>报警状态:'
info.alarmModelList.forEach((item)=>{
if(item.alarmType === '1'){
_html+=`<button type="button" class="el-button el-button--mini el-button--danger" data-alarmoff data-alarmtime="${item.alarmTime}">断电</button>`
}else if(item.alarmType === '99'){
_html+=`<button type="button" class="el-button el-button--mini el-button--danger" data-alarmlight data-alarmtime="${item.alarmTime}">光感</button>`
}
});
infoDiv.querySelector('[data-alarm]').innerHTML = _html;
if(infoDiv.querySelector('[data-alarmoff]')){
infoDiv.querySelector('[data-alarmoff]').onclick = function(e){
console.log(e.target.dataset)
window.open(`#/report/antiOffAlarm?type=1&time=${e.target.dataset.alarmtime}&sn=${info.sn}`)
}
}
if(infoDiv.querySelector('[data-alarmlight]')){
infoDiv.querySelector('[data-alarmlight]').onclick = function(e){
console.log(e.target.dataset)
window.open(`#/report/antiOffAlarm?type=99&time=${e.target.dataset.alarmtime}&sn=${info.sn}`)
}
}
infoDiv.querySelector('[data-alarm]').style.display = 'block';
}else{
infoDiv.querySelector('[data-alarm]').style.display = 'none';
}
const snSourceType = `${info.sn}:${info.isSource}`
/* EventBus.$on(`uiMap.monitor.changeStatus.${snSourceType}`, (status)=>{
if(status === 2){
infoDiv.querySelector('[data-status]').textContent = `${statusArr[info.status]} | 已离线${info.deadline}`;
}else{
infoDiv.querySelector('[data-status]').textContent = statusArr[info.status];
}
}) */
return this.createInfoWindow(marker, map, infoDiv, isInfoOpen, isInfoAutoMove);
},
bindLocationInfoWindow(marker, map, info){
var self = this;
var infoDiv = document.createElement('div');
infoDiv.innerHTML = self.createLocationInfo(info);
return this.createInfoWindow(marker, map, infoDiv);
},
bindResidentInfoWindow(marker, map, info){
var self = this;
var infoDiv = document.createElement('div');
infoDiv.innerHTML = self.createResidentInfo(info);
return this.createInfoWindow(marker, map, infoDiv);
},
bindFenceInfoWindow(marker, map, info){
var self = this;
var infoDiv = document.createElement('div');
infoDiv.innerHTML = self.createFenceInfo(info);
var statusArr = ['行驶中', '静止', '离线', '在线'];
function fillGPS(){
infoDiv.querySelector('[data-time]').textContent = info.timeGPS;
infoDiv.querySelector('[data-transferAddress]').textContent = info.transferAddressGPS;
infoDiv.querySelector('[data-clipboard-text').setAttribute('data-clipboard-text', info.transferAddressGPS);
infoDiv.querySelector('#locateTypeGps').classList.add('active');
infoDiv.querySelector('#locateTypeBase').classList.remove('active');
marker.setPosition(self.getLngLat(info.lngGPS, info.latGPS));
marker.infoWindow && marker.infoWindow.open(map, marker.getPosition());
}
function fillBase(){
infoDiv.querySelector('[data-time]').textContent = info.timeBase;
infoDiv.querySelector('[data-transferAddress]').textContent = info.transferAddressBase;
infoDiv.querySelector('[data-clipboard-text').setAttribute('data-clipboard-text', info.transferAddressBase);
infoDiv.querySelector('#locateTypeGps').classList.remove('active');
infoDiv.querySelector('#locateTypeBase').classList.add('active');
marker.setPosition(self.getLngLat(info.lngBase, info.latBase));
marker.infoWindow && marker.infoWindow.open(map, marker.getPosition());
}
infoDiv.querySelector('[data-status]').textContent = statusArr[info.status];
if(info.battery){
infoDiv.querySelector('[data-battery]').classList.remove('hide');
infoDiv.querySelector('[data-battery-percentage]').style.width = info.battery;
infoDiv.querySelector('[data-battery-text]').textContent = info.battery;
}else{
infoDiv.querySelector('[data-battery]').classList.add('hide');
}
infoDiv.querySelector('#locateTypeGps').onclick = function(e){
fillGPS()
}
infoDiv.querySelector('#locateTypeBase').onclick = function(e){
fillBase()
}
fillGPS();
return this.createInfoWindow(marker, map, infoDiv);
},
getLngLat: function(lng, lat){
return new AMap.LngLat(lng, lat);
},
getGeocoder: function(){
return new Promise((resolve)=>{
AMap.service('AMap.Geocoder',function(){//回调函数
var geocoder = new AMap.Geocoder({
batch: true
});
resolve(geocoder);
});
})
},
getAddress: function(geocoder, lnglatXY){
geocoder.getAddress(lnglatXY, function(status, result) {
if (status === 'complete' && result.info === 'OK') {
//获得了有效的地址信息:
//即,result.regeocode.formattedAddress
}else{
//获取地址失败
}
});
},
zoomIn: function(){
this.map.zoomIn();
},
zoomOut: function(){
this.map.zoomOut();
},
createMonitorInfo: function(info){console.log(info)
/*var _html = '<h3 class="uimap-info-title">'+ info.name+'/'+ info.standNo +'</h3><div class="uimap-info-ct"><p><span><i class="fa fa-inbox"></i></span>'+ info.sn +'</p>';
if(info.time){
_html += '<p><span><i class="fa fa-clock-o"></i></span>'+ info.time +'</p>';
}
_html += '<p><span><i class="fa fa-map-marker"></i></span>'+ info.transferAddress +'</p>';
_html += '<p><span><i class="fa fa-car"></i></span>'+ '驻留次数:' +(info.totalTimes?info.totalTimes:'1')+'</p>';
return _html;*/
let queryCode = `sn=${info.sn}&name=${encodeURI(info.name)}&standno=${info.standNo}`;
return `<h3 class="map-infowindow-title">${info.name}/${info.standNo}</h3>
<div class="map-infowindow-ct">
<p><i class="icon icon-info_device"></i> 设备号:<span class="des"> ${info.sn} (${info.isSource==='1'?'有线':'无线'})</span>
<span class="battery" data-battery>
<i class="fill"><i class="fill-percentage" data-battery-percentage></i></i>
<i class="icon icon-battery_enough"></i>
<i class="text" data-battery-text></i>
</span></p>
<p><i class="icon icon-info_device_status"></i> 设备状态: <span class="des" data-status></span></p>
<p data-alarm>
<button type="button" class="el-button el-button--mini el-button--primary" data-alarmoff>断电</button>
<button type="button" class="el-button el-button--mini el-button--primary" data-alarmlight>光感</button>
</p>
<p><i class="icon icon-info_time"></i> 最后上点时间: <span class="des" data-time></span></p>
<p><i class="icon icon-info_location"></i> 最后上点地址: <span class="des adr" data-transferAddress>${info.transferAddress}</span>
<a class="copy-btn" data-clipboard-text=""><i class="icon icon-info_copy"></i></a>
</p>
<p><i class="icon icon-info_type"></i> 定位类型:
${info.eLocateSingle?
(info.eLocateType==='gpsLocation'?`<button type="button" class="el-button el-button--mini el-button--primary" data-gps>GPS</button> `:
`<button type="button" class="el-button el-button--mini el-button--primary" data-base>基站</button>`):
`<span class="el-button-group">
<button type="button" class="el-button el-button--mini el-button--primary" data-gps>GPS</button>
<button type="button" class="el-button el-button--mini" data-base>基站</button>
</span>`
}
</p>
<p class="redirect-row">
<a class="redirect-btn" onclick="window.open('#/monitor/historyLocation?${queryCode}')">历史停留</a>
<a class="redirect-btn" onclick="window.open('#/monitor/resident?${queryCode}')">常驻地</a>
<a class="redirect-btn" onclick="window.open('#/monitor/replay?${queryCode}')">轨迹回放</a>
<a class="redirect-btn" onclick="window.open('#/monitor/fence?${queryCode}')">电子围栏</a>
</p>
</div>`;
},
createFenceInfo(info){
return `<h3 class="map-infowindow-title">${info.name}/${info.standno}</h3>
<div class="map-infowindow-ct">
<p><i class="icon icon-info_device"></i> 设备号:<span class="des"> ${info.sn} (${info.sourceString})</span>
<span class="battery hide" data-battery>
<i class="fill"><i class="fill-percentage" data-battery-percentage></i></i>
<i class="icon icon-battery_enough"></i>
<i class="text" data-battery-text></i>
</span></p>
<p><i class="icon icon-info_device_status"></i> 设备状态: <span class="des" data-status></span></p>
<p><i class="icon icon-info_time"></i> 最后上点时间: <span class="des" data-time></span></p>
<p><i class="icon icon-info_location"></i> 最后上点地址: <span class="des adr" data-transferAddress>${info.transferAddress}</span>
<a class="copy-btn" data-clipboard-text=""><i class="icon icon-info_copy"></i></a>
</p>
<p>
<i class="icon icon-info_type"></i>
定位类型:
<a class="locate-btn active" id="locateTypeGps">GPS</a>
<a class="locate-btn" id="locateTypeBase">基站</a>
</p>
</div>`;
},
createLocationInfo(info){
return `<h3 class="map-infowindow-title">${info.name}/${info.standno}</h3>
<div class="map-infowindow-ct">
<p><i class="icon icon-info_time"></i> 停留时间: <span class="des">${info.begintime}</span></p>
<p><i class="icon icon-info_location"></i> 停留地址: <span class="des adr" >${info.transferAddress}</span>
<a class="copy-btn" data-clipboard-text="${info.transferAddress}"><i class="icon icon-info_copy"></i></a>
</p>
<p><i class="icon icon-info_stop"></i> 停留时长: <span class="des">${info.duration}</span></p>
</div>`;
},
createResidentInfo(info){
return `<h3 class="map-infowindow-title">${info.name}/${info.standNo}</h3>
<div class="map-infowindow-ct">
<p><i class="icon icon-info_device"></i> 设备号: <span class="des">${info.sn}</span></p>
<p><i class="icon icon-info_location"></i> 常驻地址: <span class="des adr" >${info.transferAddress}</span>
<a class="copy-btn" data-clipboard-text="${info.transferAddress}"><i class="icon icon-info_copy"></i></a>
</p>
<p><i class="icon icon-info_device"></i> 驻留次数: <span class="des">${info.totalTimes}次</span></p>
<p><i class="icon icon-info_stop"></i> 驻留时长: <span class="des">${info.totalDurationString}</span></p>
</div>`;
},
clearMap: function(map){
this.map.clearMap();
},
setFitView: function(map){
this.map.setFitView();
},
bindClickEvent(){
}
}
const mapService = new MapService();
export default mapService
\ No newline at end of file
export default function remoteLoad (url, hasCallback) {
return createScript(url)
/**
* 创建script
* @param url
* @returns {Promise}
*/
function createScript (url) {
var scriptElement = document.createElement('script')
scriptElement.src = url
if(window.__POWERED_BY_QIANKUN__) {
document.getElementById('sub-system-frame').children[0].appendChild(scriptElement);
} else {
document.body.appendChild(scriptElement);
}
var promise = new Promise((resolve, reject) => {
scriptElement.addEventListener('load', e => {
// removeScript(scriptElement)
resolve(e)
if (!hasCallback) {
resolve(e)
}
}, false)
scriptElement.addEventListener('error', e => {
// removeScript(scriptElement)
reject(e)
}, false)
if (hasCallback) {
window.____callback____ = function () {
resolve()
window.____callback____ = null
}
}
})
if (hasCallback) {
url += '&callback=____callback____'
}
return promise
}
/**
* 移除script标签
* @param scriptElement script dom
*/
function removeScript (scriptElement) {
document.body.removeChild(scriptElement)
}
}
......@@ -30,16 +30,124 @@
</el-form-item>
</el-form>
<div class="ibox-content" style="height: 500px; padding:0 20px;z-index: 100">
<fence-map
:mapData="mapData"
@onUpdateMapData="updateMapData"
ref="fenceMap"
>
</fence-map>
</div>
</div>
</template>
<script>
import fenceMap from 'components/map/fenceMap.vue'
export default {
components: { fenceMap },
data() {
return {
shopForm: {}
shopForm: {},
mapData: []
}
},
created() {
this.init();
},
methods: {
init() {
this.fenceId = this.$route.query.id
if(typeof this.fenceId != 'undefined'){
this.getFenceDetail(this.fenceId);
this.getFenceSnsList(this.fenceId);
}else{
// MONITOR_SERVICE.getNewFenceId().then((res)=>{
// if(res.returnCode == 0){
// this.form.fenceNo = res.data.fenceNo;
// this.$refs.fenceMap.initFence({
// fenceType: 'circle'
// });
// }
// });
// this.restainFenceName = undefined;
}
},
getFenceDetail(id){
MONITOR_SERVICE.getFenceDetailById({id: id}).then((res)=>{
if(res.returnCode == 0){
const form = this.form;
const data = res.data;
for(let key in data){
form[key] = data[key]
}
this.form.dateRange = [form.startTime, form.endTime];
this.areaCode = form.areaCode
this.restainFenceName = form.electricFenceName;
this.form.msgtel = data.telNumbers
if(form.shapeType === 2){
this.mapData = {
fenceType: 'circle',
lng: form.lng,
lat: form.lat,
radius: form.radius,
}
}else if(form.shapeType === 3){
this.mapData = {
fenceType: 'area',
areaCode: this.form.areaCode
}
}else if(form.shapeType === 5){
if(data.lnglat){
this.polygonPath = data.lnglat.split('|').map((item)=>{
return [item.split(',')[0], item.split(',')[1]]
})
}
console.log(this.polygonPath)
this.mapData = {
fenceType: 'polygon',
polygonPath: this.polygonPath
}
}
this.$refs.fenceMap.initFence(this.mapData);
}
});
},
getFenceSnsList(id,cur){
let params = {};
if(this.currentPage>this.maxPage){
return;
}
if(cur){
params.currentPage =cur;
params.pageSize = this.pageSize;
}else{
params.currentPage =this.currentPage;
params.pageSize = this.pageSize;
}
params.id=id;
MONITOR_SERVICE.getFenceSnsList(params).then((res)=>{
if(res.draw == 0){
this.tableData = this.tableData.concat(res.data);
this.maxPage = Math.ceil(res.recordsTotal/this.pageSize);
this.$refs.userList.reset(res.data);
}
});
},
updateMapData() {
}
}
}
</script>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!