drawCircleByStation参数是坐标【lng,lat】
// 绘制范围圆taylor
drawCircleOld(centerPosition, radius = 2000, callback, color = '#fff', text = '') {
let features = []
for (let i = 0; i < centerPosition.length; i++) {
let EPSGTransCoord = fromLonLat(centerPosition[i],'EPSG:3857') //,'EPSG:3857'
let circle = new CircleGeom(EPSGTransCoord, radius)
let feature = new Feature({
geometry: fromCircle(circle)
.transform('EPSG:3857','EPSG:4326'),
})
let coord = feature.getGeometry().getLinearRings()[0].getCoordinates()[0]
let featureText = new Feature({
geometry: new Point(coord)
})
featureText.setStyle(new Style({
text: new Text({
font: '16px Microsoft YaHei',
text: text,
textAlign: "right", //对齐方式
textBaseline: "middle", //文本基线
fill: new Fill({
// color: color
color: '#000'
}),
offsetX: 10
})
}))
if (callback !== undefined && typeof callback === 'function') {
callback(feature, i, color)
}
// features.push(feature,featureText)
features.push(feature)
}
return features;
}
drawCircle(centerPosition, radius = 2000, callback, color = '#fff', text = '') {
let features = []
const projection = this.map.getView().getProjection()
for (let i = 0; i < centerPosition.length; i++) {
const circlenew = circular(
transform(centerPosition[i], projection, 'EPSG:4326'),
radius,
128
);
circlenew.transform('EPSG:4326', projection);
let feature = new Feature({
geometry: circlenew,
})
let coord = circlenew.getCoordinates()[0]
let featureText = new Feature({
geometry: new Point(coord)
})
featureText.setStyle(new Style({
text: new Text({
font: '16px Microsoft YaHei',
text: text,
textAlign: "right", //对齐方式
textBaseline: "middle", //文本基线
fill: new Fill({
// color: color
color: '#000'
}),
offsetX: 10
})
}))
if (callback !== undefined && typeof callback === 'function') {
callback(feature, i, color)
}
// features.push(feature,featureText)
features.push(feature)
}
return features;
}
drawCircleByStation(obtData){
function setCircleStyle(color,color1){
return new Style({
fill: new Fill({
color: color
}),
stroke: new Stroke({
color: color1,
width: 1,
// lineDash: [10]
}),
})
}
let layerArr = this.map.getLayers().getArray()
let circleLayer = layerArr.find(item => item.values_.name == 'circlelayer')
if(circleLayer){
this.map.removeLayer(circleLayer)
}
let stationData = obtData
let layer = new VectorLayer({
zIndex: 10,
visible: true,
name: 'circlelayer'
})
let source = new VectorSource()
let positions = []
for (let i in stationData) {
let curData = stationData[i]
let [lon, lat] = [Number(curData.lon), Number(curData.lat)]
positions.push([lon, lat])
}
// 首先颜色配置、接着到 虚线 、 接着 到半径 依次生成features 将其放入该图层
let colorArray=['#4c97f14d','#f3111133','#e2ea8f33','#11bff34d']
function circleCallback(feature,index,color){
feature.setStyle(setCircleStyle(color,color.slice(0,-2)))
}
// let feature5km = this.drawCircle(positions,15000,circleCallback,colorArray[2],'15km')
// let feature3km = this.drawCircle(positions,3000,circleCallback,colorArray[1],'3km')
let feature1km = this.drawCircle(positions,10000,circleCallback,colorArray[0],'10km')
// let allFeatures = feature5km.concat(feature3km).concat(feature1km)
let allFeatures = [...feature1km]
source.addFeatures(allFeatures)
layer.setSource(source)
// return layer
this.map.addLayer(layer)
return allFeatures
},
// turf扇形与circular圆组合精准
initLineTurf(videocenterP){
this.flag = false
if (this.featureLine) {
this.gisMap2D.featuresSource.removeFeature(this.featureLine)
}
// 创建扇形要素
// const center = fromLonLat([videocenterP.lon, videocenterP.lat])
const center = point([videocenterP.lon, videocenterP.lat])
const radius = 10
this.startAngle = 0
this.endAngle = 0
let bearing1 = 10;
let bearing2 = 120;
const geometry = new Polygon(sector(center, radius, bearing1, bearing2).geometry.coordinates)
this.lineGeom = geometry
this.featureLine = new Feature({
geometry,
name: 'rotateLine'
})
this.gisMap2D.featuresSource.addFeature(this.featureLine)
},
lineRotateNewTurf(videocenterP, anglePoints, ft){
const center = point([videocenterP.lon, videocenterP.lat])
const radius = 10 //km
// 旋转扇形
let angle = 0
let _this = this
// 接口获取 正传倒转和转多少度
let rotateDerection = 1
let changeAngle = 50
let timeInterval = setInterval(() => {
const geometry = _this.featureLine.getGeometry()
const coordinates = sector(center, radius, this.startAngle+angle, this.endAngle+angle).geometry.coordinates
geometry.setCoordinates(coordinates)
this.lineGeom = geometry
_this.featureLine.setGeometry(geometry)
// 正传减一度
angle = rotateDerection ? angle+1 : angle-1
if (Math.abs(angle) >= changeAngle) {
clearInterval(timeInterval)
ft && _this.overRotate(ft)
_this.startAngle += angle
_this.endAngle += angle
}
},10)
},
// 计算可视区域
visibleArea () {
Promise.all([this.getVideoPitch(this.disMile, 0), this.getVideoSpin(this.disMile, 0)]).then(res => {
// 俯仰角和垂直角度
let [pitchAngle, fHorizontalValue] = [res[0].data.pitchAngle, res[1].data.fHorizontalValue]
// 塔与可视区域夹角 塔高40m
let towerAngleMin = 90 + pitchAngle - fHorizontalValue / 2
let towerAngleMax = 90 + pitchAngle + fHorizontalValue / 2
let maxR, minR
if (pitchAngle + fHorizontalValue / 2 >= 0) {
maxR = 10000
} else {
let r = 40 * Math.tan(towerAngleMax * Math.PI / 180)
maxR = r >= 10000 ? 10000 : r
}
minR = 40 * Math.tan(towerAngleMin * Math.PI / 180)
let rMin = minR * this.realRadius / 10000
let rMax = maxR * this.realRadius / 10000
let [newstartAngle, newendAngle] = [res[1].data.sectionAngle[0] * Math.PI / 180, res[1].data.sectionAngle[1] * Math.PI / 180]
let minFeature = this.sectorFeature(rMin, newstartAngle, newendAngle)
let maxFeature = this.sectorFeature(rMax, newstartAngle, newendAngle)
let coordinatesMin = WKT.parse(featureUtils.transformWktFromFeature(minFeature)).coordinates
let coordinatesMax = WKT.parse(featureUtils.transformWktFromFeature(maxFeature)).coordinates
// 扇形差集-不包括min
let differenceLine = difference(polygon(coordinatesMax), polygon(coordinatesMin))
// 扇形小班交集-重叠
let overlapXb = []
this.allXb.forEach(item => {
let coordinates = WKT.parse(item.geom).coordinates
// 是否重叠
// if (booleanOverlap(differenceLine, polygon(coordinates[0]))) {
// overlapXb.push(item)
// }
// 交集
let intersectGeom = intersect(differenceLine, polygon(coordinates[0]))
if (intersectGeom) {
overlapXb.push(intersectGeom)
}
})
// console.log(overlapXb, '双扇形公共区域小班', this.allXb)
})
},