import mapConfig from "./mapConfig"; const mapServer = { listData: [], sourceType: null, init() {}, addServer(res) { this.remoServer(res); this.sourceType = res.sourceType; switch (this.sourceType) { case "arcgis": this.addArcgisServer(res); break; case "geoserver": this.addGeoServer(res); break; case "tms": this.addTmsLayer(res); break; } }, remoServer(res) { for (var i in this.listData) { const obj = this.listData[i]; if (obj.type == res.sourceType) { obj.layer.removeFromMap(); this.listData.splice(i, 1); } } }, addTmsLayer(res) { var layer = earthCtrl.factory.createImageryLayer({ sourceType: "tms", // url: "http://test.smartearth.cn:9037/gisserver/tmsserver/SubicBayArea" url: res.url }); this.listData.push({ layer: layer, type: this.sourceType }); mapConfig.flyToImageryLayer(layer); }, addArcgisServer(res) { const layer = earthCtrl.factory.createImageryLayer({ sourceType: "arcgis", url: res.url }); this.listData.push({ layer: layer, type: this.sourceType }); }, addGeoServer(res) { const layer = earthCtrl.factory.createWfsLayer("polygon", { urls: res.url, layer: res.layerF, color: "#de3", extrudedHeight: 30 // 拉伸高度,无拉伸高度则为贴地面 }); this.listData.push({ layer: layer, type: this.sourceType }); } }; export default mapServer;