bug 统一修改计算算法吧

This commit is contained in:
FDD 2018-01-11 23:04:26 +08:00
parent 35f147df6d
commit 718ab779d6
5 changed files with 36 additions and 22 deletions

View File

@ -25,13 +25,14 @@
var map = new maptalks.Map('map', {
center: [108.93, 34.27],
zoom: 5,
projection: 'EPSG:4326',
baseLayer: new maptalks.TileLayer('base', {
urlTemplate: 'https://webst01.is.autonavi.com/appmaptile?style=6&x={x}&y={y}&z={z}'
})
});
var layer = new maptalks.VectorLayer('vector').addTo(map);
var layer = new maptalks.VectorLayer('vector', {
enableSimplify : false
}).addTo(map);
var drawTool = new MaptalksPlot.PlotDraw({
mode: 'Curve'

View File

@ -9,7 +9,6 @@ import * as Constants from '../../Constants'
import {
Mid,
getThirdPoint,
MathDistance,
getBisectorNormals,
getCubicValue
} from '../helper/index'
@ -44,8 +43,9 @@ class GatheringPlace extends maptalks.Polygon {
if (count < 2) return
if (count === 2) {
let mid = Mid(_points[0], _points[1])
let d = MathDistance(_points[0], mid) / 0.9
let pnt = getThirdPoint(_points[0], mid, Constants.HALF_PI, d, true)
const measurer = this._getMeasurer()
const distance = measurer.measureLength(Coordinate.toCoordinates(_points[0]), Coordinate.toCoordinates(mid)) / 0.9
let pnt = getThirdPoint(measurer, _points[0], mid, Constants.HALF_PI, distance, true)
_points = [_points[0], pnt, _points[1]]
}
let mid = Mid(_points[0], _points[2])

View File

@ -8,7 +8,6 @@ import * as Constants from '../../Constants'
import {
Mid,
getThirdPoint,
MathDistance,
isClockWise,
getAzimuth,
getArcPoints,
@ -42,15 +41,18 @@ class Lune extends maptalks.Polygon {
const count = this._points.length
let _points = Coordinate.toNumberArrays(this._points)
if (count < 2) return
const measurer = this._getMeasurer()
if (count === 2) {
let mid = Mid(_points[0], _points[1])
let d = MathDistance(_points[0], mid)
let pnt = getThirdPoint(_points[0], mid, Constants.HALF_PI, d)
let pnt = getThirdPoint(
measurer, _points[0], mid, Constants.HALF_PI,
measurer.measureLength(Coordinate.toCoordinates(_points[0]), Coordinate.toCoordinates(mid))
)
_points.push(pnt)
}
let [pnt1, pnt2, pnt3, startAngle, endAngle] = [_points[0], _points[1], _points[2], undefined, undefined]
let center = getCircleCenterOfThreePoints(pnt1, pnt2, pnt3)
let radius = MathDistance(pnt1, center)
let radius = measurer.measureLength(Coordinate.toCoordinates(pnt1), Coordinate.toCoordinates(center))
let angle1 = getAzimuth(pnt1, center)
let angle2 = getAzimuth(pnt2, center)
if (isClockWise(pnt1, pnt2, pnt3)) {
@ -60,7 +62,7 @@ class Lune extends maptalks.Polygon {
startAngle = angle1
endAngle = angle2
}
_points = getArcPoints(center, radius, startAngle, endAngle)
_points = getArcPoints(measurer, center, radius, startAngle, endAngle)
_points.push(_points[0])
this.setCoordinates([
Coordinate.toCoordinates(_points)

View File

@ -6,7 +6,6 @@
import * as maptalks from 'maptalks'
import {
MathDistance,
getAzimuth,
getArcPoints
} from '../helper/index'
@ -43,10 +42,11 @@ class Sector extends maptalks.Polygon {
this.setCoordinates([this._points])
} else {
let [center, pnt2, pnt3] = [_points[0], _points[1], _points[2]]
let radius = MathDistance(pnt2, center)
const measurer = this._getMeasurer()
const radius = measurer.measureLength(Coordinate.toCoordinates(pnt2), Coordinate.toCoordinates(center))
let startAngle = getAzimuth(pnt2, center)
let endAngle = getAzimuth(pnt3, center)
let pList = getArcPoints(center, radius, startAngle, endAngle)
let pList = getArcPoints(measurer, center, radius, startAngle, endAngle)
pList.push(center, pList[0])
this.setCoordinates([
Coordinate.toCoordinates(pList)

View File

@ -169,6 +169,7 @@ export const getCubicValue = (t, startPnt, cPnt1, cPnt2, endPnt) => {
/**
* 根据起止点和旋转方向求取第三个点
* @param measurer
* @param startPnt
* @param endPnt
* @param angle
@ -176,30 +177,40 @@ export const getCubicValue = (t, startPnt, cPnt1, cPnt2, endPnt) => {
* @param clockWise
* @returns {[*,*]}
*/
export const getThirdPoint = (startPnt, endPnt, angle, distance, clockWise) => {
export const getThirdPoint = (measurer, startPnt, endPnt, angle, distance, clockWise) => {
let azimuth = getAzimuth(startPnt, endPnt)
let alpha = clockWise ? (azimuth + angle) : (azimuth - angle)
let dx = distance * Math.cos(alpha)
let dy = distance * Math.sin(alpha)
return ([endPnt[0] + dx, endPnt[1] + dy])
const vertex = measurer.locate({
'x': endPnt[0],
'y': endPnt[1]
}, dx, dy)
return [vertex['x'], vertex['y']]
}
/**
* 插值弓形线段点
* @param measurer
* @param center
* @param radius
* @param startAngle
* @param endAngle
* @param numberOfPoints
* @returns {null}
*/
export const getArcPoints = (center, radius, startAngle, endAngle) => {
let [x, y, points, angleDiff] = [null, null, [], (endAngle - startAngle)]
export const getArcPoints = (measurer, center, radius, startAngle, endAngle, numberOfPoints = 100) => {
let [dx, dy, points, angleDiff] = [null, null, [], (endAngle - startAngle)]
angleDiff = ((angleDiff < 0) ? (angleDiff + (Math.PI * 2)) : angleDiff)
for (let i = 0; i < 200; i++) {
const angle = startAngle + angleDiff * i / 200
x = center[0] + radius * Math.cos(angle)
y = center[1] + radius * Math.sin(angle)
points.push([x, y])
for (let i = 0; i < numberOfPoints; i++) {
const rad = angleDiff * i / numberOfPoints + startAngle
dx = radius * Math.cos(rad)
dy = radius * Math.sin(rad)
const vertex = measurer.locate({
'x': center[0],
'y': center[1]
}, dx, dy)
points.push([vertex['x'], vertex['y']])
}
return points
}