| | |
| | | import { clone } from '../../../utils/utils' |
| | | import { logicMapper, SERVICE_TYPE } from '../../../conf/Constants' |
| | | import WmsLayerService from './WmsLayerService' |
| | | import AnimalService from './AnimalService' |
| | | |
| | | /** |
| | | * init 只初始化一次 |
| | |
| | | this.minZoomLayers = {} |
| | | this.wmsLayers = [] |
| | | this.clickSwitch = true // 图层点击弹窗开关 |
| | | this.animalService = new AnimalService({ L: this.L }) |
| | | this.hightlightLayer = options.L.featureGroup({}).addTo(window.map) |
| | | } |
| | | |
| | | init (layerConfig) { |
| | |
| | | * @param feature |
| | | */ |
| | | flyByFeature (feature, code) { |
| | | this.clearHighlight() |
| | | const type = feature.geometry.type |
| | | var point = [] |
| | | switch (type) { |
| | | case 'Point': |
| | | point = clone(feature.geometry.coordinates) |
| | | point = feature.geometry.coordinates |
| | | break |
| | | case 'MultiLineString': |
| | | var coordinates = feature.geometry.coordinates |
| | |
| | | if (point.length > 2) { |
| | | point.splice(2, 1) |
| | | } |
| | | window.map.setView(point.reverse(), 17) |
| | | 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.eachLayer) { |
| | | if (layer) { |
| | | layer.eachLayer(function (layer) { |
| | | const layers = layer.getLayers() |
| | | for (var i = 0; i < layers.length; i++) { |