
<template>
<div class="app-container">
<div id="container">div>
div>
template>
<script setup>
import AMapLoader from '@amap/amap-jsapi-loader';
import { shallowRef } from '@vue/reactivity';
import { ref, reactive} from "vue";
import geojsonData from '../assets/huzhou_division'
const allMap = shallowRef(null);
function initMap() {
window._AMapSecurityConfig = {
securityJsCode: '',
}
AMapLoader.load({
key: "",
version: "2.0",
plugins: ["AMap.GeoJSON"],
}).then((AMap) => {
const map = new AMap.Map("container", {
viewMode: "2D",
zoom: 10,
center: [119.898881, 30.594178],
mapStyle: 'amap://styles/',
});
allMap.value = map
const geoJson = new AMap.GeoJSON({
geoJSON: geojsonData,
getPolygon: function (geojson, lnglats) {
return new AMap.Polygon({
path: lnglats,
strokeColor: 'rgba(230, 230, 254, 0.5)',
fillColor: '#0E465A',
strokeWeight: 2,
strokeColor: '#2FD7D7',
strokeStyle: 'dashed'
})
},
})
map.add(geoJson)
const markerdata = reactive([[119.898881, 30.794178], [119.998881, 30.794178], [119.798881, 30.794178], [119.698881, 30.794178], [120.098881, 30.794178]])
markerdata.forEach(element => {
const icon = new AMap.Icon({
size: new AMap.Size(50, 60),
image: new URL('../assets/images/压力表.png', import.meta.url).href,
imageSize: new AMap.Size(50, 60),
imageOffset: new AMap.Pixel(0, 0)
});
const marker = new AMap.Marker({
position: new AMap.LngLat(element[0], element[1]),
icon: icon
});
marker.content = proxy.$refs.dialog
map.add(marker);
});
}).catch(e => {
console.log(e);
})
}
initMap()
script>
<style lang="scss" scoped>
.app-container {
position: absolute;
top: 0;
left: 0;
z-index: -1;
}
#container {
padding: 0px;
margin: 0px;
width: 1920px;
height: 1080px;
}
style>