Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed roundabout rotating #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions RAUtil.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name WME RA Util
// @namespace https://greasyfork.org/users/30701-justins83-waze
// @version 2024.01.24.01
// @version 2024.10.15.01
// @description Providing basic utility for RA adjustment without the need to delete & recreate
// @include https://www.waze.com/editor*
// @include https://www.waze.com/*/editor*
Expand Down Expand Up @@ -43,7 +43,7 @@ normal RA color:#4cc600

//var totalActions = 0;
var _settings;
const updateMessage = "WME 2.206 compatibility. <br><br>Thanks to lacmacca for the update!";
const updateMessage = "Fixed roundabouts transforming into ovals when rotating.";

function bootstrap(tries = 1) {

Expand Down Expand Up @@ -98,7 +98,7 @@ normal RA color:#4cc600

var alertsHTML = '<div id="header" style="padding: 4px; background-color:#92C3D3; border-radius: 5px;-moz-border-radius: 5px;-webkit-border-radius: 5px; color: white; font-weight: bold; text-align:center; letter-spacing: 1px;text-shadow: black 0.1em 0.1em 0.2em;"><img src="https://storage.googleapis.com/wazeopedia-files/1/1e/RA_Util.png" style="float:left"></img> Roundabout Utility <a data-toggle="collapse" href="#divWrappers" id="collapserLink" style="float:right"><span id="collapser" style="cursor:pointer;padding:2px;color:white;" class="fa fa-caret-square-o-up"></a></span></div>';
// start collapse // I put it al the beginning
alertsHTML += '<div id="divWrappers" class="collapse in">';
alertsHTML += '<div id="divWrappers" class="collapse in">';
//***************** Round About Angles **************************
alertsHTML += '<p style="margin: 10px 0px 0px 20px;"><input type="checkbox" id="chkRARoundaboutAngles">&nbsp;Enable Roundabout Angles</p>';
//***************** Shift Amount **************************
Expand Down Expand Up @@ -455,9 +455,27 @@ normal RA color:#4cc600
}

function rotatePoints(origin, points, angle){
var lineFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(points),null,null);
lineFeature.geometry.rotate(angle, new OpenLayers.Geometry.Point(origin[0], origin[1]));
return [].concat(lineFeature.geometry.components);
let angleRadians = angle * Math.PI / 180;
let {lon: centerLon, lat: centerLat} = WazeWrap.Geometry.ConvertTo900913(origin[0], origin[1]);
let center = new OpenLayers.Geometry.Point(centerLon, centerLat);

for (let point of points) {
let {lon: pointLon, lat: pointLat} = WazeWrap.Geometry.ConvertTo900913(point.x, point.y);
point.x = pointLon;
point.y = pointLat;

let distance = point.distanceTo(center);
let newAngleRadians = angleRadians + Math.atan2(point.y - center.y, point.x - center.x);
point.x = center.x + distance * Math.cos(newAngleRadians);
point.y = center.y + distance * Math.sin(newAngleRadians);

let {lon: newPointLon, lat: newPointLat} = WazeWrap.Geometry.ConvertTo4326(point.x, point.y);
point.x = newPointLon;
point.y = newPointLat;
point.clearBounds();
}

return points;
}

function RotateRA(segObj, angle){
Expand Down