派生自 wuyushui/SewerAndRainNetwork

陈泽平
2021-05-29 c42c548a635e7086f6cffc132625c5c7902b63b5
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
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* 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 = 5
  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 = clone(feature.geometry.coordinates)
  var latlng = []
  for (var j = 0; j < coordinates.length; j++) {
    let coordinate = coordinates[j]
    coordinate = [coordinate[1], coordinate[0]]
    latlng.push(coordinate)
  }
  return latlng
}
 
export function reverseMultiLine (feature) {
  const coordinates = clone(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++) {
      let coor = coordinate[k]
      if (coor.length > 2) {
        coor = coor.splice(2, 1)
      }
      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()
      }
    }
  }
}
 
/**
 * 去掉两头空格
 * @param str
 * @returns {*}
 */
export function lrtrim (str) {
  return str.replace(/^\s+|\s+$/g, '')
}
 
export default clone