Greasemonkey script for easy river drawing

Discussion for the unofficial, community-developed addons, extensions and scripts built for the Waze Map Editor.

The official index of these tools is the Community Plugins, Extensions and Tools wiki page.

Moderators: krankyd, Unholy

Forum rules
Discussion for the unofficial, community-developed addons, extensions and scripts built for the Waze Map Editor.

DO NOT START a new thread unless it is about a new idea. Keep discussion of existing tools within the main thread for that tool.

The official index of these tools is the Community Plugins, Extensions and Tools wiki page.

Re: Greasemonkey script for easy river drawing

Postby BastianL » Wed Jun 27, 2012 8:35 pm

Hello,
I want to draw a river that has already a beginning.
Is it possible to add kilometer's to a existing river with this plugin?

Gruß!
BastianL
 
Posts: 6
Joined: Tue Jun 19, 2012 2:15 pm
Has thanked: 0 time
Been thanked: 0 time

Greasemonkey script for easy river drawing

Postby Dave2084 » Tue Jan 03, 2012 2:14 pm

This sounds interesting, I will have to install it and give it a go!
iPhone 4S 32GB (Jailed) • iOS 7.1.0 • Waze 3.7.9.922 Beta
Lincolnshire Area Manager • UK Country Administrator • iOS Beta Tester • iPhone Expert
UK WikiUK ForumWaze UK on FacebookBecome a UK Area ManagerWaze Status
Dave2084
Waze Global Champs
Waze Global Champs
 
Posts: 1838
Joined: Tue Feb 09, 2010 12:58 am
Location: Lincoln, UK
Has thanked: 154 times
Been thanked: 127 times

Re: Greasemonkey script for easy river drawing

Postby Dave2084 » Mon Jan 30, 2012 5:35 am

Thanks!
iPhone 4S 32GB (Jailed) • iOS 7.1.0 • Waze 3.7.9.922 Beta
Lincolnshire Area Manager • UK Country Administrator • iOS Beta Tester • iPhone Expert
UK WikiUK ForumWaze UK on FacebookBecome a UK Area ManagerWaze Status
Dave2084
Waze Global Champs
Waze Global Champs
 
Posts: 1838
Joined: Tue Feb 09, 2010 12:58 am
Location: Lincoln, UK
Has thanked: 154 times
Been thanked: 127 times

Re: Greasemonkey script for easy river drawing

Postby DGlanem » Fri May 25, 2012 7:52 am

I want to make a Railroad-Landmark from an existing street(railroad).

The tool gives me a messagebox "there are no new streets" (or so).

A few minutes later I try it again - the messagebox say "...succsessful created..." . :shock:


Where is my Bug?


regards from germany
#Dominik
Area-Manager: Landkreis Helmstedt (city & county), germany, Niedersachsen (lower saxony)
Wazing with Volkswagen GolfVII and Samsung Galaxy S3

* * * Excuse my terrible english... * * *
DGlanem
 
Posts: 94
Joined: Fri Aug 19, 2011 6:42 am
Location: Helmstedt, Germany
Has thanked: 2 times
Been thanked: 2 times

Re: Greasemonkey script for easy river drawing

Postby EduardoCarvajal » Mon May 20, 2013 1:53 am

Solved: Tampermonkey + Chrome

Hi,
I found 2 unhandled exceptions that crash script execution on Google Chome/Tampermonkey. That’s the reasons this script doesn’t work on Tampermonkey.

It's very easy to solve this issue, just replace the code for the following functions:

FUNCTION #01:
Code: Select all
function insertButtons() {
    if(selectionManager.selectedItems.length == 0) return;
     
    // 2013-04-19: Catch exception
    try{
       if(document.getElementById('streetToRiver') != null) return;
    }
    catch(e){ }
   
      
    var btn1 = $('<button class="btn" title="create a new street, select and click this button">Street to river</button>');
    btn1.click(doRiver);
    var btn2 = $('<button class="btn" title="create a new street, select and click this button">Street to railway</button>');
    btn2.click(doRailway);

    var cnt = $('<section id="streetToRiver"/>');
    cnt.append(btn1);
    cnt.append(btn2);
    $("#segment-edit-general").append(cnt);
    console_log("Street to river initialized");
  }

FUNCTION #02:
Code: Select all
function console_log(msg) {
    //if (console.log)
    // 2013-05-19: Alternate method to valided console object
    if(typeof console != "undefined")
      console.log(msg);
  }


THE NEW SCRIPT:
Code: Select all
// ==UserScript==
// @name WME Street to river
// @description This script create a new river landmark in waze editor papyrus. It transforms the the geometry of a new unsaved street to a polygon.
// @namespace http://www.tay-tec.de/waze-street-to-river
// @grant none
// @version 12.12.20.1
// @include https://*.waze.com/editor/*
// @include https://*.waze.com/map-editor/*
// @include https://*.waze.com/beta_editor/*
// @include https://descartes.waze.com/beta/*
// @include https://descartesw.waze.com/beta/*
// ==/UserScript==


