JGirault has uploaded a new change for review. https://gerrit.wikimedia.org/r/295737
Change subject: Edit preview: Right click on map should tell you the coordinates ...................................................................... Edit preview: Right click on map should tell you the coordinates Bug: T138520 Change-Id: I40c9aff9d49e048d1dc0e4825f6f50b08a3b6b58 --- M extension.json M i18n/en.json M i18n/qqq.json M modules/kartographer.js A modules/preview/preview.js 5 files changed, 55 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Kartographer refs/changes/37/295737/1 diff --git a/extension.json b/extension.json index 9431ee6..32d0d90 100644 --- a/extension.json +++ b/extension.json @@ -150,6 +150,18 @@ "desktop" ] }, + "ext.kartographer.preview": { + "scripts": [ + "modules/preview/preview.js" + ], + "messages": [ + "kartographer-contextmenu-coords" + ], + "targets": [ + "mobile", + "desktop" + ] + }, "ext.kartographer.fullscreen": { "dependencies": [ "ext.kartographer.site", diff --git a/i18n/en.json b/i18n/en.json index be99bc3..a92185e 100644 --- a/i18n/en.json +++ b/i18n/en.json @@ -17,6 +17,7 @@ "kartographer-attribution": "Wikimedia maps | Map data © [https://www.openstreetmap.org/copyright OpenStreetMap contributors]", "kartographer-broken-category": "Pages with broken maps", "kartographer-broken-category-desc": "The page includes an invalid map usage", + "kartographer-contextmenu-coords": "You clicked the map at <br>lat=$1 | lon=$2", "kartographer-desc": "Allows maps to be added to the wiki pages", "kartographer-error-context": "<$1>: $2", "kartographer-error-context-multi": "<$1> problems:\n$2", diff --git a/i18n/qqq.json b/i18n/qqq.json index 34714cc..fd22b0a 100644 --- a/i18n/qqq.json +++ b/i18n/qqq.json @@ -20,6 +20,7 @@ "kartographer-attribution": "Attribution text shown at the bottom of the map", "kartographer-broken-category": "Name of the tracking category", "kartographer-broken-category-desc": "Description on [[Special:TrackingCategories]] for the {{msg-mw|kartographer-broken-category}} tracking category.", + "kartographer-contextmenu-coords": "Popup for displaying coordinates of where you clicked. \n\nParameters:\n* $1 - latitude\n* $2 - longitude", "kartographer-desc": "{{desc|name=Kartographer|url=https://www.mediawiki.org/wiki/Extension:Kartographer}}", "kartographer-error-context": "{{Optional}}\nGeneral message shown before a single specific error\n\nParameters:\n* $1 - tag name, 'mapframe' or 'maplink'\n* $2 - error message", "kartographer-error-context-multi": "General message shown before multiple errors\n\nParameters:\n* $1 - tag name, 'mapframe', 'maplink' or 'mapdata'\n* $2 - list of errors combined into a bullet list", diff --git a/modules/kartographer.js b/modules/kartographer.js index fca4daf..9f6153c 100644 --- a/modules/kartographer.js +++ b/modules/kartographer.js @@ -6,7 +6,8 @@ forceHttps = mapServer[ 4 ] === 's', config = L.mapbox.config, router = mw.loader.require( 'mediawiki.router' ), - worldLatLng = new L.LatLngBounds( [ -90, -180 ], [ 90, 180 ] ); + worldLatLng = new L.LatLngBounds( [ -90, -180 ], [ 90, 180 ] ), + getScaleCoords; config.REQUIRE_ACCESS_TOKEN = false; config.FORCE_HTTPS = forceHttps; @@ -445,6 +446,9 @@ /** * Convenient method that formats the coordinates based on the zoom level. * + * FIXME: This method is public but do not use it. It will become private + * again once this file is split into several modules (T134079). + * * @param {number} zoom * @param {number} lat * @param {number} lng @@ -452,7 +456,7 @@ * the longitude (string). * @private */ - function getScaleCoords( zoom, lat, lng ) { + getScaleCoords = mw.kartographer.getScaleCoords = function( zoom, lat, lng ) { var precisionPerZoom = [ 0, 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5 ]; return [ @@ -745,5 +749,9 @@ mapDialog.close(); } } ); + + if ( mw.config.get( 'wgAction' ) === 'submit' ) { + mw.loader.using( 'ext.kartographer.preview' ); + } } ); }( jQuery, mediaWiki ) ); diff --git a/modules/preview/preview.js b/modules/preview/preview.js new file mode 100644 index 0000000..b51b637 --- /dev/null +++ b/modules/preview/preview.js @@ -0,0 +1,31 @@ +(function ( mw, L ) { + + /** + * This module adds a `contextmenu` event to the map. When a user right + * clicks on the map, he gets a little popup with the coordinates of + * where he clicked. + */ + mw.hook( 'wikipage.maps' ).add( function ( maps ) { + maps = $.isArray( maps ) ? maps : [ maps ]; + + $.each( maps, function ( i, map ) { + var popup = L.popup(); + + function onMapMenu( e ) { + var coords = mw.kartographer.getScaleCoords( + map.getZoom(), + e.latlng.lat, + e.latlng.lng + ); + + popup + .setLatLng( e.latlng ) + .setContent( mw.msg( 'kartographer-contextmenu-coords', coords[ 1 ], coords[ 2 ] ) ) + .openOn( map ); + } + + map.on( 'contextmenu', onMapMenu ); + } ); + } ); + +})( mediaWiki, L ); -- To view, visit https://gerrit.wikimedia.org/r/295737 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I40c9aff9d49e048d1dc0e4825f6f50b08a3b6b58 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Kartographer Gerrit-Branch: master Gerrit-Owner: JGirault <julien.inbox.w...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits