From 96ba614d1de9ce36d6d47dcd036738c06e84289c Mon Sep 17 00:00:00 2001 From: filippov Date: Wed, 23 Jul 2014 17:30:37 +0700 Subject: [PATCH] =?UTF-8?q?=D0=BF=D1=80=D0=B5=D0=B4=D0=B2=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D1=80=D0=B0?= =?UTF-8?q?=D1=81=D1=87=D1=91=D1=82=20=D0=B4=D0=B8=D1=80=D0=B5=D0=BA=D1=86?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=BD=D1=8B=D1=85=20=D1=83=D0=B3=D0=BB=D0=BE?= =?UTF-8?q?=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public_html/app.js | 48 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/public_html/app.js b/public_html/app.js index f8a33ce..87f2723 100644 --- a/public_html/app.js +++ b/public_html/app.js @@ -71,6 +71,7 @@ function parseGeom() { log('Геометрия не распознана.'); } } + // в openlayers у полигона первая точка дублируется в конце! function parseLinearRing(index, ring) { log('Обрабатывается контур ' + (index + 1)); @@ -106,7 +107,7 @@ function parseLinearRing(index, ring) { data2.push(' '); data2.push(' '); data2.push(' '); - data2.push(getAngle( + data2.push(getDirectionalAngle( { x: ring[i + 1][0], y: ring[i + 1][1] @@ -138,8 +139,49 @@ function getLenth(point, nextPoint) { return Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2)).toFixed(2); } -function getAngle(point, nextPoint) { - return 'getAngle'; +function getDirectionalAngle(point, nextPoint) { + var dx = nextPoint.x - point.x; + var dy = nextPoint.y - point.y; + if (dx === 0) { + if (ddy < 0) { + return '270° 0,0\''; + } + else { + return '90° 0,0\''; + } + } + else { + var alfa = Math.abs(Math.atan(dy/dx) * (180/Math.PI)); + var angle; + if (dx > 0 && dy > 0) { + angle = alfa; + return getDegreeAndMinit(angle); + } + else if (dx < 0 && dy > 0) { + angle = 180 - alfa; + return getDegreeAndMinit(angle); + } + else if (dx < 0 && dy < 0) { + angle = 180 + alfa; + return getDegreeAndMinit(angle); + } + else if (dx > 0 && dy < 0) { + angle = 360 + alfa; + return getDegreeAndMinit(angle); + } + else if (dx > 0 && dy === 0) { + return '0° 0\''; + } + else if (dx < 0 && dy === 0) { + return '180° 0\''; + } + } +} + +function getDegreeAndMinit (angle) { + var a = Math.floor(angle); + var minit = (angle - a) * 60; + return a + '° ' + minit.toFixed(1) + '\''; } function createTableHeader() {