User:Jgirault/Kartodeveloper/helpers/MultiplePointMap.js

(function ( mw, $ ) {	var mapId = 0;

mw.Kartodeveloper.helpers.MultiplePointMap = (function {

var Map = function ( container, points, options ) { this.container = container; this.points = points; this.options = options || {}; this.map = null; this.mapId = mapId++; };

Map.prototype.draw = function { var deferred = $.Deferred, that = this;

mw.loader.using( [ 'ext.kartographer.style', 'ext.kartographer.box' ], function {

var kartoBox = mw.loader.require( 'ext.kartographer.box' ), map, marker, poiData, featureCollection = { "type": "FeatureCollection", "features": [] },					dataGroups = {};

for ( var i = that.points.length - 1; i >= 0; i-- ) { poiData = that.points[ i ]; marker = new mw.Kartodeveloper.helpers.GeoJSON.Point; marker.setLatLng( poiData[ 0 ], poiData[ 1 ] ); if ( poiData[ 2 ] ) { marker.setTitle( mw.html.element('a', {href: '/wiki/' + poiData[ 2 ], title: poiData[ 2 ] }, poiData[ 2 ]) ); }					if ( poiData[ 3 ] ) { marker.setDescription( poiData[ 3 ] ); }					marker.setMarkerColor( i === 0 ? '3366cc' : 'AEC8EB' );

featureCollection.features.push( marker.getGeoJSON ); }				dataGroups[ 'MultiplePointMap' + that.mapId ] = featureCollection

mw.config.set( 'wgKartographerLiveData', 					$.extend( mw.config.get( 'wgKartographerLiveData' ) || {}, dataGroups )				); map = kartoBox.map( {					container: that.container,					zoom: 11,					dataGroups: [ 'MultiplePointMap' + that.mapId ],					allowFullScreen: true				} );

// TODO: this should not be required

// Bind the "ready" hook map.doWhenReady( function ( map ) {					deferred.resolve;				} ); } );

return deferred.promise; };

return Map;

});

})( mediaWiki, jQuery );