import { pulseEffect, reversePolyLine } from '../../utils/utils'
|
|
/**
|
* 根据传的 feature对象定位,
|
* @param code
|
* @param feature
|
*/
|
export const fitBounds = function (feature) {
|
const type = feature.geometry.type
|
switch (type) {
|
case 'Point':
|
var point = feature.geometry.coordinates
|
point = [point[1], point[0]]
|
window.map.setView(point, 17)
|
break
|
case 'MultiLineString':
|
window.map.fitBounds(window.L.geoJSON(feature).getBounds())
|
break
|
case 'LineString':
|
window.map.fitBounds(window.L.polyline(reversePolyLine(feature)).getBounds())
|
break
|
}
|
}
|
|
export const highlight = function (feature, config) {
|
const L = window.L
|
const type = feature.geometry.type
|
const highlightLayer = window.mapManager.hightlightLayer
|
if (type === 'MultiLineString') {
|
L.geoJSON(feature, {
|
style: function () {
|
return {
|
fillColor: 'red',
|
color: 'red'
|
}
|
}
|
}).addTo(highlightLayer)
|
} else if (type === 'Point') {
|
// 叠加一个大尺寸的图标
|
let point = feature.geometry.coordinates
|
point = [point[1], point[0]]
|
|
if (config) {
|
L.marker(point, {
|
icon: L.icon({
|
iconUrl: '/assets/images/map/' + config.icon,
|
iconSize: [30, 30],
|
iconAnchor: [15, 15]
|
})
|
}).addTo(highlightLayer)
|
}
|
pulseEffect(point)
|
} else if (type === 'LineString') {
|
L.polyline(reversePolyLine(feature), { color: 'red' }).addTo(highlightLayer)
|
}
|
}
|
|
export const openPopup = function (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
|
}
|
}
|
})
|
}
|
return null
|
}
|
|
export const getLayer = function (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
|
if (feature.id === id) {
|
return lay
|
}
|
}
|
})
|
}
|
return null
|
}
|