Skip to content

Commit

Permalink
Merge pull request #45 from 2gis/fix/entrance-arrows
Browse files Browse the repository at this point in the history
Портятся стрелки входов в здания
  • Loading branch information
ilfa committed Sep 23, 2014
2 parents 525cced + 27d7591 commit 4a015e2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
53 changes: 33 additions & 20 deletions src/DGEntrance/src/Arrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,35 +60,48 @@ DG.Entrance.Arrow = DG.Polyline.extend({
},

_offsetLastPathPoint: function () {
var lastSegmentInPercents,
offsetVector,
offsetTo = {},
origPoints = this._rings[0],
pointsLen = origPoints.length,
var origPoints = this._rings[0],
style = this.options.byZoom[this._map.getZoom()],

lastPoint = origPoints[pointsLen - 1],
lastByOnePoint = origPoints[pointsLen - 2],
lastSegmentLen = lastPoint.distanceTo(lastByOnePoint);
pointsLen = origPoints.length,
lastSegmentLen = origPoints[pointsLen - 1].distanceTo(origPoints[pointsLen - 2]),
lastSegmentInPercents,
offsetVector,
offsetTo;

if (style) {
lastSegmentInPercents = Math.abs((style.lastPointOffset * 100) / lastSegmentLen);

offsetVector = {
x: origPoints[pointsLen - 1].x - origPoints[pointsLen - 2].x,
y: origPoints[pointsLen - 1].y - origPoints[pointsLen - 2].y
};

offsetTo.x = Math.round(offsetVector.x * lastSegmentInPercents / 100);
offsetTo.y = Math.round(offsetVector.y * lastSegmentInPercents / 100);

// move last point forward/back by offsetVector direction
if (style.lastPointOffset > 0) {
origPoints[pointsLen - 1].x += offsetTo.x;
origPoints[pointsLen - 1].y += offsetTo.y;
// сравнение длины последнего сегмента пути с размером иконки стрелки
if (lastSegmentLen > style.iconWidth) {
lastSegmentInPercents = Math.abs(style.lastPointOffset / lastSegmentLen);

offsetTo = {
x: offsetVector.x * lastSegmentInPercents,
y: offsetVector.y * lastSegmentInPercents
};

// move last point forward/back by offsetVector direction
if (style.lastPointOffset > 0) {
origPoints[pointsLen - 1].x += offsetTo.x;
origPoints[pointsLen - 1].y += offsetTo.y;
} else {
origPoints[pointsLen - 1].x -= offsetTo.x;
origPoints[pointsLen - 1].y -= offsetTo.y;
}
} else {
origPoints[pointsLen - 1].x -= offsetTo.x;
origPoints[pointsLen - 1].y -= offsetTo.y;
// удлиняем последний участок, если он меньше стрелки
lastSegmentInPercents = lastSegmentLen / style.iconWidth;

if (offsetVector.x !== 0) {
origPoints[pointsLen - 1].x = origPoints[pointsLen - 2].x + offsetVector.x / lastSegmentInPercents;
}

if (offsetVector.y !== 0) {
origPoints[pointsLen - 1].y = origPoints[pointsLen - 2].y + offsetVector.y / lastSegmentInPercents;
}
}
}
}
Expand Down
24 changes: 16 additions & 8 deletions src/DGEntrance/src/DGEntrance.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ DG.Entrance = DG.Layer.extend({
},
lastPointOffset: 2,
vmlEndArrow: 'none',
weight: 6
weight: 6,
iconWidth: 4
},
17: {
marker: {
Expand All @@ -181,7 +182,8 @@ DG.Entrance = DG.Layer.extend({
},
lastPointOffset: 0,
vmlEndArrow: 'none',
weight: 7
weight: 7,
iconWidth: 6
},
18: {
marker: {
Expand All @@ -202,7 +204,8 @@ DG.Entrance = DG.Layer.extend({
},
lastPointOffset: !DG.Browser.vml ? -5 : -2,
vmlEndArrow: 'none',
weight: 8
weight: 8,
iconWidth: 8
},
19: {
marker: {
Expand All @@ -227,7 +230,8 @@ DG.Entrance = DG.Layer.extend({
},
lastPointOffset: !DG.Browser.vml ? -5 : -2,
vmlEndArrow: 'none',
weight: 10
weight: 10,
iconWidth: 12
}
}
};
Expand All @@ -251,7 +255,8 @@ DG.Entrance = DG.Layer.extend({
}
},
lastPointOffset: 2,
weight: 2
weight: 2,
iconWidth: 4
},
17: {
marker: {
Expand All @@ -265,7 +270,8 @@ DG.Entrance = DG.Layer.extend({
}
},
lastPointOffset: 0,
weight: 3
weight: 3,
iconWidth: 6
},
18: {
marker: {
Expand All @@ -279,7 +285,8 @@ DG.Entrance = DG.Layer.extend({
}
},
lastPointOffset: !DG.Browser.vml ? -5 : 0,
weight: 4
weight: 4,
iconWidth: 8
},
19: {
marker: {
Expand All @@ -294,7 +301,8 @@ DG.Entrance = DG.Layer.extend({
}
},
lastPointOffset: !DG.Browser.vml ? -5 : 0,
weight: 5
weight: 5,
iconWidth: 12
}
}
};
Expand Down

0 comments on commit 4a015e2

Please sign in to comment.