Get a sneak peek at whats next for Permanent Hazards on our April 7th Office Hours!
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.

Post Reply
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.

[Scripts] APIHelper

Post by AX1983CT
APIHelper - simple library for scripts developers.

When you need it most?

For replace code similar to follows:

Code: Select all

boostrap(tries = 1) { 
// ... 
setTimeout(() => bootstrap(++tries), 500) 
// ...
}
With simple construction:

Code: Select all

// Initialization
APIHelper.bootstrap();
// Event handler
$(document)
      .on('ready.apihelper', function () {
        console.info('@ready');
        // Your code here
        // ...
      });
It works with WazeWrap too

If you use MutationObserver in your code – please, remove it ASAP!
Of cause, you can use native event selectionchanged to replace it, or my library:

Code: Select all

  $(document)
      .on('node.apihelper', (e, el) => {
        console.info('@node', el);
      })
      .on('segment.apihelper', (e, el) => {
        console.info('@segment', el);
      })
      .on('landmark.apihelper', (e, el) => {
        console.info('@landmark', el);
      })
      .on('landmark-collection.apihelper', (e, el) => {
        console.info('@landmark-collection', el)
      });
This library will run once for all scripts!

Events:
  • ready.apihelper – on document, when all ready for usage
  • node.apihelper – on document, when chosen some node for edit
  • segment.apihelper – on document, when chosen some segment for edit
  • landmark.apihelper – on document, when chosen some place for edit
  • landmark-collection.apihelper – on document, when chosen more than one place
Methods:
  • APIHelper.bootstrap() — initialization of the helper, for setup event triggers
  • APIHelper.addStyle(style) – append CSS style to the page
  • APIHelper.addTranslation(uid, data) – add translation data to I18n object
  • APIHelper.getVenues(except = []) – return Array of venues, except some categories
  • APIHelper.getSegments(except = []) – return Array of segments, except some road types
  • APIHelper.getSelectedVenues() – return Array of the selected venues, which you can edit
  • APIHelper.getSelectedSegments() – return Array of the selected segments, which you can edit
  • APIHelper.getSelectedNode() – return Model of the selected node, which you can edit, or null
Yep, I'm already use it for all my scripts, I will describe all of them later.
AX1983CT
Posts: 25
Has thanked: 4 times
Been thanked: 47 times

POSTER_ID:17464314

1

Send a message
Kharkiv, UA 🇺🇦
WME E40/E50/E58/E85/E95/E97 scripts @ GreasyFork