MediaWiki:Kartographer.js
注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:按 Ctrl-F5。
/**********************************************************************
* The JavaScript in this file is a CUSTOMIZATION of the Kartographer
* extension for Wikivoyage.
*
* For any information about Kartographer, visit the page:
* https://www.mediawiki.org/wiki/Extension:Kartographer
*
* WHAT IS IT DOING ?
*
* This code listens to a Kartographer extension hook `wikipage.maps`
* and adds a few features onto the map:
*
* - Adds a control (top right) to select a different tile layer and toggle
* overlays:
* - Adds tile layers (mapnik, mapquestopen, mapquest, landscape)
* - Adds overlays (traffic, maplabels, boundaries, hill, cycling, hiking)
*
* HOW CAN YOU HELP ?
*
* We need to collect feedback, about the experimentation itself, about the
* features, the design, the user experience, the code... We also need to
* start tracking bugs and fixing them. Please help.
*
* To report a bug or an issue:
* https://phabricator.wikimedia.org/maniphest/task/create/?projects=maps
* https://phabricator.wikimedia.org/tag/maps
*
* To contribute to the code:
* https://phabricator.wikimedia.org/r/p/mediawiki/extensions/Kartographer;browse/master/
* https://github.com/wikimedia/mediawiki-extensions-Kartographer
*
**********************************************************************/
( function ( mw ) {
mw.loader.using( [ 'ext.gadget.site-lib' ], function () {
var wv,
ready,
/* 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": wgULS('地图资料:', '地圖資料:')
}
]
}
},
"landscape": {
/* [[User:DTankersley (WMF)]] is the contact person for this API key */
"tilesUrl": "http://{s}.tile.thunderforest.com/landscape/{z}/{x}/{y}.png?apikey=ca8e8a8e3f9a44c19a8edcf8fb5f90c4",
"options": {
"wvIsExternal": true,
"wvName": wgULS('等高线地图', '等高線地圖'),
"attribs": [
{
"url": "http://www.openstreetmap.org/copyright",
"name": "OpenStreetMap",
"label": wgULS('地图资料:', '地圖資料:')
},
{
"url": "http://www.opencyclemap.org/",
"name": "Andy Allan",
"label": wgULS('图砖:', '圖磚:')
}
]
}
},
"traffic-line-network": {
"tilesUrl": "http://www.openptmap.org/tiles/{z}/{x}/{y}.png",
"options": {
"wvIsOverlay": true,
"wvIsExternal": true,
"wvName": wgULS('交通路线网', '交通路線網'),
"attribs": [
{
"url": "http://openptmap.org/",
"name": "Openptmap.org",
"label": wgULS('交通路线:', '交通路線:')
}
],
"opacity": 0.5,
"maxNativeZoom": 17
}
},
"boundaries": {
"tilesUrl": "http://korona.geog.uni-heidelberg.de/tiles/adminb/x={x}&y={y}&z={z}",
"options": {
"wvIsOverlay": true,
"wvIsExternal": true,
"wvName": wgULS('边界线', '邊界線'),
"attribs": []
}
},
"cycling": {
"tilesUrl": "http://tile.waymarkedtrails.org/cycling/{z}/{x}/{y}.png",
"options": {
"wvIsOverlay": true,
"wvIsExternal": true,
"wvName": wgULS('自行车路线', '自行車路線'),
"attribs": [
{
"url": "http://cycling.waymarkedtrails.org",
"name": "Waymarked Trails",
"label": wgULS('自行车路线:', '自行車路線:')
}
]
}
},
"hiking": {
"tilesUrl": "http://tile.waymarkedtrails.org/hiking/{z}/{x}/{y}.png",
"options": {
"wvIsOverlay": true,
"wvIsExternal": true,
"wvName": wgULS('步道', '步道'),
"attribs": [
{
"url": "http://hiking.waymarkedtrails.org",
"name": "Waymarked Trails",
"label": wgULS('远足步道:', '遠足步道:')
}
]
}
},
"hill-shading": {
"tilesUrl": "http://{s}.tiles.wmflabs.org/hillshading/{z}/{x}/{y}.png",
"options": {
"wvIsOverlay": true,
"wvIsExternal": true,
"wvName": wgULS('山部晕渲', '山部暈渲'),
"attribs": [
{
"url": "http://www2.jpl.nasa.gov/srtm/",
"name": "NASA",
"label": wgULS('山部晕渲:', '山部暈渲:')
}
]
}
}
};
/* 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' );
$.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( 'landscape' )
.overlay( 'traffic-line-network' )
.overlay( 'boundaries' )
.overlay( 'hill-shading' )
.overlay( 'cycling' )
.overlay( 'hiking' )
.datalayer( map.dataLayers )
.update();
} );
} );
} );
} );
} )( mediaWiki );