🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@wikimedia/mapdata

Package Overview
Dependencies
Maintainers
25
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wikimedia/mapdata

Wikimedia map data manager for Kartographer's extension and Kartotherian.

latest
npmnpm
Version
0.9.2
Version published
Maintainers
25
Created
Source

npm

Wikimedia MapData

Wikimedia MapData is a library for use in the MediaWiki Kartographer extension and Kartotherian snapshot service.

Introduction

The library takes a list of ids, downloads the map data from the MediaWiki API, parses map data, extracts the external data, and downloads the external data. Once the process is complete, a list of internal and external data groups is returned. The geoJson for each groups is returned with group.getGeoJSON().

The library first requires wrapper methods to be passed in order to be used both on client-side and server-side.

Install

npm install git+https://gerrit.wikimedia.org/r/mapdata --save

Required wrapper methods

  • createPromise
  • whenAllPromises: A reference to e.g. jQuery.when
  • isEmptyObject: A reference to e.g. jQuery.isEmptyObject
  • isPlainObject: A reference to e.g. jQuery.isPlainObject
  • extend: A reference to e.g. jQuery.extend
  • getJSON: A reference to e.g. jQuery.getJSON

Example for use on client-side

// Configure data manager with wrapper methods
var dataManager = require( './DataManager' )( {

  /**
   * @required same as JS6 new Promise:
   * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
   */
  createPromise: function ( callback ) {
    var promise = $.Deferred();
    try {
      callback( promise.resolve.bind( promise ), promise.reject.bind( promise ) );
    } catch (err) {
      promise.reject( err );
    }
    return promise;
  },

  /**
   * @required
   */
  whenAllPromises( promises ) {
    return $.when.apply( $, promises );
  },

  /**
   * @required
   */
  isEmptyObject: function () {
    return $.isEmptyObject.apply( $, arguments );
  },

  /**
   * @required
   */
  isPlainObject: function () {
    return $.isPlainObject.apply( $, arguments );
  },

  /**
   * @required
   */
  extend: function () {
    return $.extend.apply( $, arguments );
  },

  /**
   * @required
   */
  getJSON: function ( url ) {
    return $.getJSON( url );
  },

  /**
   * @required
   */
  mwApi: function ( data ) {
    return new mw.Api()[ 'get' ]( data );
  }
} );

// Download and build map geojson for a list of groups:
DataManager.loadGroups( groupIds, title, revid ).then( function ( dataGroups ) {
  var mapGeoJSON, group;

  dataGroups.forEach( function ( group ) {
    mapGeoJSON.push( group.getGeoJSON() );
  } );
} );

FAQs

Package last updated on 04 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts