Script authors: W.map API changed

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: Unholy, bextein, Glodenox, JustinS83

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

Postby Glodenox » Wed Nov 20, 2019 2:11 pm

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.
Script Writing Community Coordinator
[ img ][ img ]
Glodenox
Waze Global Champs
Waze Global Champs
 
Posts: 1055
Joined: Tue Aug 11, 2015 9:04 pm
Location: Belgium
Has thanked: 510 times
Been thanked: 1207 times

Re: Script authors: W.map API changed

Postby tunisiano18 » Wed Nov 20, 2019 2:36 pm

For those that want to know, WME Sent-to-slack has been corrected.
Tunisiano18
L5 - CM [ img ] Belgique - GDLuxembourg
[ img ] [ img ][ img ]
[ img ]
tunisiano18
State Manager
State Manager
 
Posts: 57
Joined: Mon Oct 29, 2018 10:02 am
Location: Wallonia Belgium
Has thanked: 26 times
Been thanked: 8 times

Re: Script authors: W.map API changed

Postby iainhouse » Tue Dec 03, 2019 12:26 am

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 158 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.
[ img ][ img ][ img ]
UK AdminsUK WikiWaze FAQWMEFU Script :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season
iainhouse
Country Manager
Country Manager
 
Posts: 10090
Joined: Mon Jul 23, 2012 5:16 pm
Location: on the road from London to insanity, with Waze HQ in the driving seat
Has thanked: 2637 times
Been thanked: 8242 times

Re: Script authors: W.map API changed

Postby Glodenox » Tue Dec 03, 2019 8:36 am

Sure! I can easily adjust the code for that.
Script Writing Community Coordinator
[ img ][ img ]
Glodenox
Waze Global Champs
Waze Global Champs
 
Posts: 1055
Joined: Tue Aug 11, 2015 9:04 pm
Location: Belgium
Has thanked: 510 times
Been thanked: 1207 times

Re: Script authors: W.map API changed

Postby iainhouse » Tue Dec 03, 2019 9:08 pm

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:
[ img ][ img ][ img ]
UK AdminsUK WikiWaze FAQWMEFU Script :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season
iainhouse
Country Manager
Country Manager
 
Posts: 10090
Joined: Mon Jul 23, 2012 5:16 pm
Location: on the road from London to insanity, with Waze HQ in the driving seat
Has thanked: 2637 times
Been thanked: 8242 times

Re: Script authors: W.map API changed

Postby Glodenox » Wed Dec 04, 2019 11:58 am

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.
Script Writing Community Coordinator
[ img ][ img ]
Glodenox
Waze Global Champs
Waze Global Champs
 
Posts: 1055
Joined: Tue Aug 11, 2015 9:04 pm
Location: Belgium
Has thanked: 510 times
Been thanked: 1207 times

Re: Script authors: W.map API changed

Postby iainhouse » Wed Dec 04, 2019 8:49 pm

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.
[ img ][ img ][ img ]
UK AdminsUK WikiWaze FAQWMEFU Script :ugeek:
I want to go to a commune in Vermont and deal with no unit of time shorter than a season
iainhouse
Country Manager
Country Manager
 
Posts: 10090
Joined: Mon Jul 23, 2012 5:16 pm
Location: on the road from London to insanity, with Waze HQ in the driving seat
Has thanked: 2637 times
Been thanked: 8242 times

Re: Script authors: W.map API changed

Postby Glodenox » Wed Dec 04, 2019 10:17 pm

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.
Script Writing Community Coordinator
[ img ][ img ]
Glodenox
Waze Global Champs
Waze Global Champs
 
Posts: 1055
Joined: Tue Aug 11, 2015 9:04 pm
Location: Belgium
Has thanked: 510 times
Been thanked: 1207 times


Return to Addons, Extensions, and Scripts

Who is online

Users browsing this forum: dhschneider, RussPA