` $(popupContent).html(str) overlay.setPosition(coordinate); flag = true; return; // } // }).catch((error) => { // console.log(error); // }) } let data = properties.html; let html = data; if (html != '') { $(popupContent).html(html) overlay.setPosition(coordinate); flag = true; } } } }) if (flag) { map.addOverlay(overlay) } else { map.removeOverlay(overlay); } }); }, //添加geoserver图层方法 addGeoLayer: function (name,zIndex) { let layer = new TileLayer({ source: new TileWMS({ url: MapUrl, params: { 'LAYERS': devStr + ':' + name, 'TILED': true }, serverType: 'geoserver', projection: DataSource }), zIndex: zIndex?zIndex:10 }); map.addLayer(layer); return layer }, // 添加geoserver图层 addXinXingWhite: function () { if(xinxingWhitelayer==null){ // console.log(1111) xinxingWhitelayer = this.addGeoLayer("xinxing_yaogan", 14); // console.log(222,xinxingWhitelayer) } }, // 移除geoserver图层 removeXinXingWhite:function(){ if(xinxingWhitelayer!=null){ map.removeLayer(xinxingWhitelayer); xinxingWhitelayer = null; } }, /* * 添加瓦片图层 * */ addXYZLayer: function () { if (JDLayer) { return; } else { JDLayer = new TileLayer({ source: new XYZ({ url: MapJDUrl }), zIndex: 11 }); map.addLayer(JDLayer); } }, // 删除瓦片图层 removeXYZLayer: function () { if (JDLayer) { map.removeLayer(JDLayer) JDLayer = null; } }, // 添加多个点,返回图层对象Feature addPointsLayer: function (points) { let arrLayer = []; for (let i = 0; i < points.length; i++) { let point1X = points[i].lon; let point1Y = points[i].lat; let name1 = points[i].num; let feature = this.vectorPointCircleReturn([point1X, point1Y], name1, points[i]) arrLayer.push(feature) } return arrLayer; }, addPointsLayer_zygk: function (points) { let arrLayer = []; for (let i = 0; i < points.length; i++) { let pointX = points[i].lon; let pointY = points[i].lat; let name = points[i].name; let img = points[i].img; let params = points[i].params let option ={ coordinate:[pointX, pointY], img:img, name:name, params: params, scale:1.2, zIndex:99 } if (points[i].html != undefined) { option.html = points[i].html } else { option.html = "" } let feature = this.vectorPointImgReturn_zygk(option) arrLayer.push(feature) } return arrLayer; }, //删除多个点,输入图层对象数组 removePointslayer(arr) { for (let i = 0; i < arr.length; i++) { map.removeLayer(arr[i]); } }, // 撒点,点是图片 vectorPointImg: function (point, img, name) { let scale = 0.4; let styleFunc = function () { let style = new Style({ image: new Icon({ src: require('../assets/images/mapIcon/' + img + '.png'), scale: scale }), text: new Text({ //文本样式 text: name, textAlign: 'center', offsetY: -20, offsetX: 10, textBaseline: 'middle', font: '17px Calibri,sans-serif', fill: new Fill({ color: '#cd5c5c' }) }) }) return style; } let source = new VectorSource({ wrapX: false }); let vector = new VectorLayer({ source: source, zIndex: 99, style: styleFunc() }); // let points = [112.16629, 22.65025] // let points = fromLonLat([112.16629, 22.65025]) let fetureLine = new Feature({ geometry: new Point(point) }); source.addFeature(fetureLine); map.addLayer(vector); }, vectorPointCircleReturn: function (point, name, data) { let scale = 0.4; let styleFunc = function () { let style = new Style({ image: new Circle({ radius: 7, stroke: new Stroke({ color: '#cd5c5c' }), fill: new Fill({ color: '#cd5c5c' }) }), text: new Text({ //文本样式 text: data.name ? data.name : '', textAlign: 'center', offsetY: -20, offsetX: 10, textBaseline: 'middle', font: '17px Calibri,sans-serif', fill: new Fill({ color: '#cd5c5c' }) }) }) return style; } let source = new VectorSource({ wrapX: false }); let vector = new VectorLayer({ source: source, zIndex: 99, style: styleFunc() }); // let points = [112.16629, 22.65025] // let points = fromLonLat([112.16629, 22.65025]) let fetureLine = new Feature({ geometry: new Point(point), data: data.params }); source.addFeature(fetureLine); map.addLayer(vector); return vector; }, vectorPointImgReturn_zygk: function (option) { let styleFunc = function () { let scale = 0.4; let zIndex=99; let style = new Style({ image: new Icon({ src: require('../assets/images/mapIcon/' + option.img + '.png'), scale: option.scale?option.scale:scale }), text: new Text({ //文本样式 text: option.name?option.name:'', textAlign: 'center', offsetY: -20, offsetX: 10, textBaseline: 'middle', font: '17px Calibri,sans-serif', fill: new Fill({ color: '#cd5c5c' }) }) }) return style; } let source = new VectorSource({ wrapX: false }); let vector = new VectorLayer({ source: source, zIndex: option.zIndex?option.zIndex:zIndex, style: styleFunc() }); // let points = [112.16629, 22.65025] // let points = fromLonLat([112.16629, 22.65025]) let fetureLine = new Feature({ geometry: new Point(option.coordinate), data: option.params, html: option.html }); source.addFeature(fetureLine); map.addLayer(vector); return vector; }, // 撒点,可以改变样式 vectorPointColor: function (coordinate, styles, data) { let defaultStyle = { color: '#cd5c5c', radius: 7, text: '' } let styleFunc = function (styles) { let style = new Style({ image: new Circle({ radius: styles.radius ? styles.radius : defaultStyle.radius, stroke: new Stroke({ color: styles.color ? styles.color : defaultStyle.color }), fill: new Fill({ color: styles.color ? styles.color : defaultStyle.color }) }), text: new Text({ //文本样式 text: styles.text ? styles.text : defaultStyle.text, textAlign: 'center', offsetY: -20, offsetX: 0, textBaseline: 'middle', font: '16px Microsoft YaHei', fill: new Fill({ color: styles.color ? styles.color : defaultStyle.color }) }) }) return style; } let source = new VectorSource({ wrapX: false }); let vector = new VectorLayer({ source: source, zIndex: 99, style: styleFunc(styles) }); // let points = [112.16629, 22.65025] // let points = fromLonLat([112.16629, 22.65025]) let feturePoint = new Feature({ geometry: new Point(coordinate), data: data.params }); source.addFeature(feturePoint); map.addLayer(vector); return vector; }, // 潮流线路绘制 vectorLineAutoDash_clt: function (lineArr) { let source = new VectorSource({ wrapX: false }); let vector = new VectorLayer({ source: source, zIndex: 97 }); // 遍历画线画点 for (let j = 0; j < lineArr.length; j++) { let lines = lineArr[j]; for (let i = 0; i < lines.length; i++) { if (i == lines.length - 1) { continue; } let to = { coordinate: [lines[i].lon, lines[i].lat], name: lines[i].name, type: lines[i].type, params: lines[i].params, }; let from = { coordinate: [lines[i + 1].lon, lines[i + 1].lat], name: lines[i + 1].name, type: lines[i + 1].type, params: lines[i + 1].params, } let points = new Array(to.coordinate, from.coordinate); // let defaultStyle = { // color:'#cd5c5c', // radius :7, // text:'' // } // 设置变电站点的颜色 let getColor = function (type) { if (type == '110') { return '#cd5c5c' } else if (type == '35') { return '#33cccc' } else if (type == '220') { return '#fff'; } else { return '#fff'; } } let colorLine = getColor(to.type) // 绘制点 this.vectorPointColor(from.coordinate, { color: getColor(from.type), radius: 7, text: from.name, }, from) this.vectorPointColor(to.coordinate, { color: getColor(to.type), radius: 7, text: to.name }, to) let fetureLine = new Feature({ geometry: new LineString(points), dashOffset: 0 }); // 线背景 let outlineStroke = new Style({ stroke: new Stroke({ // color:'red', // width:5 }) }); let getAnimationStrokeStyle = function () { return new Style({ stroke: new Stroke({ color: colorLine, width: 4, lineDash: [1, 3, 5], lineDashOffset: fetureLine.get("dashOffset") }) }) }; let getStyle = function () { return [outlineStroke, getAnimationStrokeStyle()]; } fetureLine.setStyle(getStyle); source.addFeature(fetureLine); setInterval(function () { let offset = fetureLine.get('dashOffset'); offset = offset == 8 ? 0 : offset + 4; fetureLine.set('dashOffset', offset); }, 100); } } map.addLayer(vector); }, // 画直线,可以改变颜色 vectorLineSoildColor: function (points, color) { let source = new VectorSource({ wrapX: false }); let vector = new VectorLayer({ source: source, zIndex: 99 }); let fetureLine = new Feature({ geometry: new LineString(points), }); let defaultStyle = { color: 'yellow' } function getStyle(color) { return new Style({ stroke: new Stroke({ color: color == '' ? defaultStyle.color : color, width: 5 }) }); } fetureLine.setStyle(getStyle(color)); source.addFeature(fetureLine); map.addLayer(vector); }, // 画多条直线 vectorLinesSoild: function (points) { let isError = false; for (let i = 0; i < points.length; i++) { if (i == (points.length - 1)) return; let point1X = points[i].lon; let point1Y = points[i].lat; let point2X = points[i + 1].lon; let point2Y = points[i + 1].lat; let color = ''; if (points[i].yc == 1) { if (!isError) { color = 'red'; } isError = !isError; } this.vectorLineSoildColor(new Array([point1X, point1Y], [point2X, point2Y]), color); } }, // 恢复默认位置 resetCenter: function () { map.getView().animate({center: defaultDatas.center}, {zoom: defaultDatas.zoom}) }, // 根据zoom加载或者删除点 LineAndPoindZoom: function (points) { let xlPoints = []; let isOk = true; map.on('moveend', e => { let currentZoom = map.getView().getZoom(); if (currentZoom >= 13) { if (isOk) { xlPoints = this.addPointsLayer(points) isOk = !isOk; } } else { if (!isOk) { this.removePointslayer(xlPoints) xlPoints = []; isOk = !isOk; } } }); }, load3minReset: function () { let that = this; let zoomArr = []; let i = 0; let timer = setInterval(() => { let zoom = map.getView().getZoom(); if (i == 29) { that.resetCenter(); zoomArr = []; i = 0; window.clearInterval(timer); return; } i++; if (zoomArr.length > 0) { if (zoomArr[zoomArr.length - 1] != zoom) { zoomArr = []; i = 0; return; } } zoomArr.push(zoom); }, 6000) return timer; }, addCirclelayers:function (data,r) { // let data = [112.314079,22.6958978]; r = r/10000; let styleFunc = function (name) { let style = new Style({ fill:new Fill({ color:[255,0,0,.3] }), stroke:new Stroke({ color:'red', width:2 }) }) return style; } let source = new VectorSource({ wrapX: false }); let vector = new VectorLayer({ source: source, zIndex: 99, style: styleFunc(name) }); // let points = [112.16629, 22.65025] // let points = fromLonLat([112.16629, 22.65025]) let fetureLine = new Feature({ // geometry: new CircleL(data,0.005), geometry: new CircleL(data,r), }); source.addFeature(fetureLine); map.addLayer(vector); }}export default efgis