123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <style lang='scss' scoped>
- .mapContent {
- position: relative;
- height: 95%;
- transition: 0.5s;
- .center-add {
- position: absolute;
- top: 0;
- bottom: 0;
- left: 0;
- right: 0;
- margin: auto;
- z-index: 999;
- width: 30px;
- height: 30px;
- }
- }
- #mapContainer {
- width: 100%;
- height: 100%;
- }
- .amap-info-close {
- display: none !important;
- }
- </style>
- <template>
- <div class="mapContent">
- <div id="mapContainer"></div>
- </div>
- </template>
- <script>
- import {
- regionData,
- CodeToText,
- TextToCode
- } from 'element-china-area-data'
- import image from '../../../public/img/ic_locationmarker.jpg'
- import AMapLoader from '@amap/amap-jsapi-loader';
- export default {
- data() {
- return {
- map: null,
- marker: null,
- markers: [],
- zoomEnable: true,
- dragEnable: true,
- status: true,
- }
- },
- props: [
- 'listData'
- ],
- computed: {},
- watch: {
- listData: function(val1, val2) {
- this.listData = val1
- var that = this
- this.map = new AMap.Map('mapContainer', {
- resizeEnable: true,
- zoom: 5,
- center: [103.809074, 36.051121],
- zoomEnable: this.zoomEnable,
- dragEnable: this.dragEnable
- })
- this.loadmap()
- }
- },
- async created() {
- // AMapLoader.reset();
- // 已载入高德地图API,则直接初始化地图
- if (window.AMap && window.AMapUI) {
- this.initMap()
- // 未载入高德地图API,则先载入API再初始化
- } else {
- await remoteLoad(`http://webapi.amap.com/maps?v=1.3&key=${MapKey}&plugin=AMap.AutoComplete`)
- await remoteLoad('http://webapi.amap.com/ui/1.0/main.js')
- this.initMap()
- }
- },
- mounted() {},
- methods: {
- makeMarkersList() {
- let _list = this.listData
- for (let i = 0; i < _list.length; i++) {
- _list[i].marker = []
- _list[i].marker.push(_list[i].warehousePositioning.split(',')[1])
- _list[i].marker.push(_list[i].warehousePositioning.split(',')[0])
- }
- },
- loadmap(val) {
- let that = this
- //构造markersList
- this.makeMarkersList()
- AMap.plugin(['AMap.DistrictSearch', 'AMap.Polygon'], function() {
- var geolocation = new AMap.Geolocation({
- // 是否使用高精度定位,默认:true
- enableHighAccuracy: true, // 设置定位超时时间,默认:无穷大
- timeout: 10000, // 定位按钮的停靠位置的偏移量,默认:Pixel(10, 20)
- buttonOffset: new AMap.Pixel(10, 20), // 定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
- zoomToAccuracy: true, // 定位按钮的排放位置, RB表示右下
- buttonPosition: 'RB'
- })
- geolocation.getCurrentPosition()
- AMap.event.addListener(geolocation, 'complete', e => {
- console.log(e) // 定位成功之后做的事 // 定位成功之后再定位处添加一个marker
- var infoWindow = new AMap.InfoWindow({
- offset: new AMap.Pixel(0, -30)
- })
- function infoOpen(e) {
- infoWindow.setContent(e.target.content)
- infoWindow.open(that.map, e.target.getPosition())
- }
- function infoClose(e) {
- infoWindow.close(that.map, e.target.getPosition())
- }
- function toGetList(e) {
- // console.log(e.target.getExtData())
- that.$parent.getList(e.target.getExtData().id, 1)
- }
- for (let i = 0; i < that.listData.length; i++) {
- var marker = new AMap.Marker({
- map: that.map,
- position: that.listData[i]
- .marker, // marker最终显示在那个点上,
- icon: new AMap.Icon({
- image: "https://taohaoliang.oss-cn-beijing.aliyuncs.com/pcfiles/home_pic.png",
- size: new AMap.Size(20, 20), //图标大小
- imageSize: new AMap.Size(20, 20),
- }),
- })
- marker.setExtData({
- 'id': that.listData[i].warehouseName
- })
- let _cwList = '<div class="cw-wrap">'
- for (let k = 0; k < that.listData[i].tradeWarehouseReceiptAppls.length; k++) {
- let _k = that.listData[i].tradeWarehouseReceiptAppls[k]
- _cwList += '<div style="display:flex">' +
- '<div style="margin:10px 20px">' + _k.warehouseNo + '仓位</div>' +
- '<div style="margin:10px 20px">' + _k.goodsName + '</div>' +
- '<div style="margin:10px 20px">' + _k.weight + '</div>' +
- '</div>'
- }
- _cwList = _cwList + '</div>'
- console.log('地图仓位数据', _cwList)
- marker.content = '<div style="display:flex;justify-content: center">' + that.listData[i]
- .warehouseName + '</div>' + _cwList + '</div>'
- marker.on('mouseover', infoOpen)
- marker.on('mouseout', infoClose)
- marker.on('click', toGetList)
- // 设置label标签
- // label默认蓝框白底左上角显示,样式className为:amap-marker-label
- // marker.setLabel({
- // offset: new AMap.Pixel(20, 20), //设置文本标注偏移量
- // content: "<div class='info'>我是 marker 的 label 标签</div>", //设置文本标注内容
- // direction: 'right' //设置文本标注方位
- // });
- }
- })
- AMap.event.addListener(geolocation, 'error', e => {
- console.log(e) // 定位失败
- })
- })
- }
- }
- }
- </script>
|