// Mini howto:
// 1) install this script as greasemonkey script or chrome extension
// 2) draw a new street but do not save the street
// 3) add and apply a street name to define the rivers name and the the width of the river
//    Example: "20m Spree" creates a 20 meters width river named "Spree"
// 4) Select the helper street
// 5) Click the "Street to river" button
// 4) Delete the helper street
// 5) Edit the new landmark as you like


if ('undefined' == typeof __RTLM_PAGE_SCOPE_RUN__) {
  (function page_scope_runner() {
    // If we're _not_ already running in the page, grab the full source
    // of this script.
    var my_src = "(" + page_scope_runner.caller.toString() + ")();";

    // Create a script node holding this script, plus a marker that lets us
    // know we are running in the page scope (not the Greasemonkey sandbox).
    // Note that we are intentionally *not* scope-wrapping here.
    var script = document.createElement('script');
    script.setAttribute("type", "text/javascript");
    script.textContent = "var __RTLM_PAGE_SCOPE_RUN__ = true;\n" + my_src;

    // Insert the script node into the page, so it will run, and immediately
    // remove it to clean up.  Use setTimeout to force execution "outside" of
    // the user script scope completely.
    setTimeout(function() {
          document.body.appendChild(script);
          document.body.removeChild(script);
        }, 0);
  })();

  // Stop running, because we know Greasemonkey actually runs us in
  // an anonymous wrapper.
  return;
}


