[Script] WazeWrap

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] WazeWrap

Postby JustinS83 » Mon Nov 14, 2016 9:42 pm

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.


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.
Last edited by JustinS83 on Tue Apr 10, 2018 6:48 pm, edited 12 times in total.
JustinS83
Waze Global Champs
Waze Global Champs
 
Posts: 1321
Joined: Wed Dec 03, 2014 4:33 am
Location: Franklin, OH
Has thanked: 336 times
Been thanked: 2341 times

Re: [Script] WazeWrap

Postby Tortured1 » Tue Nov 15, 2016 1:14 pm

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!
Tortured1
 
Posts: 5
Joined: Wed Jun 01, 2016 4:05 am
Has thanked: 3 times
Been thanked: 1 time

Re: [Script] WazeWrap

Postby JustinS83 » Tue Nov 15, 2016 3:43 pm

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.
Script Writing Community Coordinator
[ img ][ img ][ img ][ img ][ img ]
JustinS83
Waze Global Champs
Waze Global Champs
 
Posts: 1321
Joined: Wed Dec 03, 2014 4:33 am
Location: Franklin, OH
Has thanked: 336 times
Been thanked: 2341 times

Re: [Script] WazeWrap

Postby Olestas » Wed Nov 16, 2016 8:00 am

Thanks - this line fixes Route Speeds.
[ img ][ img ][ img ][ img ]

GC: Latvia
Coordinator: Latvia
Country manager (Full coverage): Latvia/Lithuania/Belarus/Russia/Ukraine
Olestas
Coordinators
Coordinators
 
Posts: 6337
Joined: Wed Mar 09, 2011 7:08 pm
Location: Latvia
Has thanked: 3473 times
Been thanked: 2356 times

Re: [Script] WazeWrap

Postby JustinS83 » Tue Mar 14, 2017 9:04 pm

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.
Script Writing Community Coordinator
[ img ][ img ][ img ][ img ][ img ]
JustinS83
Waze Global Champs
Waze Global Champs
 
Posts: 1321
Joined: Wed Dec 03, 2014 4:33 am
Location: Franklin, OH
Has thanked: 336 times
Been thanked: 2341 times

Re: [Script] WazeWrap

Postby JustinS83 » Wed Mar 15, 2017 1:52 pm

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.
Script Writing Community Coordinator
[ img ][ img ][ img ][ img ][ img ]
JustinS83
Waze Global Champs
Waze Global Champs
 
Posts: 1321
Joined: Wed Dec 03, 2014 4:33 am
Location: Franklin, OH
Has thanked: 336 times
Been thanked: 2341 times

Re: [Script] WazeWrap

Postby JustinS83 » Thu Mar 16, 2017 9:11 pm

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.
Script Writing Community Coordinator
[ img ][ img ][ img ][ img ][ img ]
JustinS83
Waze Global Champs
Waze Global Champs
 
Posts: 1321
Joined: Wed Dec 03, 2014 4:33 am
Location: Franklin, OH
Has thanked: 336 times
Been thanked: 2341 times

Re: [Script] WazeWrap

Postby JustinS83 » Fri Mar 17, 2017 4:57 pm

Added documentation for the current state of WazeWrap implementation with short descriptors for each method.
Script Writing Community Coordinator
[ img ][ img ][ img ][ img ][ img ]
JustinS83
Waze Global Champs
Waze Global Champs
 
Posts: 1321
Joined: Wed Dec 03, 2014 4:33 am
Location: Franklin, OH
Has thanked: 336 times
Been thanked: 2341 times

Re: [Script] WazeWrap

Postby jm6087 » Thu Mar 30, 2017 12:51 am

Is it possible for WazeWrap to include the fix for the en-US change that is breaking some scripts?
jm6087
US Waze Champs
US Waze Champs
 
Posts: 3460
Joined: Wed Jun 17, 2015 10:05 pm
Location: Texas
Has thanked: 585 times
Been thanked: 1412 times

Re: [Script] WazeWrap

Postby JustinS83 » Thu Mar 30, 2017 12:54 am

jm6087 wrote: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?
Script Writing Community Coordinator
[ img ][ img ][ img ][ img ][ img ]
JustinS83
Waze Global Champs
Waze Global Champs
 
Posts: 1321
Joined: Wed Dec 03, 2014 4:33 am
Location: Franklin, OH
Has thanked: 336 times
Been thanked: 2341 times

Next

Return to Addons, Extensions, and Scripts

Who is online

Users browsing this forum: ehepner1977, n4dog