根据两个点,计算箭头。
var x2 = points[length - 1].x;
var y2 = points[length - 1].y;
var x1 = points[length - 2].x;
var y1 = points[length - 2].y;
var distance = Math.sqrt(Math.pow((x2 - x1),2) + Math.pow((y2 - y1),2));
var yb = y2 - s * (x2 - x1) / (Math.SQRT2 * distance) + s * (y1 - y2) / (Math.SQRT2 * distance);
var xb = x2 - s * (x2 - x1) / (Math.SQRT2 * distance) - s * (y1 - y2) / (Math.SQRT2 * distance);
var ya = y2 + s * (x2 - x1) / (Math.SQRT2 * distance) + s * (y1 - y2) / (Math.SQRT2 * distance);
var xa = x2 - s * (x2 - x1) / (Math.SQRT2 * distance) + s * (y1 - y2) / (Math.SQRT2 * distance);
feature.geometry.components.push(new OpenLayers.Geometry.Point(xa, ya));
feature.geometry.components.push(new OpenLayers.Geometry.Point(x2, y2));
feature.geometry.components.push(new OpenLayers.Geometry.Point(xb, yb));
/*
var x1 = points[length - 1].x;
var y1 = points[length - 1].y;
var x2 = points[length - 2].x;
var y2 = points[length - 2].y;
if (x2 != x1) {
var k = (y2 - y1) / (x2 - x1);
if (k > 0) {
if (x2 > x1) {//1象限
var angle = Math.PI / 2 - Math.atan(k);
var angleL = angle - Math.PI / 4;
if (angleL < 0) {
angleL += 2 * Math.PI;
}
var angleR = angle + Math.PI / 4;
}
else {//3
var angle = 1.5 * Math.PI - Math.atan(k);
var angleL = angle - Math.PI / 4;
var angleR = angle + Math.PI / 4;
}
} else {
if (y2 > y1) {//4
var angle = 1.5 * Math.PI + Math.atan(-k);
var angleL = angle - Math.PI / 4;
var angleR = angle + Math.PI / 4;
if (angleR > 2 * Math.PI) {
angleR -= 2 * Math.PI;
}
}
else {//2
var angle = 0.5 * Math.PI + Math.atan(-k);
var angleL = angle - Math.PI / 4;
var angleR = angle + Math.PI / 4;
}
}
} else {
var angle = 0;
var angleL = angle - Math.PI / 4;
var angleR = angle + Math.PI / 4;
}
var xn1 = x1 + s * Math.sin(angleL);
var yn1 = y1 + s * Math.cos(angleL);
var xn2 = x1 + s * Math.sin(angleR);
var yn2 = y1 + s * Math.cos(angleR);
feature.geometry.components.push(new OpenLayers.Geometry.Point(xn1, yn1));
feature.geometry.components.push(new OpenLayers.Geometry.Point(x1, y1));
feature.geometry.components.push(new OpenLayers.Geometry.Point(xn2, yn2));*/