修改电子围栏

master
夜笙歌 2 years ago
parent 3dc23a0bb5
commit 70d2f638c3

@ -24,12 +24,13 @@
<el-form-item label=" "> <el-form-item label=" ">
<el-button icon="Search" type="primary" @click="handleQuery">{{ t('option.search') }}</el-button> <el-button icon="Search" type="primary" @click="handleQuery">{{ t('option.search') }}</el-button>
<el-button icon="Refresh" @click="resetQuery">{{ t('option.reset') }}</el-button> <el-button icon="Refresh" @click="resetQuery">{{ t('option.reset') }}</el-button>
<el-button icon="Refresh" @click="getLine"></el-button>
</el-form-item> </el-form-item>
</el-form> </el-form>
<el-button class="add" @click="createPolygon"></el-button>
<el-button class="clear" @click="clearPolygon"></el-button>
<el-button class="clear" type="primary" @click="getLine"></el-button>
<div id="container4"></div> <div id="container4"></div>
<el-button class="add" @click="createPolygon"></el-button>
</div> </div>
</template> </template>
<script setup> <script setup>
@ -45,9 +46,12 @@ const {proxy} = getCurrentInstance();
const queryParams = ref({}) const queryParams = ref({})
let map = null let map = null
let polyEditor = null
let path = [[116.390969, 39.911592], [116.391496, 39.909008], [116.389264, 39.909765], [116.38802, 39.911016]] let path = [[116.390969, 39.911592], [116.391496, 39.909008], [116.389264, 39.909765], [116.38802, 39.911016]]
let path1 = [[116.391969, 39.912592], [116.392496, 39.910008], [116.390264, 39.910765], [116.38902, 39.912016]]
const areaPath = ref([path]) const areaPath = ref([path])
const marketPath = ref([[116.390669, 39.911147],[116.400669, 39.921147]]) const areaPath1 = ref([path1])
const marketPath = ref([[116.390669, 39.911147], [116.400669, 39.921147]])
AMapLoader.load({ AMapLoader.load({
key: "ba8fb8d8bae1b280b93406d5959d492f", // WebKey load key: "ba8fb8d8bae1b280b93406d5959d492f", // WebKey load
// version: "1.4.15", // // version: "1.4.15", //
@ -78,99 +82,99 @@ AMapLoader.load({
map.addControl(new AMap.MapType()); map.addControl(new AMap.MapType());
setPolygon(areaPath.value) // setPolygon(areaPath.value)
setMarker(marketPath.value) // setMarker(marketPath.value)
}).catch(e => { }).catch(e => {
console.log(e); console.log(e);
}) })
const setMarker = (e)=>{
let markers = map.getAllOverlays('marker'); let one = true
const handleQuery = () => {
clearPolygon()
if (one) {
setPolygon(areaPath.value)
} else {
setPolygon(areaPath1.value)
}
setMarker(marketPath.value)
one = !one
}
const setMarker = (e) => {
let markers = map.getAllOverlays('marker');
map.remove(markers) map.remove(markers)
e.forEach(val=>{ let polygons = map.getAllOverlays('polygon');
let list = polygons.map(e => e._opts.path)
e.forEach(val => {
let marker = new AMap.Marker({ let marker = new AMap.Marker({
position: val, position: val,
anchor: 'bottom-center', anchor: 'bottom-center',
offset: new AMap.Pixel(0, 0) offset: new AMap.Pixel(0, 0)
}); });
marker.setTitle('我是marker的title'); marker.setTitle('我是marker的title');
console.log((areaPath.value))
let isPointInRing = false let isPointInRing = false
areaPath.value.forEach(res=>{ list.forEach(res => {
if(AMap.GeometryUtil.isPointInRing(val, res)){ if (AMap.GeometryUtil.isPointInRing(val, res)) {
isPointInRing=true isPointInRing = true
} }
}) })
marker.setLabel({ marker.setLabel({
direction: 'top', direction: 'top',
offset: new AMap.Pixel(0, -10), // offset: new AMap.Pixel(0, -10), //
content: "" +isPointInRing, content: "" + isPointInRing,
}); });
marker.setMap(map); marker.setMap(map);
}) })
} }
const createPolygon = () => {
polyEditor.close();
polyEditor.setTarget();
polyEditor.open()
}
const clearPolygon = () => {
if (!polyEditor) return
polyEditor.close();
let polygons = map.getAllOverlays('polygon');
map.remove(polygons)
}
const setPolygon = (res) => { const setPolygon = (res) => {
res.forEach((e, index) => { let polygonArr = []
let polygon = new AMap.Polygon({path: e}); res.forEach(val => {
map.add([polygon]); let thisPolygon = new AMap.Polygon({path: val});
let polyEditor = new AMap.PolygonEditor(map); polygonArr.push(thisPolygon)
polyEditor.addAdsorbPolygons([polygon]); thisPolygon.on('dblclick', () => {
polygon.on('dblclick', () => { polyEditor.setTarget(thisPolygon);
polyEditor.setTarget(polygon);
polyEditor.open(); polyEditor.open();
}) })
polyEditor.on('addnode', function (data) {
//
areaPath.value[index] = polyEditor.getTarget()._opts.path
setMarker(marketPath.value)
})
polyEditor.on('adjust', function (data) {
//
areaPath.value[index] = polyEditor.getTarget()._opts.path
setMarker(marketPath.value)
})
})
setMarker(marketPath.value)
}
const removePolygon = () =>{
let polygons = map.getAllOverlays('polygon');
console.log('s',polygons)
polygons.forEach(e=>{
// e.close()
}) })
} map.add(polygonArr)
let createPolygon = () => { polyEditor = new AMap.PolygonEditor(map);
let arr = [] polyEditor.addAdsorbPolygons(polygonArr);
map.add([new AMap.Polygon({path: arr})]);
let polyEditor = new AMap.PolygonEditor(map)
let index = areaPath.value.length
polyEditor.close();
polyEditor.setTarget();
polyEditor.open();
polyEditor.on('add', function (data) { polyEditor.on('add', function (data) {
areaPath.value.push(data.target._opts.path) let polygon = data.target;
// polyEditor.close(); polyEditor.addAdsorbPolygons(polygon);
// map.clearMap() polygon.on('dblclick', () => {
// removePolygon() polyEditor.setTarget(polygon);
// setPolygon([data.target._opts.path]) polyEditor.open();
})
}) })
polyEditor.on('addnode', function (data) { polyEditor.on('addnode', function (data) {
// console.log('addnode', data)
areaPath.value[index] = polyEditor.getTarget()._opts.path
setMarker(marketPath.value) setMarker(marketPath.value)
}) })
polyEditor.on('adjust', function (data) { polyEditor.on('adjust', function (data) {
// console.log('adjust', data)
areaPath.value[index] = polyEditor.getTarget()._opts.path
setMarker(marketPath.value) setMarker(marketPath.value)
}) })
map.setFitView();
} }
const getLine = () => { const getLine = () => {
let list = areaPath.value let polygons = map.getAllOverlays('polygon');
let list = polygons.map(e => e._opts.path)
let params = [] let params = []
list.forEach((e, index) => { list.forEach((e, index) => {
e.forEach(val => { e.forEach(val => {
@ -189,12 +193,13 @@ const getLine = () => {
padding: 0px; padding: 0px;
margin: 20px 0 0 0; margin: 20px 0 0 0;
width: 100%; width: 100%;
height: calc(100vh - 190px); height: calc(100vh - 220px);
} }
.add { .add {
position: absolute; margin-left: 30px;
bottom: 15px; }
right: 150px;
.clear {
} }
</style> </style>

Loading…
Cancel
Save