User:JGirault (WMF)/Mediawiki:Kartographer.js

From Wikivoyage
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
( function ( mw ) {

	var wv,
		ready,
		nearbyArticlesCfg = {
			url: 'https://tools.wmflabs.org/wikivoyage/w/data/en-articles.js',
			thumbPath: '//upload.wikimedia.org/wikipedia/commons/thumb/'
		},
	/* jscs:disable validateQuoteMarks, disallowQuotedKeysInObjects */
		maptiles = {
			"mapnik": {
				"tilesUrl": "//{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
				"options": {
					"wvIsExternal": true,
					"wvName": "Mapnik",
					"subdomains": [
						"a",
						"b",
						"c"
					],
					"attribs": [
						{
							"url": "http://www.openstreetmap.org/copyright",
							"name": "OpenStreetMap",
							"label": "Map data"
						}
					]
				}
			},
			"mapquest-open": {
				"tilesUrl": "https://{s}.mqcdn.com/tiles/1.0.0/map/{z}/{x}/{y}.png",
				"options": {
					"wvIsExternal": true,
					"wvName": "Mapquest open",
					"subdomains": [
						"otile1-s",
						"otile2-s",
						"otile3-s",
						"otile4-s"
					],
					"attribs": [
						{
							"url": "http://www.openstreetmap.org/copyright",
							"name": "OpenStreetMap",
							"label": "Map data"
						},
						{
							"url": "http://open.mapquest.co.uk",
							"name": "Mapquest",
							"label": "Tiles"
						}
					]
				}
			},
			"mapquest": {
				"tilesUrl": "https://{s}.mqcdn.com/tiles/1.0.0/sat/{z}/{x}/{y}.jpg",
				"options": {
					"wvIsExternal": true,
					"wvName": "Mapquest",
					"subdomains": [
						"otile1-s",
						"otile2-s",
						"otile3-s",
						"otile4-s"
					],
					"attribs": [
						{
							"url": "http://open.mapquest.co.uk",
							"name": "Mapquest",
							"label": "Data, imagery and map information provided by"
						}
					]
				}
			},
			"landscape": {
				"tilesUrl": "http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png",
				"options": {
					"wvIsExternal": true,
					"wvName": "Relief map",
					"attribs": [
						{
							"url": "http://www.openstreetmap.org/copyright",
							"name": "OpenStreetMap",
							"label": "Map data"
						},
						{
							"url": "http://www.opencyclemap.org/",
							"name": "Andy Allan",
							"label": "Tiles"
						}
					]
				}
			},
			"traffic-line-network": {
				"tilesUrl": "http://www.openptmap.org/tiles/{z}/{x}/{y}.png",
				"options": {
					"wvIsOverlay": true,
					"wvIsExternal": true,
					"wvName": "Traffic line network",
					"attribs": [
						{
							"url": "http://openptmap.org/",
							"name": "Openptmap.org",
							"label": "Traffic lines"
						}
					],
					"opacity": 0.5,
					"maxNativeZoom": 17
				}
			},
			"mapquest-labels": {
				"tilesUrl": "https://{s}.mqcdn.com/tiles/1.0.0/hyb/{z}/{x}/{y}.png",
				"options": {
					"wvIsOverlay": true,
					"wvIsExternal": true,
					"wvName": "Mapquest (labels)",
					"subdomains": [
						"otile1-s",
						"otile2-s",
						"otile3-s",
						"otile4-s"
					],
					"attribs": [
						{
							"url": "http://open.mapquest.co.uk",
							"name": "Mapquest",
							"label": "Data, imagery and map information provided by"
						}
					]
				}
			},
			"boundaries": {
				"tilesUrl": "http://korona.geog.uni-heidelberg.de/tiles/adminb/x={x}&y={y}&z={z}",
				"options": {
					"wvIsOverlay": true,
					"wvIsExternal": true,
					"wvName": "Boundaries",
					"attribs": []
				}
			},
			"cycling": {
				"tilesUrl": "http://tile.lonvia.de/cycling/{z}/{x}/{y}.png",
				"options": {
					"wvIsOverlay": true,
					"wvIsExternal": true,
					"wvName": "Cycling",
					"attribs": [
						{
							"url": "http://cycling.lonvia.de",
							"name": "Cycling Map",
							"label": "Cycling routes"
						}
					]
				}
			},
			"hiking": {
				"tilesUrl": "http://tile.waymarkedtrails.org/hiking/{z}/{x}/{y}.png",
				"options": {
					"wvIsOverlay": true,
					"wvIsExternal": true,
					"wvName": "Hiking",
					"attribs": [
						{
							"url": "http://hiking.waymarkedtrails.org/de/",
							"name": "Hiking Map",
							"label": "Hiking trails"
						}
					]
				}
			},
			"hill-shading": {
				"tilesUrl": "http://{s}.tiles.wmflabs.org/hillshading/{z}/{x}/{y}.png",
				"options": {
					"wvIsOverlay": true,
					"wvIsExternal": true,
					"wvName": "Hill shading",
					"attribs": [
						{
							"url": "http://www2.jpl.nasa.gov/srtm/",
							"name": "NASA",
							"label": "Hill shading"
						}
					]
				}
			}
		};
	/* jscs:enable validateQuoteMarks, disallowQuotedKeysInObjects */

	mw.hook( 'wikipage.maps' ).add( function ( maps ) {

		ready = ready || mw.loader.using( [ 'oojs-ui', 'ext.kartographer.wv' ] ).done( function () {
				wv = mw.loader.require( 'ext.kartographer.wv' );

				wv.NearbyArticles.setConfig( nearbyArticlesCfg );

				$.each( maptiles, function ( i, tile ) {
					wv.wikivoyage.addTileLayer( i, tile.tilesUrl, tile.options );
				} );
			} );

		// `maps` can be an array
		maps = $.isArray( maps ) ? maps : [ maps ];

		ready.done( function () {

			// customize each map
			$.each( maps, function ( i, map ) {

				var wvmap = new wv.WVMap( map );
				wvmap.controlLayers()
					.basemap( 'mapnik' )
					.basemap( 'mapquest-open' )
					.basemap( 'mapquest' )
					.basemap( 'landscape' )
					.overlay( 'traffic-line-network' )
					.overlay( 'mapquest-labels' )
					.overlay( 'boundaries' )
					.overlay( 'hill-shading' )
					.overlay( 'cycling' )
					.overlay( 'hiking' )
					.datalayer( map.dataLayers )
					.update();
				wvmap.scale();
				wvmap.nearby();

			} );
		} );
	} );
} )( mediaWiki );