EsriMap.vue 3.03 KB
<template>
  <div class="map">
    <div :id="viewId" class="viewDiv">
    </div>
	<div class="mapViewPoint">
		<span class="key">比例尺:</span>
		<span class="value">{{ mapInfo.scale }}km</span>
		<span class="key">经度:</span>
		<span class="value">{{ mapInfo.x }}</span>
		<span class="key">纬度:</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(3);
							
						});
                    }).catch(err => {
                        throw(err);
                    });
                }
            }

    }
</script>
<style scoped lang="less">
  .map{
      height: 100%;
      width: 100%;
      .viewDiv{
          height: 100%;
          width: 100%;
          }
		  .mapViewPoint{
			      position: absolute;
			      bottom: 10px;
			      left: 5px;
			      background-color: white;
			      line-height: 36px;
			      font-size: 12px;
			      border-radius: 4px;
				  box-shadow: 0px 1px 1px 1px rgba(0, 0, 0, 0.18);
				  .key{
					  font-weight: 600;
				  }
				  .value{
					  margin-left: 0px;
				  }
				  span{
					  margin:0px 5px;
				  }
		  }
  }
</style>