[Scripts] APIHelper

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.

[Scripts] APIHelper

Postby AX1983CT » Fri Sep 27, 2019 4:53 am

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: 4
Joined: Thu May 18, 2017 7:04 pm
Location: Kharkiv, Ukraine
Has thanked: 0 time
Been thanked: 2 times

Return to Addons, Extensions, and Scripts

Who is online

Users browsing this forum: jmbox