/** * Created by cp on 2018/7/6. */ /** * Created by cp on 2018/7/2. */ // 定义类 修改地图基础图层类 import {BaseLayer} from '../layer/baseLayer'; import {FeatureStyle} from '../front/FeatureStyle'; import Tile from 'ol/layer/Tile'; import XYZ from 'ol/source/XYZ'; import OSM from 'ol/source/OSM'; import BingMaps from 'ol/source/BingMaps'; import {addProjection, transformExtent, transform} from 'ol/proj'; import ImageLayer from 'ol/layer/Image.js'; import Static from 'ol/source/ImageStatic.js'; import Projection from 'ol/proj/Projection.js'; import {getCenter} from 'ol/extent.js'; class ChangeBaseLayer { constructor(vueThis,objMap) { if(objMap.getMap()){ this.map=objMap.getMap();//地图 有可能传的是最外层的map this.objMap=objMap; }else{ this.map=objMap;//地图 } this.vm = vueThis;//类中变量 this.allLayers=[]; } chanegMapLayer(value){ if(value=="normalMap"){// 普通地图 this.showBaseLayerByName(["矢量图层"],true); } else if(value=="earth"){// earth地形图 this.showBaseLayerByName(["遥感图层","标注"],true); } else if(value=="panorama"){// 热度图 } } setImageLayer(extent,imageUrl,imageLayer){ if(imageLayer){ this.map.removeLayer(imageLayer); } imageLayer= new ImageLayer({ zIndex:1,//所有的图层默认都是0 如果想要区别开 其他图层都需要进行设置 source: new Static({ url: imageUrl, imageExtent: transformExtent(extent, 'EPSG:4326', 'EPSG:3857') }) }) imageLayer.setZIndex(1); this.map.addLayer(imageLayer); // this.objMap.setLimitCenter(getCenter(transformExtent(extent, 'EPSG:4326', 'EPSG:3857'))); this.objMap.setLimitExtent(transformExtent(extent, 'EPSG:4326', 'EPSG:3857')); return imageLayer; } //控制图层的显示影藏图层 图层名称 以及显示状态 isRemove 为true 是找到并且从系统中移除 /***修改图层显示隐藏 ,同时语句isremove确认是否删除底图****/ showBaseLayerByName(layerName,isRemoveBase){ var arrGroup=this.map.getLayerGroup().getLayers().getArray(); for(var j=0;j0){ let feItem=features[0]; let feExtent= feItem.getGeometry().getExtent(); this.map.getView().fit(feExtent, {duration:1000}) } } } removeFeatureFromLayer(layerId,featureId){ let layerItem=this.getLayerClassById(layerId); if(layerItem){ layerItem.removeFeatureById(featureId); } } getFeatureByLayerId(layerId,success,fail){ let layerFeature= new FeatureStyle(this.vm,null); layerFeature.setToken(this.vm.frontToken); layerFeature.getFeatureByLayerId(layerId,{},success,fail) } getLayerClassById(dataId){ let layerArr=this.allLayers; for(let i=0;i