[Script] WazeWrap

Waze Wrap

Current version: 2019.06.12.01

Authors: JustinS83, MapOMatic

Greasyfork: https://greasyfork.org/en/scripts/24851-wazewrap

WazeWrap is intended to be a base library for script writers, filling the roll that wLib started to fill before the author stopped supporting. Originally we intended to extend the wLib script, but the recent WME changes made that impossible since some wLib functionality would need to be updated in order to work properly - so we are starting anew.

The require line will look something like this:

// @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js

Once the script is required it can be accessed via WazeWrap. Examples:

WazeWrap.User.Rank() will return the current user’s normalized rank.

WazeWrap.User.Username() will return the current user’s username.

new WazeWrap.Interface.Tab('My Script', <div>Tab info</div>, callbackFunction) - will create a tab in the side panel with the title “My Script”, “Tab info” for html and will call the callbackFunction once the tab is created and html set.

There are currently 5 namespaces that are being developed - Model, Geometry, Interface, Util & User. These can be explored via accessing WazeWrap in the console. Below is the current implementation as of 2017-03-17.

Geometry:

ConvertTo4326 - converts given 900913 projection coordinates to 4326 projection coordiantes ConvertTo900913 - converts given 4326 projection coordinates to 900913 coordinates CalculateLongOffsetGPS - converts a longitudinal offset in meters to an offset in 4326 projection CalculateLatOffsetGPS - converts a latitudinal offset in meters to an offset in 4326 projection isLonLatInMapExtent - checks if the given LatLon is in the current map extent isGeometryInMapExtent - checks if the given OL.Geometry is in the current map extent calculateDistance - Calculates the distance between the given points (OL.Geometry.Point array) in meters findClosestSegment - finds the closest segment on screen to the given Ol.Geometry, with options to ignore PLR segments and unnamed PR segments

Model:

getPrimaryStreetID - Returns the primary street ID for the given segment ID getStreetName - Returns the street name for the given primary street ID getCityID - Returns the city ID for the given primary street ID getStateName - Returns the state name for the given primary street ID getStateID - Returns the state ID for the given primary street ID getCountryID - Returns the country ID for the given primary street ID getCountryName - Returns the country name for the given primary street ID getCityNameFromSegmentObj - Returns the city name for the given segment object getStateNameFromSegmentObj - Returns the state name for the given segment object getAllRoundaboutSegmentsFromObj - Returns an array of segmentIDs for all segments that are part of the same roundabout as the passed segment getAllRoundaboutJunctionNodesFromObj - Returns an array of segmentIDs for all nodes that are part of the same roundabout as the passed segment isRoundaboutSegmentID - Checks if the given segment ID is a part of a roundabout isRoundaboutSegmentObj - Checks if the given segment object is a part of a roundabout getOnscreenSegments - Returns all onscreen segments onModelReady - Defers execution of a callback function until the WME map and data model are ready. Call this function before calling a function that causes a map and model reload, such as W.map.moveTo() RouteSelection - Retrives a route from the Waze Live Map

User:

Rank - Returns the [b]normalized[/b] rank of the current user Username - Returns the current user's username isCM - Returns true if the current user is a Country Manager isAM - Returns true if the current user is an Area Manager

Require:

DragElement - Definition of the DragElement class that can be require'd - Waze removed this from the native require DivIcon - Definition of the DivIcon class that can be required'd - Waze removed this from the native require, but as of 2017-3-14 it is re-instituted natively.

Util:

waitForElement - Defers execution until the given element is present on the page mapReady - Returns if a map operation is pending or undefined if the function has not yet seen a map ready event fired. modelReady - Returns if the model has loaded objects or undefined if the function has not yet seen a model ready event fired

Interface:

