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: W.map API changed

Post by Glodenox
As you may have noticed, many scripts are currently broken. The reason for this is the removal of various methods that used to be available in the W.map object. This object gives access to the OpenLayers instance used to draw the Waze map. As you may expect, this is one of the key sections of the WME used by a lot of scripts.

Several of the most common methods remain available, but several others are now hidden away. It is however still possible to access these methods by using W.map.getOLMap().

As a temporary workaround to make "outdated" and old scripts work again, I've created a little userscript that copies over all methods from the W.map.getOLMap object, unless they still exist: https://greasyfork.org/scripts/391783-w ... map-object This will probably work best if the script is executed before the other userscripts.
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
Belgium & Luxembourg Coordinator • Script Writing Community Coordinator
https://www.tomputtemans.com/images/WazeBelgium.pnghttps://www.tomputtemans.com/images/WazeWMEbeta.png

Post by Glodenox
Sure! I can easily adjust the code for that.
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 Glodenox
I've updated the Fix Map Object script, but I've gone for a slightly different approach after realising that the script would be missing out on reporting the use of any non-function properties.

I've pretty much replaced W.map with a Proxy object and keep track of which properties the script has recovered. This way I know for each property access whether or not I need to trigger a message in the console. To prevent spamming the console too much, I've also made it so that the use of a certain property will only be reported 10 times at most.

I first tried to add the removed properties as a Proxy object, but that doesn't work for primitive values as they'd suddenly get a Proxy object instead of a number or String.

In theory it could be that a value property that has been copied over was null, but got replaced after the recovery. The script will check every two seconds whether or not all properties that were null are still the same. It will not keep primitive values in sync between the two objects though. I don't think that is needed here, even though it is possible by also wrapping the OL Map object in a Proxy that listens to "set" actions. That just seems like too much effort for what it's worth.
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 Glodenox
Eh, I'm also just bashing rocks together until they form a nice bridge. Sometimes I accidentally end up with a nice house instead and decide to keep it :lol: I've learnt stuff as well by doing this as I hadn't successfully used the Proxy class in the past, for example. And somewhere halfway solving this, the code was about 3 times as long and was choking up my browser with console log loops.
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 iainhouse
Hi Glodenox

After several days, during which I've learned quite a bit about Javascript, I've modified the code for WME Fix Map Object so that it will log to the console every attempt to use a function that you've copied from W.map.olMap to W.map. Here's an example:
WME_FMO.png
(8.26 KiB) Downloaded 834 times
Would you be interested in adding this modification to WME Fix Map Object? It should help with identifying scripts which are only working because they are relying on it.
iainhouse
EmeritusChamps
EmeritusChamps
Posts: 11143
Answers: 1
Has thanked: 2173 times
Been thanked: 8188 times
Send a message
https://storage.googleapis.com/wazeoped ... c4/AGC.pnghttps://sign.waze.tools/s2000.pnghttps://sign.waze.tools/c6.png
My scripts: WME FixUI WME Presets :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season

Post by iainhouse
Sorry for the delay - I currently have no Waze access at work. :)

Code: Select all

    function init() {
        if (typeof W === 'undefined' ||
            typeof W.map === 'undefined' ||
            typeof W.map.olMap === 'undefined') {
            setTimeout(init, 100);
            return;
        }
        function intercept(propName, destFunction) {
            return function() {
                console.groupCollapsed ("WME FMO: Removed function W.map." + propName + " called. Expand for stack trace.");
                console.log ((new Error()));
                console.groupEnd();
                return destFunction.apply(W.map.olMap,arguments);
           }
        }
        // Go through all properties, including the prototype chain
        console.groupCollapsed("WME FMO: copying W.map.olMap functions to W.map...");
        for (var mapProperty in W.map.olMap) {
            if (!W.map[mapProperty]) {
                  console.log("WME FMO processing " + mapProperty);
                  W.map[mapProperty] = intercept(mapProperty, W.map.olMap[mapProperty]);
            }
        }
        console.groupEnd();
    }
There's some logging in there when the properties get copied - you don't necessarily need to include that. I had real fun learning about Javascript closures and why you shouldn't create functions inside a loop. Finding a way to refer back to whoever called the function was also a struggle. :mrgreen:

I'm somewhat surprised at how few scripts are triggering the alerts. Validator did yesterday and I must report it if I find it again. I think it's possible Waze may have put in some crosslinks themselves: the current definition of W.map.getZoom is ƒ (){return this.olMap.getZoom()}, and that's without any scripts running.

Also, very amusingly, I've just spotted an attempt to use W.map.raiseLayer - by WME itself! If I weren't running WME Fix Map Object, that would have failed. :lol:
iainhouse
EmeritusChamps
EmeritusChamps
Posts: 11143
Answers: 1
Has thanked: 2173 times
Been thanked: 8188 times
Send a message
https://storage.googleapis.com/wazeoped ... c4/AGC.pnghttps://sign.waze.tools/s2000.pnghttps://sign.waze.tools/c6.png
My scripts: WME FixUI WME Presets :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season

Post by iainhouse
Thanks Tom. :mrgreen:

That looks considerably more complex than what I had - I should have known it was a job better handed to someone who really knows what they're doing! :lol: I would have just asked you to add the functionality, but I thought I'd try doing it myself and certainly had some fun trying.
iainhouse
EmeritusChamps
EmeritusChamps
Posts: 11143
Answers: 1
Has thanked: 2173 times
Been thanked: 8188 times
Send a message
https://storage.googleapis.com/wazeoped ... c4/AGC.pnghttps://sign.waze.tools/s2000.pnghttps://sign.waze.tools/c6.png
My scripts: WME FixUI WME Presets :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season