| | |
| | | import WfsLayerService from './WfsLayerService' |
| | | import { clone } from '../../../utils/utils' |
| | | import { logicMapper, SERVICE_TYPE } from '../../../conf/Constants' |
| | | import WmsLayerService from './WmsLayerService' |
| | | import AnimalService from './AnimalService' |
| | | |
| | | /** |
| | | * init 只初始化一次 |
| | |
| | | this.layersLogic = {} |
| | | this.minZoomLayers = {} |
| | | this.wmsLayers = [] |
| | | this.clickSwitch = true // 图层点击弹窗开关 |
| | | this.animalService = new AnimalService({ L: this.L }) |
| | | this.hightlightLayer = options.L.featureGroup({}).addTo(window.map) |
| | | this.wmsLayerService = null |
| | | } |
| | | |
| | | init (layerConfig) { |
| | | this.initConfig(layerConfig) |
| | | // wms服务只需要初始化一次 |
| | | this.wmsLayerService = new WmsLayerService(this.wmsLayers) |
| | | this.wmsLayerService = new WmsLayerService() |
| | | this.wmsLayerService.init() |
| | | this.initConfig(layerConfig) |
| | | } |
| | | |
| | | initConfig (layerConfig) { |
| | |
| | | wmsGroupLayerService.init() |
| | | continue |
| | | } */ |
| | | layers && this.init(config.layers) |
| | | childLayer && this.init(config.childLayer) |
| | | layers && this.initConfig(config.layers) |
| | | childLayer && this.initConfig(config.childLayer) |
| | | |
| | | this.initMinZoom(config) |
| | | this.loadLogic(config) |
| | |
| | | logic = new BusiLayer() |
| | | } else if (type === SERVICE_TYPE.WFS) { |
| | | logic = new WfsLayerService(config) |
| | | } else if (type === SERVICE_TYPE.WMS) { |
| | | var layer = {} |
| | | layer[config.code] = config |
| | | this.wmsLayers.push(layer) |
| | | } |
| | | } |
| | | this.layersLogic[code] = logic |
| | |
| | | return layer |
| | | } |
| | | |
| | | showAll (configs) { |
| | | if (Array.isArray(configs)) { |
| | | for (let i = 0; i < configs.length; i++) { |
| | | const config = configs[i] |
| | | this.show(config) |
| | | } |
| | | this.wmsLayerService && this.wmsLayerService.addAll(configs) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 如果 存在已经加载了的对象,就直接加到map |
| | | * 如果 不存在则 调用 addLayer 及 逻辑类的init 进行初始化操作 |
| | |
| | | } |
| | | logic && logic.start && logic.start() |
| | | this.wmsLayerService && this.wmsLayerService.add(config) |
| | | } |
| | | |
| | | hideAll (configs) { |
| | | if (Array.isArray(configs)) { |
| | | for (let i = 0; i < configs.length; i++) { |
| | | this.hide(configs[i]) |
| | | } |
| | | this.wmsLayerService && this.wmsLayerService.removeAll(configs) |
| | | } |
| | | } |
| | | |
| | | hide (config) { |
| | |
| | | this.hide(config) |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * |
| | | * 根据传的 feature对象定位, |
| | | * @param code |
| | | * @param feature |
| | | */ |
| | | flyByFeature (feature, code) { |
| | | this.clearHighlight() |
| | | const type = feature.geometry.type |
| | | var point = [] |
| | | switch (type) { |
| | | case 'Point': |
| | | point = feature.geometry.coordinates |
| | | break |
| | | case 'MultiLineString': |
| | | var coordinates = feature.geometry.coordinates |
| | | var coordinate = coordinates[parseInt(coordinates.length / 2)][0] |
| | | if (coordinate.length > 2) { |
| | | point = [coordinate[0], coordinate[1]] |
| | | } |
| | | break |
| | | case 'LineString': |
| | | var lineString = feature.geometry.coordinates |
| | | point = lineString[parseInt(lineString.length / 2)][0] |
| | | break |
| | | } |
| | | if (point.length > 2) { |
| | | point.splice(2, 1) |
| | | } |
| | | this.highlight(feature) |
| | | window.map.setView(clone(point).reverse(), 17) |
| | | code && this.openPopup(code, feature.id) |
| | | } |
| | | |
| | | clearHighlight () { |
| | | this.hightlightLayer.clearLayers() |
| | | } |
| | | |
| | | highlight (feature) { |
| | | const type = feature.geometry.type |
| | | if (type === 'MultiLineString') { |
| | | this.L.geoJSON(feature, { |
| | | style: function () { |
| | | return { |
| | | fillColor: 'red', |
| | | color: 'red' |
| | | } |
| | | } |
| | | }).addTo(this.hightlightLayer) |
| | | } else if (type === 'Point') { |
| | | let point = clone(feature.geometry.coordinates) |
| | | if (point.length > 2) { |
| | | point = [point[0], point[1]] |
| | | } |
| | | this.animalService.pulseEffect(point.reverse()) |
| | | /* var myIcon = this.L.divIcon({ className: 'my-div-icon' }) |
| | | this.L.marker(feature.geometry.coordinates.reverse(), { |
| | | icon: myIcon |
| | | }).addTo(this.hightlightLayer) */ |
| | | } else if (type === 'LineString') { |
| | | this.L.polyline(this.reversePolyLine(feature), { color: 'red' }).addTo(this.hightlightLayer) |
| | | } |
| | | } |
| | | |
| | | reverseMultiLine (feature) { |
| | | const coordinates = feature.geometry.coordinates |
| | | var latlng = [] |
| | | for (var j = 0; j < coordinates.length; j++) { |
| | | const coordinate = coordinates[j] |
| | | var xy = [] |
| | | for (var k = 0; k < coordinate.length; k++) { |
| | | const coor = coordinate[k] |
| | | xy.push(coor.reverse()) |
| | | } |
| | | latlng.push(xy) |
| | | } |
| | | return latlng |
| | | } |
| | | |
| | | reversePolyLine (feature) { |
| | | const coordinates = feature.geometry.coordinates |
| | | var latlng = [] |
| | | for (var j = 0; j < coordinates.length; j++) { |
| | | const coordinate = coordinates[j] |
| | | latlng.push(coordinate.reverse()) |
| | | } |
| | | return latlng |
| | | } |
| | | |
| | | openPopup (layerId, id) { |
| | | const layer = this.layers[layerId] |
| | | |
| | | if (layer) { |
| | | layer.eachLayer(function (layer) { |
| | | const layers = layer.getLayers() |
| | | for (var i = 0; i < layers.length; i++) { |
| | | const lay = layers[i] |
| | | const feature = lay.feature |
| | | lay.closePopup() |
| | | if (feature.id === id) { |
| | | lay.openPopup() |
| | | break |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | /* for (var k in this.layers) { |
| | | var layerGroup = this.layers[k] |
| | | layerGroup.eachLayer(function (layer) { |
| | | console.log(layer) |
| | | console.log(layer.getAttribution()) |
| | | }) |
| | | var layers = layerGroup.getLayers() |
| | | if (layers) { |
| | | for (var m = 0; m < layers.length; m++) { |
| | | var layer = layers[m] |
| | | console.log(layer) |
| | | console.log(layer.getLayerId(val.id)) |
| | | /!* var feature = layer.feature |
| | | if (feature.id === layerId) { |
| | | this.map.flyToBounds(bound) |
| | | return layer |
| | | } *!/ |
| | | } |
| | | } |
| | | } */ |
| | | return null |
| | | } |
| | | |
| | | findLayerById (layer, id) { |
| | | const layers = layer.getLayers |
| | | if (layers) { |
| | | this.findLayerById(layer.getLayers(), id) |
| | | } else { |
| | | layer.eachLayer(function (layer) { |
| | | // console.log(layer) |
| | | }) |
| | | } |
| | | } |
| | | } |