Shortcut - Class for creating a keyboard shortcut in WME. Tab - Creates a new WazeWrap.Interface.Tab. The tab is appended to the WME editor sidebar and contains the passed HTML content AddLayerCheckbox - Adds a checkbox to the new Layer menu. The checkbox will be re-added when switching to/from Event mode, and the checked status preserved. If a custom group (not the standard "issues", "places", "road", "display" is passed a new group will be created and the checkbox will be added to it, correctly toggling with the group's checkbox status.

PIN information:
https://www.waze.com/forum/viewtopic.php?p=1970026#p1970026

Changelog:

[code]2019-06-12 - 2019.06.12.01 - Added an interface for WazeWrap and API for saving/retrieving settings from the server.
2019-04-29 - 2019.04.29.01 - Added Alerts interface
2018-04-10 - 2018.04.10.01 - Added support for WME object changes in beta - new functions support both production and beta WME with changed objects.
2017-11-10 - 2017.11.10.01 - Interface.Tab will now recreate the script’s tab when switching between event & edit mode and when the user changes imperial/metric units.
2017-03-16 - AddLayerCheckbox can now handle custom groups (and handles event mode switching and persists the checkbox state between hard refreshes)
2017-03-15 - Support for recovering from changing to/from event mode
2017-03-14 - Added WazeWrap.Interface.AddLayerCheckbox method for adding an item to the new layer list.
2017-01-04 - Added a Require section that allows use of DivIcon and DragElement.

2016-12-01 - Added Geometry.calculateDistance to calculate the total distance for the OL.Geometry.Point array given (minimum 2 points necessary). Started adding method header comments.

2016-11-21 - Checking if loaded in beta editor and if so not applying d2’s fix. Latest: version=159287

2016-11-17 - Move the WazeWrap object definition outside of the function so each script using WazeWrap will get the version quested in their require.

2016-11-16 - Added support for wLib’s mapReady, modelReady & onModelReady due to request.[/code]

1 Like

Excellent! I’ve already had success using this to fix scripts!

Is there any advice on mapping some things to the new way? For example, there are a number of scripts with constructs like this: “W.model.venues.events.registerPriority(…)” However, “W.model.venues.events” no longer exists. Since “W” is being brought in via “/* global W */”, I’m not sure where/how to create and object that has the events sub-object.

Thanks!

This isn’t the best place to discuss, but I haven’t looked into this yet - been getting this script ready to release to try and get as many scripts back working as possible! I’ll start looking into this as well, though, as it will affect some of my scripts as well.

Thanks - this line fixes Route Speeds.

Update released 0.2.6

Adds function to add an entry to the layer list. The checkbox added will listen to the group’s checkbox setting and enable/disable when the group is toggled (and fire the callback method).

Example from Been There which was just updated with this code:

WazeWrap.Interface.AddLayerCheckbox("display", "Been There", true, LayerToggled);

“display” - will show under the “Display” group
“Been There” - is the text to show for the checkbox
true - indicates the checkbox should be checked by default
LayerToggled - method in BeenThere that handles toggling the visibility of the layers when the checkbox is checked/unchecked.

If your script is not already using WazeWrap simply add the require in the header

// @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js

And make sure to check for WazeWrap.Interface in the bootstrap.

1 Like

Update released - 0.2.7

AddLayerCheckbox has been updated to support recovering from switching to/from Event mode. This will preserve the current state of your checkbox when re-adding it to the layer after switching to/from event mode.

Update released - 0.2.8

Adding support for custom groups to the AddLayerCheckbox method.

The custom group will be built if it is not found, will persist between event/editing mode and the checked status will persist across hard refreshes (will be reset upon browser close/open). Child elements will now also check against the checked status of the parent when they are added and disable themselves (and send a call to the script to disable its layers) if the parent group is not enabled.

Added documentation for the current state of WazeWrap implementation with short descriptors for each method.

Is it possible for WazeWrap to include the fix for the en-US change that is breaking some scripts?

What fix are you referring to?

Probably this one.

The new website for en-US is https://www.waze.com/en-US/editor/ and https://beta.waze.com/en-US/editor/

Nothing WazeWrap can do about that - the header is loaded before any required scripts. Scripter’s have to use the regex that turbomkt linked, or simply call out each one individually and use a * in place of the language.

Thanks for the explanation, I was just hoping but wasn’t sure it could be done.

Never the less, awesome script to keep other scripts working correctly

Update released - 2017.11.10.01

It’s been a while since we have made any changes to this library!

The Interface.Tab class (allows easy addition of a tab in the side bar for your script) will not automatically recreate the tab when the user switches in/out of Event Mode (the side bar is not shown in Event Mode…) or if they switch between imperial & metric units. Huzzah!

Devs:
The Tab class will automatically recreate the tab based upon the html originally given and will then re-call the callback method (which should, of course, enable any setting checkboxes based upon your current settings object…you’re not checking directly against the checkboxes for different features, right? Right???).

1 Like

Update released - 2019.02.01.01

A Script Updates interface is finally here! Holy moly I put that off for over a year…but now we have a way for scripts to publish update information in a consistent manner, and most importantly - no ridiculous alert() boxes interrupting the page loading and forcing focus to the tab.

Special thanks to falco_sparverius for the elegant design work - if it was left up to me it would have been an eyesore. Nice work :smiley:

This update window will allow multiple scripts to display update information at once - so we do not have 2, 3, 4+ scripts popping up windows to announce their update. Each script that has an update to announce will get its own tab on the left side of the dialog. The right side will contain the update information with the new version at the top, followed by the update description and links to the Greasyfork and forum thread (optional).

For devs:

WazeWrap.Interface.ShowScriptUpdate("Script Name", ScriptVersion, "Update description", "Greasyfork Link", "Forum Link");

I would recommend using GM_info.script.version for the script version so it is automatically pulled from the script and does not have to be updated. The Greasyfork link and forum link are not required - you can pass empty strings for these if you do not wish for the links to be displayed.

The Script Update function will track the script name and version so you can call it with the same name and version but it will only display the update the first time - the version must be different on subsequent runs for the update to display again.

WOW, super nice and so clean looking.

I can take no credit for the aesthestics - all credit goes to falco_sparverius. She took my initial turd of a design and cleaned it up.

Thank you, Justin! Good stuff! Is the update content capable of being HTML encode?

Yes, you can pass html for the content. Just don’t do anything to crazy and change the look of the window or I’ll have to start sanitizing the css and that’s no fun :slight_smile: