map.vue 2.2 KB
<template>
    <div class="testMap">
        <div class="mapTools">
            <mapTools :viewId="viewId"></mapTools>
        </div>
        <EsriMap :viewId = "viewId" :afterLoaderFunction="addLayer"></EsriMap>
    </div>
</template>
<script>
import EsriMap from '@/components/map/EsriMap'
import MapTools from './mapWeight/mapTools'
import {loadModules} from 'esri-loader'
import {maps} from '@/libs/map/mapUtils'
import mapLayerManager from "./mapWeight/js/mapLayerManager";
export default {
    components:{
        EsriMap,
        MapTools
    },
    data(){
        return{
            viewId:"testMap",
            layerUrl:"http://192.168.2.201:6080/arcgis/rest/services/%E4%BA%92%E8%81%94%E7%BD%91%E5%8A%A0%E4%B8%8D%E5%8A%A8%E4%BA%A7/XA_%E4%B8%8D%E5%8A%A8%E4%BA%A7/MapServer"
        }
    },
    mixins:[mapLayerManager],
    mounted(){
      var query = this.$route.query;
      if(query && JSON.stringify(query) != "{}"){
        this.addGeoByBsm(query.bsm,query.type,this.viewId);
      }
    },
    methods:{
        addLayer(){
            var self = this;
            var view = maps[this.viewId];
            loadModules([
                "esri/layers/MapImageLayer",
            ]).then(([
                MapImageLayer,
                ])=>{
                var mapImageLayer = new MapImageLayer({
                    url:self.layerUrl,
                    id:"testLayer",
                    spatialReference:view.spatialReference,
                    sublayers:[{
                        id:19,
                        visible:true
                    },
                        {
                            id:8,
                            visible:true
                        },
                        {
                            id:10,
                            visible:true
                        }]
                });
                view.map.add(mapImageLayer,1);
            }).catch(err => {
                throw(err);
            })
        }

    }
}
</script>
<style scoped lang="less">
  .testMap{
      height: 100%;
      width: 100%;
      position: relative;
      .mapTools{
              position: absolute;
            top: 12px;
            z-index: 99;
            right: 5px;
      }
  }
</style>