[Script] WazeWrap
Posted: 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:
Once the script is required it can be accessed via WazeWrap. Examples:
will return the current user's normalized rank.
will return the current user's username.
- 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:
Model:
User:
Require:
Util:
Interface:
PIN information:
viewtopic.php?p=1970026#p1970026
Changelog:
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
Code: Select all
WazeWrap.User.Rank()
Code: Select all
WazeWrap.User.Username()
Code: Select all
new WazeWrap.Interface.Tab('My Script', <div>Tab info</div>, callbackFunction)
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
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.
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.