Git Product home page Git Product logo

wikimedia-mapdata's Introduction

wikimedia-mapdata

Wikimedia map data 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 juliengirault/wikimedia-mapdata --save

Required wrapper methods

  • createPromise
  • whenAllPromises
  • isEmptyObject
  • isPlainObject
  • isArray
  • extend
  • getJSON
  • mwApi
  • mwUri
  • title

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
     */
	isArray: function () {
		return $.isArray.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 );
	},

	/**
     * @required
     */
	title: mw.config.get( 'wgPageName' ),

	/**
     * @optional
     */
	mwUri: function ( data ) {
		return new mw.Uri( data );
	},

	/**
     * @optional
     */
	clientStore: mw.config.get( 'wgKartographerLiveData' ),

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

	/**
     * @optional
     */
	bind: function () {
		return $.proxy.apply( $, arguments );
	},

	/**
     * @optional
     */
	mwMsg: function () {
		return mw.msg.apply( mw.msg, arguments );
	}
} );

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

	for (var i = 0; i < dataGroups.length; i++ ) {
		group = dataGroups[ i ];

		if (dataGroups.length > 1) {
			mapGeoJSON = mapGeoJSON || [];
			mapGeoJSON.push( group.getGeoJSON() );
		} else {
			mapGeoJSON = group.getGeoJSON();
		}
	}
} );

wikimedia-mapdata's People

Contributors

juliengirault avatar nyurik avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.