|
|
|
@ -29,6 +29,7 @@
|
|
|
|
|
</el-form>
|
|
|
|
|
|
|
|
|
|
<div id="container4"></div>
|
|
|
|
|
<el-button class="add" @click="createPolygon">新建</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
<script setup>
|
|
|
|
@ -43,12 +44,10 @@ const locale = (Cookies.get('language') || 'zhCn') === 'zhCn'
|
|
|
|
|
const {proxy} = getCurrentInstance();
|
|
|
|
|
const queryParams = ref({})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let map = null
|
|
|
|
|
let path = [[116.390969, 39.911592], [116.391496, 39.909008], [116.389264, 39.909765], [116.38802, 39.911016]]
|
|
|
|
|
let path2 = [[116.400969, 39.921592], [116.401496, 39.919008], [116.399264, 39.919765], [116.39802, 39.921016]]
|
|
|
|
|
const areaPath = ref([path,path2])
|
|
|
|
|
let marketPath = [116.390669, 39.911147]
|
|
|
|
|
const areaPath = ref([path])
|
|
|
|
|
const marketPath = ref([[116.390669, 39.911147],[116.400669, 39.921147]])
|
|
|
|
|
AMapLoader.load({
|
|
|
|
|
key: "ba8fb8d8bae1b280b93406d5959d492f", // 申请好的Web端开发者Key,首次调用 load 时必填
|
|
|
|
|
// version: "1.4.15", //
|
|
|
|
@ -66,19 +65,6 @@ AMapLoader.load({
|
|
|
|
|
center: [116.397428, 39.90923], //初始化地图中心点位置
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
let marker = new AMap.Marker({
|
|
|
|
|
position: marketPath,
|
|
|
|
|
anchor: 'bottom-center',
|
|
|
|
|
offset: new AMap.Pixel(0, 0)
|
|
|
|
|
});
|
|
|
|
|
marker.setTitle('我是marker的title');
|
|
|
|
|
marker.setLabel({
|
|
|
|
|
direction: 'top',
|
|
|
|
|
offset: new AMap.Pixel(0, -10), //设置文本标注偏移量
|
|
|
|
|
content: "" + AMap.GeometryUtil.isPointInRing(marketPath,path,path2),
|
|
|
|
|
});
|
|
|
|
|
marker.setMap(map);
|
|
|
|
|
|
|
|
|
|
// 在图面添加工具条控件,工具条控件集成了缩放、平移、定位等功能按钮在内的组合控件
|
|
|
|
|
map.addControl(new AMap.ToolBar({position: 'LT'}));
|
|
|
|
|
|
|
|
|
@ -91,33 +77,90 @@ AMapLoader.load({
|
|
|
|
|
// 在图面添加类别切换控件,实现默认图层与卫星图、实施交通图层之间切换的控制
|
|
|
|
|
map.addControl(new AMap.MapType());
|
|
|
|
|
|
|
|
|
|
areaPath.value.forEach( (e,index)=> {
|
|
|
|
|
|
|
|
|
|
setPolygon(areaPath.value)
|
|
|
|
|
setMarker(marketPath.value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}).catch(e => {
|
|
|
|
|
console.log(e);
|
|
|
|
|
})
|
|
|
|
|
const setMarker = (e)=>{
|
|
|
|
|
let markers = map.getAllOverlays('marker');
|
|
|
|
|
map.remove(markers)
|
|
|
|
|
e.forEach(val=>{
|
|
|
|
|
let marker = new AMap.Marker({
|
|
|
|
|
position: val,
|
|
|
|
|
anchor: 'bottom-center',
|
|
|
|
|
offset: new AMap.Pixel(0, 0)
|
|
|
|
|
});
|
|
|
|
|
marker.setTitle('我是marker的title');
|
|
|
|
|
console.log((areaPath.value))
|
|
|
|
|
let isPointInRing = false
|
|
|
|
|
areaPath.value.forEach(res=>{
|
|
|
|
|
if(AMap.GeometryUtil.isPointInRing(val, res)){
|
|
|
|
|
isPointInRing=true
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
marker.setLabel({
|
|
|
|
|
direction: 'top',
|
|
|
|
|
offset: new AMap.Pixel(0, -10), //设置文本标注偏移量
|
|
|
|
|
content: "" +isPointInRing,
|
|
|
|
|
});
|
|
|
|
|
marker.setMap(map);
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const setPolygon = (res) => {
|
|
|
|
|
res.forEach((e, index) => {
|
|
|
|
|
let polygon = new AMap.Polygon({path: e});
|
|
|
|
|
map.add([polygon]);
|
|
|
|
|
let polyEditor = new AMap.PolygonEditor(map);
|
|
|
|
|
polyEditor.addAdsorbPolygons([polygon]);
|
|
|
|
|
polyEditor.on('add', function (data) {
|
|
|
|
|
console.log(data);
|
|
|
|
|
let polygon = data.target;
|
|
|
|
|
polyEditor.addAdsorbPolygons(polygon);
|
|
|
|
|
polygon.on('dblclick', () => {
|
|
|
|
|
polyEditor.setTarget(polygon);
|
|
|
|
|
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)
|
|
|
|
|
})
|
|
|
|
|
polyEditor.setTarget(polygon);
|
|
|
|
|
polyEditor.open();
|
|
|
|
|
})
|
|
|
|
|
setMarker(marketPath.value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}).catch(e => {
|
|
|
|
|
console.log(e);
|
|
|
|
|
let createPolygon = () => {
|
|
|
|
|
let arr = []
|
|
|
|
|
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) {
|
|
|
|
|
areaPath.value.push(data.target._opts.path)
|
|
|
|
|
// polyEditor.close();
|
|
|
|
|
// map.clearMap()
|
|
|
|
|
setPolygon(areaPath.value)
|
|
|
|
|
})
|
|
|
|
|
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)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
const getLine = () => {
|
|
|
|
|
let list = areaPath.value
|
|
|
|
|
let params = []
|
|
|
|
@ -140,4 +183,10 @@ const getLine = () => {
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: calc(100vh - 190px);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.add {
|
|
|
|
|
position: absolute;
|
|
|
|
|
bottom: 15px;
|
|
|
|
|
right: 150px;
|
|
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|