
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
var dataManager = require( './DataManager' )( {
createPromise: function ( callback ) {
var promise = $.Deferred();
try {
callback( promise.resolve.bind( promise ), promise.reject.bind( promise ) );
} catch (err) {
promise.reject( err );
}
return promise;
},
whenAllPromises( promises ) {
return $.when.apply( $, promises );
},
isEmptyObject: function () {
return $.isEmptyObject.apply( $, arguments );
},
isPlainObject: function () {
return $.isPlainObject.apply( $, arguments );
},
extend: function () {
return $.extend.apply( $, arguments );
},
getJSON: function ( url ) {
return $.getJSON( url );
},
mwApi: function ( data ) {
return new mw.Api()[ 'get' ]( data );
}
} );
DataManager.loadGroups( groupIds, title, revid ).then( function ( dataGroups ) {
var mapGeoJSON, group;
dataGroups.forEach( function ( group ) {
mapGeoJSON.push( group.getGeoJSON() );
} );
} );