EsriMap.vue 3.83 KB
<template>
  <div class="map">
    <div :id="viewId" class="viewDiv">
    </div>
	<div class="mapViewPoint">
		<!-- <span class="key">比例尺:</span> -->
		<div class="viewScale"><span class="value">{{ mapInfo.scale }}公里</span></div>
		<span class="key">X坐标</span>
		<span class="value">{{ mapInfo.x }}</span>
		<span class="key">Y坐标</span>
		<span class="value">{{ mapInfo.y }}</span>
	</div>
  </div>  
</template>
<script>
    import {loadModules} from 'esri-loader'
    import {maps} from '@/libs/map/mapUtils'
    export default {
        props:{
            viewId:{
                type:String,
                default:"mainView"
            },
            afterLoaderFunction:{
                type:Function,
                default:null
            }
        },
        data(){
              return{
                mapInfo:{
					  scale:"",
					  x:"",
					  y:''
					}
               }
            },

            mounted(){
                this.initMap();
            },
            methods:{
                initMap(){
                    var self = this;
                    loadModules([
                        "esri/views/MapView",
                        "esri/Map"
                    ]).then(([
                        MapView,
                        esriMap
                    ]) => {
                        var map = new esriMap({
                            basemap:"osm"
                        });
                        //108.95	34.27	
                        var view = new MapView({
                            container: self.viewId,
                            map: map,
                            zoom:10,
                            center: [-0.154133333770497,0.6138183594020817],
                                spatialReference: {
                                    wkid: 102100
                                   }
                          });
                        maps[self.viewId] = view; 
                        if(self.afterLoaderFunction && typeof self.afterLoaderFunction == 'function'){
                            self.afterLoaderFunction(view);
                        }
						view.on("pointer-move", function(event){
							var point = view.toMap({x: event.x, y: event.y});
							self.mapInfo.x = point.longitude.toFixed(6);
							self.mapInfo.y = point.latitude.toFixed(6);
							self.mapInfo.scale = (view.scale/1000).toFixed(0);
							
						});
                    }).catch(err => {
                        throw(err);
                    });
                }
            }

    }
</script>
<style scoped lang="less">
  .map{
      height: 100%;
      width: 100%;
      .viewDiv{
          height: 100%;
          width: 100%;
          }
		  .mapViewPoint{
			      display: inline-flex;
			      position: absolute;
			      bottom: 10px;
			      left: 5px;
				  line-height: 12px;
				  .value{
					  margin-left: 0px;
				  }
				  span{
					  margin:0px 5px;
					  font-family: SFUIDisplay-Medium;
					  font-size: 12px;
					  color: #4A4A4A;
					  font-weight: bold;
					  letter-spacing: 0;
					  text-shadow: 0 -1px 0 #FFFFFF;
					  position: relative;
					  bottom: 9px;
				  }
				  .viewScale{
					   width: auto;
					     background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANIAAAAOCAYAAABaZUIWAAAABGdBTUEAALGPC/xhBQAAADhlWElmTU0AKgAAAAgAAYdpAAQAAAABAAAAGgAAAAAAAqACAAQAAAABAAAA0qADAAQAAAABAAAADgAAAAD7u0TwAAAA4ElEQVRoBe3a4QnCMBCG4UQcpKPU39kpq8UFsoObxBzVH6WeNHBQ2nsDFYlH4j3lI1QMoY/WWumXNorUMBDwKtCDUbRwyGficvOKQ98IWAqsglRrfaWUglzy3nIj1kLg7AL/8rEK0tkb5fsjcJQAQTpKnn0vJXDf0c0sD1o76ihBwK0AJ5LbW0/jlgLqiZRzniw3Yi0ELiAwaT1wImkyzCMwIECQBrAoRUAT+BUkfljQtJhHYBHYZCTK/OdvDvNSwysCCAwIPGOMj++JtEnYwEKUIuBVQHJDdrzeffq2F3gDSn1fbXNQA8oAAAAASUVORK5CYII=) top no-repeat;
					     background-size: contain;
					     background-position-y: 6px;
						 span{
							  margin: 0px 21px;
						 }
				  }
		  }
  }
</style>