function streetToRiver() {

  var defaultWidth = 20;

  function insertButtons() {
    if(selectionManager.selectedItems.length == 0) return;
     
    // 2013-04-19: Catch exception
    try{
       if(document.getElementById('streetToRiver') != null) return;
    }
    catch(e){ }
   
      
    var btn1 = $('<button class="btn" title="create a new street, select and click this button">Street to river</button>');
    btn1.click(doRiver);
    var btn2 = $('<button class="btn" title="create a new street, select and click this button">Street to railway</button>');
    btn2.click(doRailway);

    var cnt = $('<section id="streetToRiver"/>');
    cnt.append(btn1);
    cnt.append(btn2);
    $("#segment-edit-general").append(cnt);
    console_log("Street to river initialized");
  }

  function doRiver(ev) {
    var foundSelectedSegment = false;
    for (var s=selectionManager.selectedItems.length-1; s>=0; s--) {
      var sel = selectionManager.selectedItems[s];
      if (sel.type == "segment" && sel.state == "Insert") {
        // found segment
        foundSelectedSegment = true;
        if (convertToLandmark(sel, "H3010"))
        {
          alert("Successfully created new river landmark");
        }
      }
    }
    if (! foundSelectedSegment) {
        alert("No unsaved and selected new street found!");
      }
  }

  function doRailway(ev) {
    var foundSelectedSegment = false;
    for (var s=selectionManager.selectedItems.length-1; s>=0; s--) {
      var sel = selectionManager.selectedItems[s];
      if (sel.type == "segment" && (sel.state == "Insert" || sel.data.roadType == 18)) {
        // found segment
        foundSelectedSegment = true;
        defaultWidth = 8;
        if (convertToLandmark(sel, "W0200"))
        {
          alert("Successfully created new railway landmark");
        }
        defaultWidth = 20;
      }
    }
    if (! foundSelectedSegment) {
        alert("No unsaved new street or railroad found!");
      }
  }

  function convertToLandmark(sel, lmtype) {

    var leftPa, rightPa, leftPb, rightPb;
    var prevLeftEq, prevRightEq;
    var street = getStreet(sel);

    var displacement = getDisplacement(street);

    var polyPoints = null;
    var vertices = sel.geometry.getVertices();
    for (var i=vertices.length-1; i>0; i--)
    {
      var pa = vertices[i];
      var pb = vertices[i-1];
      var scale = (pa.distanceTo(pb) + displacement) / pa.distanceTo(pb);

      leftPa = pa.clone();
      leftPa.resize(scale, pb, 1);
      rightPa = leftPa.clone();
      leftPa.rotate(90,pa);
      rightPa.rotate(-90,pa);

      leftPb = pb.clone();
      leftPb.resize(scale, pa, 1);
      rightPb = leftPb.clone();
      leftPb.rotate(-90,pb);
      rightPb.rotate(90,pb);

      var leftEq = getEquation({ 'x1': leftPa.x, 'y1': leftPa.y, 'x2': leftPb.x, 'y2': leftPb.y });
      var rightEq = getEquation({ 'x1': rightPa.x, 'y1': rightPa.y, 'x2': rightPb.x, 'y2': rightPb.y });
      if (polyPoints == null) {
        polyPoints = [ leftPa, rightPa ];
      }
      else {
        var li = intersectX(leftEq, prevLeftEq);
        var ri = intersectX(rightEq, prevRightEq);
        if (li && ri) {
          polyPoints.unshift(li);
          polyPoints.push(ri);
        }
        else {
          polyPoints.unshift(leftPb.clone());
          polyPoints.push(rightPb.clone());
        }
      }

      prevLeftEq = leftEq;
      prevRightEq = rightEq;
    }

    polyPoints.push(rightPb);
    polyPoints.push(leftPb);

    var polygon = new OpenLayers.Geometry.Polygon(new OpenLayers.Geometry.LinearRing(polyPoints));

    var landmark = new Waze.Feature.Vector.Landmark(polygon);
    landmark.attributes.mtfcc = lmtype;
    if (street) {
      landmark.attributes.name = street.name.replace(/^\d+(m|ft)\s*/, '');
    }
    var what = wazeModel.actionManager.add(new Waze.Action.AddLandmark(landmark));

    return true;
  }


  function getEquation(segment) {
    if (segment.x2 == segment.x1)
      return { 'x': segment.x1 };

    var slope =  (segment.y2 - segment.y1) / (segment.x2 - segment.x1);
    var offset = segment.y1 - (slope  * segment.x1)
    return { 'slope': slope, 'offset': offset };
  }

  //
  // line A: y = ax + b
  // line B: y = cx + b
  //
  // x = (d - b) / (a - c)
  function intersectX(eqa,eqb,defaultPoint) {
    if ("number" == typeof eqa.slope && "number" == typeof eqb.slope) {
      if (eqa.slope == eqb.slope)
        return null;

      var ix = (eqb.offset - eqa.offset) / (eqa.slope - eqb.slope);
      var iy = eqa.slope * ix + eqa.offset;
      return new OpenLayers.Geometry.Point(ix, iy);
    }
    else if ("number" == typeof eqa.x) {
      return new OpenLayers.Geometry.Point(eqa.x, eqb.slope * eqa.x + eqb.offset);
    }
    else if ("number" == typeof eqb.y) {
      return new OpenLayers.Geometry.Point(eqb.x, eqa.slope * eqb.x + eqa.offset);
    }
    return null;
  }


  function getStreet(segment) {
    if (! segment.attributes.primaryStreetID)
      return null;
    var street = segment.model.streets.get(segment.attributes.primaryStreetID)
    return street;
  }

  function getDisplacement(street) {
    if (! street)
      return defaultWidth;
    if (street.name.match(/^(\d+)m\b/))
      return parseInt(RegExp.$1);
    if (street.name.match(/^(\d+)ft\b/))
      return parseInt(RegExp.$1) * 0.3048;
    return defaultWidth;
  }

  function console_log(msg) {
    //if (console.log)
    // 2013-05-19: Alternate method to valided console object
    if(typeof console != "undefined")
      console.log(msg);
  }
 
  selectionManager.events.register("selectionchanged", null, insertButtons);
}

streetToRiver();
ImageImageImageImage
Local Champ - Level 5 - Costa Rica
EduardoCarvajal
Local Champ Mentor
Local Champ Mentor
 
Posts: 181
Joined: Sun Jul 01, 2012 5:57 pm
Location: Costa Rica
Has thanked: 112 times
Been thanked: 112 times

Street to River PLUS

Postby EduardoCarvajal » Tue Jun 04, 2013 2:30 pm

Hi,

This is a modified version of Street to River Script that I call Street to River PLUS.

Mini howto:
    1.install this script from userscripts.org as Greasemonkey script, Chrome extension or Tampermonkey script.


To add a new river:
    1.Draw a new street but do not save the Street.
    2.Add and apply a street name to define the rivers name and the width of the river.
    Example: "20m Spree" creates a 20 meters width river named "Spree".
    3.Select the helper Street.
    4.Click the "Street to river" button.
    5.Delete the helper Street.
    6.Edit the new landmark as you like.

To expand an existing river:
    1.Draw a new Street that starts inside an existing river, but do not save the Street.
    2. Make sure that you see on map the begining of the street (the instersection point of the street and the river)
    3.Select the helper Street.
    4.Click the "Street to river" button.
    5.Delete the helper Street.
    6.Edit the new landmark as you like.

Version 13.10.20
    1. Unlimited river size option added.

Version 13.10.18
    1."Twisted" river problem solved

Version 13.10.09
    1. Added support to multilingual version of Waze editor.

