Page 3 of 7

[Script] WazeWrap

Posted: Mon Nov 14, 2016 9:42 pm
by JustinS83
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:

Code: Select all

// @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
Once the script is required it can be accessed via WazeWrap. Examples:

Code: Select all

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

Code: Select all

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

Code: Select all

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:

Code: Select all

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:

Code: Select all

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:

Code: Select all

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:

Code: Select all

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:

Code: Select all

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:

Code: Select all

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:
viewtopic.php?p=1970026#p1970026


Changelog:

Code: Select all

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.
 
 
 
 
 
 
 
 

Re: [Script] WazeWrap

Posted: Thu Mar 30, 2017 1:37 am
by jm6087

Re: [Script] WazeWrap

Posted: Thu Mar 30, 2017 10:13 am
by jm6087
JustinS83 wrote: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

Re: [Script] WazeWrap

Posted: Sat Feb 02, 2019 12:10 pm
by jm6087
WOW, super nice and so clean looking.

Re: [Script] WazeWrap

Posted: Thu Feb 07, 2019 2:02 am
by jm6087
I am not sure if this is WazeWrap or not but it didn't start happening until the new update window was added.

I have seen various scripts "stuck" in my address bar, BED, Outreach Tracker and some others. Also it appears to never finish loading. I have had the page show it is still loading for over 30 minutes.


Re: [Script] WazeWrap

Posted: Wed Oct 02, 2019 9:37 pm
by jm6087
GigaaG wrote:Can you add a function that returns housenumbers connected to selected streets?
I don't think WazeWrap actually does any WME work, it is an aid for scripts.

Re: [Script] WazeWrap

Posted: Tue Apr 30, 2019 2:04 pm
by juliansean
I like this addition! Any chance you could have "none" show up when you click on the alert, because as you said it's new for each time you open WME?

Thank you!

Sean

Re: [Script] WazeWrap

Posted: Tue Nov 15, 2016 3:43 pm
by JustinS83
Tortured1 wrote: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.

Re: [Script] WazeWrap

Posted: Tue Mar 14, 2017 9:04 pm
by JustinS83
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:

Code: Select all

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

Code: Select all

// @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
And make sure to check for WazeWrap.Interface in the bootstrap.

Re: [Script] WazeWrap

Posted: Wed Mar 15, 2017 1:52 pm
by JustinS83
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.