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.

Post Reply
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.

Script authors: changes to the repositories API

Post by Glodenox
Hey everyone,

With today's release of the Waze Map Editor the methods available for repositories such as the segments, streets and users have been adjusted slightly. Whereas previously you could get an object with the .get() method (example: W.model.streets.get(someStreetId);), you now need to use .getObjectById() instead.

At the moment, .get() is still available as a proxy to the new .getObjectById() method, but it will be removed in an upcoming release of the WME (no fixed date, depends slightly on how many scripts would become broken at that point). Whenever a script currently uses .get(), a notification message will be logged in the web console of your browser. Therefore it is advised to update your userscripts in the following weeks. The change is minimal, but here's an example to help you out:

Code: Select all

W.model.users.get(267294555);
Should be replaced with

Code: Select all

W.model.users.getObjectById(267294555);
The same applies for all these repositories under W.model:
segments, nodes, users, streets, cities, states, countries, problems, mapUpdateRequests, venues, junctions, bigJunctions, roadClosures, cameras, userAreas, problemDetails, houseNumbers, updateRequestSessions, archives, archiveSessions, managedAreas, majorTrafficEvents, restrictedAreas and mapComments.

I've gone through the userscripts known to the Discord !script command and found these userscripts to be affected by this:

Code: Select all

WME Advanced Closures
WME Bookmarks
WME ClickSaver
WME Closure Details
WME Color Speeds
WME Form Filler
WME Junction Angle Info
WME MagicWand
WME Map Tiles Update
WME PL Jump
WME Place Harmonizer
WME Place Interface Enhancements
WME PlaceNames
WME RA Util
WME Reverse Nodes
WME Road History
WME Road Selector
WME Route Checker
WME Route Speeds (MoM fork)
WME Select Same Type Roads
WME Show Alt Names
WME Speedlimits
WME Street to River PLUS
WME UR Comments
WME UR-MP Tracking
WME Validator
Overview spreadsheet of affected scripts

FYI: there may also still be some calls to the get() function within the vanilla WME code though. They should mostly be gone, but I've found at least one such call already (when selecting a segment with a road closure). So don't necessarily think any such messages are always caused by your own scripts. Usually that will be the case though ;)

Thanks for all your awesome work!
Glodenox
Waze Global Champs
Waze Global Champs
Posts: 1568
Answers: 1
Answers: 1
Has thanked: 278 times
Been thanked: 946 times

POSTER_ID:17118915

1

Send a message
Last edited by Glodenox on Tue Jul 31, 2018 4:10 pm, edited 1 time in total.
Belgium & Luxembourg Coordinator • Script Writing Community Coordinator
https://www.tomputtemans.com/images/WazeBelgium.pnghttps://www.tomputtemans.com/images/WazeWMEbeta.png

Post by crazycaveman
Surprised WAL escaped the list, definitely has some references to .get() I need to clean up...
crazycaveman
US Waze Champs
US Waze Champs
Posts: 857
Has thanked: 226 times
Been thanked: 441 times
Send a message

Post by Glodenox
I also just noticed there hasn't been an announcement yet about the repositories that weren't affected by the changes above: the get() function there is being replaced with getAsync().

Here's a direct quote of what has changed:
W.model.problemDetails.get() was renamed to W.model.problemDetails.getAsync()
W.model.houseNumbers.get() was renamed to W.model.houseNumbers.getAsync()
W.model.updateRequestSessions.get() was renamed to W.model.updateRequestSessions.getAsync()
W.model.archives.get() was renamed to W.model.archives.getAsync()
W.model.archiveSessions.get() was renamed to W.model.archiveSessions.getAsync()
If anyone uses these functions, you can't just swap out "get" with "getAsync". As the name implies, these functions now return a Promise object, which will be resolved at a later point in time. Here's an example of how you'd usually handle promises:

Code: Select all

W.model.problemDetails.getAsync(['2/5606837'])
    .then((details) => console.log(details))
    .catch((error) => console.log(error));
Be aware that any lines you place outside of the callback function you put in then will be executed immediately after executing that line. This means that your code isn't stuck when it tries to retrieve this sort of data, but at the same time it also means you might need to adjust your code so it can deal with some information not being available yet.

Please note that I'm using the arrow function expression in that example to create a function somewhat comparable to an anonymous function. You could also use function(details) { console.log(details); } as before if you really want to.
Glodenox
Waze Global Champs
Waze Global Champs
Posts: 1568
Answers: 1
Has thanked: 278 times
Been thanked: 946 times
Send a message
Belgium & Luxembourg Coordinator • Script Writing Community Coordinator
https://www.tomputtemans.com/images/WazeBelgium.pnghttps://www.tomputtemans.com/images/WazeWMEbeta.png

Post by JustinS83
Glodenox wrote:I also just noticed there hasn't been an announcement yet about the repositories that weren't affected by the changes above: the get() function there is being replaced with getAsync().

Here's a direct quote of what has changed:
W.model.problemDetails.get() was renamed to W.model.problemDetails.getAsync()
W.model.houseNumbers.get() was renamed to W.model.houseNumbers.getAsync()
W.model.updateRequestSessions.get() was renamed to W.model.updateRequestSessions.getAsync()
W.model.archives.get() was renamed to W.model.archives.getAsync()
W.model.archiveSessions.get() was renamed to W.model.archiveSessions.getAsync()
If anyone uses these functions, you can't just swap out "get" with "getAsync". As the name implies, these functions now return a Promise object, which will be resolved at a later point in time. Here's an example of how you'd usually handle promises:

Code: Select all

W.model.problemDetails.getAsync(['2/5606837'])
    .then((details) => console.log(details))
    .catch((error) => console.log(error));
Be aware that any lines you place outside of the callback function you put in then will be executed immediately after executing that line. This means that your code isn't stuck when it tries to retrieve this sort of data, but at the same time it also means you might need to adjust your code so it can deal with some information not being available yet.

Please note that I'm using the arrow function expression in that example to create a function somewhat comparable to an anonymous function. You could also use function(details) { console.log(details); } as before if you really want to.
Alternatively, if you want it to act synchronous you can use async await, which I would recommend. Read the linked article but basically you can do something like this:

Code: Select all

async function doStuff(){
    var result = await W.model.problemDetails.getAsync(['2/5606837']);
    if(result != null)
        doMoreStuff();
    else
        StuffIsBroken();
}
JustinS83
Waze Global Champs
Waze Global Champs
Posts: 1463
Has thanked: 215 times
Been thanked: 2389 times
Send a message

Post by MapOMatic
Thanks, Glodenox. In addition, the W.model.actionManager.actions property was removed in the latest WME release. References to that can be replaced with the W.model.actionManager.getActions() function.
MapOMatic
Country Manager
Country Manager
Posts: 495
Has thanked: 251 times
Been thanked: 871 times
Send a message