Version 13.6.3.1
    1.Added support to Google Chrome and Tampermonkey.
    2.Now it's possible to expand an existing river.
    3.Fixed save problem on large rivers.
Last edited by EduardoCarvajal on Mon Oct 21, 2013 7:02 pm, edited 8 times in total.
ImageImageImageImage
Local Champ - Level 5 - Costa Rica
EduardoCarvajal
Local Champ Mentor
Local Champ Mentor
 
Posts: 181
Joined: Sun Jul 01, 2012 5:57 pm
Location: Costa Rica
Has thanked: 112 times
Been thanked: 112 times

Re: Street to River PLUS

Postby EduardoCarvajal » Mon Oct 14, 2013 1:20 am

I've drawn maybe a 1 km long street and then pressed the STR button. Just the first hundred meters of my river were created. Then I've deleted the corresponding first few hundred meters of my helper street and pressed it again - another hundred meters of river were created (actually, my river landmark got correctly extended by the length). And so on and so on... until the end of my segment was reached.
Did it behave as expected?


Hi,
Waze editor is limit to 40 changes between savings. If you draw a very long and complex street, the river will be truncated to the first 40 points (changes). This is by design, and it’s imposed by Waze editor (if you don’t believe me, manually draw a very complex river, with more the 50 changes, and try to save it). If you need to draw a very large river, draw a small street, press Street to River button, then press delete button (to delete the helper street) and save changes. Then add a new street that starts inside the recently created river and repeat the process. Believe me, this is faster than manually drawing a river.

Additionally, I've tried to extend an existing river landmark, but it often got the river sides twisted at my extension pont, possibly because of the not matching order of points around the two polygons. Could this be taken into account when extending an existing polygon?



Version 13.10.10 solves this issue. To dowload the latest version:
userscripts.org
ImageImageImageImage
Local Champ - Level 5 - Costa Rica
EduardoCarvajal
Local Champ Mentor
Local Champ Mentor
 
Posts: 181
Joined: Sun Jul 01, 2012 5:57 pm
Location: Costa Rica
Has thanked: 112 times
Been thanked: 112 times

Re: Street to River PLUS

Postby EduardoCarvajal » Mon Oct 14, 2013 7:35 pm

foxitrot wrote:This seems to sometimes work correctly, but occasionally (after one or two modifications and saves?) incorrect two nodes are chosen for landmark continuation, not these two, where the segment crosses the landmark borderline between them.


Foxitrot, I prefer to draw rivers using small streets segments. I have more control, it's very fast and easy, and if something goes wrong you only lose the last changes you made to the map.

If you extend an existing river, make sure that before you press Street to river button, you see on screen the beginning of the street (the area where the street and the river intersect). If you draw a very large street to expand an existing river, and scroll the map, sometimes Waze editor unloads the river from memory, so the script concludes that this is a new river because it doesn’t find any river in computer memory that intersect with the helper street.

Please make sure that you have the latest version of the Script.

Street to River 13.10.17

Sincerely,
Eduardo.
ImageImageImageImage
Local Champ - Level 5 - Costa Rica
EduardoCarvajal
Local Champ Mentor
Local Champ Mentor
 
Posts: 181
Joined: Sun Jul 01, 2012 5:57 pm
Location: Costa Rica
Has thanked: 112 times
Been thanked: 112 times

Re: Greasemonkey script for easy river drawing

Postby EduardoCarvajal » Sat Feb 08, 2014 5:53 pm

Szata76 wrote:It doesn't work for me. I'm using it with Tampermonkey and Chrome.
Does it compatible wiht the latest WME?


Right now I'm working on it. I will fix the problem as soon as posible.

Enviado desde mi Samsung S3
ImageImageImageImage
Local Champ - Level 5 - Costa Rica
EduardoCarvajal
Local Champ Mentor
Local Champ Mentor
 
Posts: 181
Joined: Sun Jul 01, 2012 5:57 pm
Location: Costa Rica
Has thanked: 112 times
Been thanked: 112 times

Re: Greasemonkey script for easy river drawing

Postby EduardoCarvajal » Sun Feb 09, 2014 2:38 pm

Szata76 wrote:It doesn't work for me. I'm using it with Tampermonkey and Chrome.
Does it compatible wiht the latest WME?


Version 14.02.01 solves the problem. If you use Tampermonkey the script will be automatically updated. You can download the latest version from userscripts.org
ImageImageImageImage
Local Champ - Level 5 - Costa Rica
EduardoCarvajal
Local Champ Mentor
Local Champ Mentor
 
Posts: 181
Joined: Sun Jul 01, 2012 5:57 pm
Location: Costa Rica
Has thanked: 112 times
Been thanked: 112 times

PreviousNext

Return to Addons, Extensions, and Scripts

Who is online

Users browsing this forum: No registered users