JGirault has uploaded a new change for review.
https://gerrit.wikimedia.org/r/292302
Change subject: Introduce "map reset" control to reset the map back to its
initial position.
......................................................................
Introduce "map reset" control to reset the map
back to its initial position.
The control is temporarily positioned in the bottom right corner,
pending a better design decision (see T136056).
Bug: T132658
Change-Id: I1d592b5f8010fccb54a7e31250638703debe6253
---
M modules/kartographer.js
1 file changed, 115 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Kartographer
refs/changes/02/292302/1
diff --git a/modules/kartographer.js b/modules/kartographer.js
index bfc3ade..4cfb18e 100644
--- a/modules/kartographer.js
+++ b/modules/kartographer.js
@@ -33,6 +33,9 @@
scale = ( scale === 1 ) ? '' : ( '@' + scale + 'x' );
urlFormat = '/{z}/{x}/{y}' + scale + '.png';
+ /**
+ * @class Kartographer
+ */
mw.kartographer = {};
/**
@@ -42,6 +45,11 @@
*/
mw.kartographer.maps = [];
+ /**
+ * @class FullScreenControl
+ * @member Kartographer
+ * @extends L.Control
+ */
mw.kartographer.FullScreenControl = L.Control.extend( {
options: {
// Do not switch for RTL because zoom also stays in
place
@@ -74,6 +82,100 @@
mw.kartographer.openFullscreenMap( this.map,
getMapPosition( this.map ) );
}
}
+ } );
+
+ /**
+ * @class ResetPositionControl
+ * @member Kartographer
+ * @extends L.Control
+ */
+ mw.kartographer.ResetPositionControl = L.Control.extend( {
+ options: {
+ // TODO: review the position of this control
+ position: 'bottomright'
+ },
+
+ /**
+ * @inheritdoc
+ */
+ initialize: function ( options ) {
+ L.Control.prototype.initialize.call( this, options );
+ this.isOnMap = false;
+ },
+
+ /**
+ * Whether the current position differs from the initial map
position.
+ *
+ * @return {boolean}
+ */
+ hasChanged: function () {
+ this.initialHash = this.initialHash ||
mw.kartographer.getMapHash( this.options.mapData );
+ return this.initialHash !== mw.kartographer.getMapHash(
this.options.mapData, this.map );
+ },
+
+ /**
+ * Toggles control whether it has changed or not.
+ */
+ toggleControl: function () {
+ var changed = this.hasChanged();
+ if ( changed !== this.isOnMap ) {
+ this[ changed ? '_show' : '_hide' ]();
+ }
+ this.isOnMap = changed;
+ },
+
+ /**
+ * @inheritdoc
+ */
+ onAdd: function ( map ) {
+ var container = L.DomUtil.create( 'div', 'leaflet-bar'
),
+ link = L.DomUtil.create( 'a',
'oo-ui-icon-undo', container );
+
+ this.href = link.href = '#' +
mw.kartographer.getMapHash( this.options.mapData, this.map );
+ link.title = mw.msg( 'kartographer-fullscreen-text' );
+ this.map = map;
+ this.element = container;
+ /*jscs:disable disallowDanglingUnderscores */
+ this._hide();
+ /*jscs:enable disallowDanglingUnderscores */
+
+ L.DomEvent.addListener( link, 'click',
this.onResetPosition, this );
+ L.DomEvent.disableClickPropagation( container );
+
+ return container;
+ },
+
+ /**
+ * Resets the view to its initial position.
+ *
+ * @param {Event} e
+ */
+ onResetPosition: function ( e ) {
+ var data = this.options.mapData;
+ L.DomEvent.stop( e );
+
+ this.map.setView( [ data.latitude, data.longitude ],
data.zoom, true );
+ },
+
+ /*jscs:disable disallowDanglingUnderscores */
+ /**
+ * Shows the control.
+ *
+ * @private
+ */
+ _show: function () {
+ this.element.style.display = 'block';
+ },
+
+ /**
+ * Hides the control.
+ *
+ * @private
+ */
+ _hide: function () {
+ this.element.style.display = 'none';
+ }
+ /*jscs:enable disallowDanglingUnderscores */
} );
/**
@@ -123,6 +225,19 @@
}
/**
+ * @property {Kartographer.ResetPositionControl} Control to
reset
+ * the map back to its initial position.
+ */
+ map.resetControl = new mw.kartographer.ResetPositionControl( {
+ mapData: data
+ } );
+
+ map.addControl( map.resetControl );
+ map.on( 'moveend', function () {
+ map.resetControl.toggleControl();
+ } );
+
+ /**
* @property {L.TileLayer} Reference to `Wikimedia` tile layer.
*/
map.wikimediaLayer = L.tileLayer( mapServer + '/' + style +
urlFormat, {
--
To view, visit https://gerrit.wikimedia.org/r/292302
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1d592b5f8010fccb54a7e31250638703debe6253
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Kartographer
Gerrit-Branch: master
Gerrit-Owner: JGirault <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits