派生自 wuyushui/SewerAndRainNetwork

徐旺旺
2021-05-18 755baaf11dd4e5c8eb7a5c2aa0ea23732fe47c85
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* url 目标url
* arg 需要替换的参数名称
* arg_val 替换后的参数的值
* return url 参数替换后的url
*/
export function changeURLArg (url, arg, argValue) {
  var pattern = arg + '=([^&]*)'
  var replaceText = arg + '=' + argValue
  if (url.match(pattern)) {
    var tmp = '/(' + arg + '=)([^&]*)/gi'
    // eslint-disable-next-line no-eval
    tmp = url.replace(eval(tmp), replaceText)
    return tmp
  } else {
    if (url.match('[\\?]')) {
      return url + '&' + replaceText
    } else {
      return url + '?' + replaceText
    }
  }
  // eslint-disable-next-line no-unreachable
  return url + '\n' + arg + '\n' + argValue
}
 
/**
 * 脉冲效果
 */
export function pulseEffect (xy) {
  let times = 1000
  const colors = ['#00f100', '#ff0000']
  // 插件 效果实现
  var pulsingIcon = window.L.icon.pulse({
    iconSize: [30, 30],
    color: colors[0],
    fillColor: ''
  })
  var picGroupMarker = window.L.marker(xy, { icon: pulsingIcon }).addTo(window.mapManager.hightlightLayer)
  // 定时
  var timeInterval = setInterval(() => {
    if (times > 0) {
      times--
    } else {
      clearInterval(timeInterval)
      picGroupMarker.remove()
    }
  }, 1000)
}
 
export function 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
}
 
export function 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
}
 
/**
 * 设置弹窗平移位置
 * @param pos
 * @param value
 */
export function setPanTo (pos, value) {
  var position = pos
  position = window.map.latLngToLayerPoint(position)
  position.y += value
  position = window.map.layerPointToLatLng(position)
  window.map.flyTo(position)
}
 
/**
 * 复制对象
 * @param obj
 * @returns {{}}
 */
export function clone (obj) {
  var o
  // 如果  他是对象object的话  , 因为null,object,array  也是'object';
  if (typeof obj === 'object') {
    // 如果  他是空的话
    if (obj === null) {
      o = null
    } else {
      // 如果  他是数组arr的话
      if (obj instanceof Array) {
        o = []
        for (var i = 0, len = obj.length; i < len; i++) {
          o.push(clone(obj[i]))
        }
      } else {
        // 如果  他是对象object的话
        o = {}
        for (var j in obj) {
          o[j] = clone(obj[j])
        }
      }
    }
  } else {
    o = obj
  }
  return o
}
 
/**
 *
 * 设置index,线在最下面,点在上面
 * @param layerGroup 图层组
 */
export function setZIndex (layer) {
  if (Array.isArray(layer)) {
    for (var i = 0; i < layer.length; i++) {
      setZIndex(layer[i])
    }
  } else {
    if (layer.getLayers) {
      setZIndex(layer.getLayers())
    } else {
      if (layer.feature && (layer.feature.geometry.type === 'LineString' || layer.feature.geometry.type === 'MultiLineString')) {
        layer.bringToBack && layer.bringToBack()
      } else {
        layer.bringToFront && layer.bringToFront()
      }
    }
  }
}
 
export default clone