jenkins-bot has submitted this change and it was merged.

Change subject: Fix VE crash when trying to add a new map
......................................................................


Fix VE crash when trying to add a new map

Bug: T139199
Change-Id: I534ad66ff2d0bb1bdfd8721b590c717dc808d58f
---
M modules/ve-maps/ve.ce.MWMapsNode.js
M modules/ve-maps/ve.ui.MWMapsDialog.js
2 files changed, 50 insertions(+), 45 deletions(-)

Approvals:
  Yurik: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/ve-maps/ve.ce.MWMapsNode.js 
b/modules/ve-maps/ve.ce.MWMapsNode.js
index a99ec08..7fe416c 100644
--- a/modules/ve-maps/ve.ce.MWMapsNode.js
+++ b/modules/ve-maps/ve.ce.MWMapsNode.js
@@ -139,7 +139,8 @@
                mwAttrs = mwData && mwData.attrs,
                latitude = +mwAttrs.latitude,
                longitude = +mwAttrs.longitude,
-               zoom = +mwAttrs.zoom;
+               zoom = +mwAttrs.zoom,
+               node = this;
 
        this.MWMap = kartoLive.MWMap( this.$element[ 0 ], {
                latitude: latitude,
@@ -147,16 +148,18 @@
                zoom: zoom
                // TODO: Support style editing
        } );
-       this.map = this.MWMap.map;
+       this.MWMap.ready( function ( map ) {
+               node.map = map;
 
-       this.updateGeoJson();
+               node.updateGeoJson();
 
-       // Disable interaction
-       this.map.dragging.disable();
-       this.map.touchZoom.disable();
-       this.map.doubleClickZoom.disable();
-       this.map.scrollWheelZoom.disable();
-       this.map.keyboard.disable();
+               // Disable interaction
+               map.dragging.disable();
+               map.touchZoom.disable();
+               map.doubleClickZoom.disable();
+               map.scrollWheelZoom.disable();
+               map.keyboard.disable();
+       } );
 };
 
 /**
diff --git a/modules/ve-maps/ve.ui.MWMapsDialog.js 
b/modules/ve-maps/ve.ui.MWMapsDialog.js
index b4bb83b..3e183dc 100644
--- a/modules/ve-maps/ve.ui.MWMapsDialog.js
+++ b/modules/ve-maps/ve.ui.MWMapsDialog.js
@@ -54,7 +54,6 @@
        this.$mapContainer = $( '<div>' ).addClass( 
've-ui-mwMapsDialog-mapWidget' );
        this.$map = $( '<div>' ).appendTo( this.$mapContainer );
        this.map = null;
-       this.mapPromise = null;
        this.scalable = null;
        this.updatingGeoJson = false;
 
@@ -273,56 +272,60 @@
 ve.ui.MWMapsDialog.prototype.setupMap = function () {
        var dialog = this;
 
-       if ( this.mapPromise ) {
+       if ( this.map ) {
                return;
        }
 
-       this.mapPromise = mw.loader.using( 'ext.kartographer.editor' ).then( 
function () {
+       mw.loader.using( 'ext.kartographer.editor' ).then( function () {
                var geoJsonLayer, drawControl,
                        defaultShapeOptions = { shapeOptions: 
L.mapbox.simplestyle.style( {} ) },
                        mapPosition = dialog.getInitialMapPosition();
 
                // TODO: Support 'style' editing
                dialog.MWMap = kartoLive.MWMap( dialog.$map[ 0 ], mapPosition );
-               dialog.map = dialog.MWMap.map;
+               dialog.MWMap.ready( function ( map ) {
 
-               dialog.updateGeoJson();
-               dialog.onDimensionsChange();
-               dialog.resetMapPosition();
+                       dialog.map = map;
 
-               geoJsonLayer = kartoEditing.getKartographerLayer( dialog.map );
-               drawControl = new L.Control.Draw( {
-                       edit: { featureGroup: geoJsonLayer },
-                       draw: {
-                               circle: false,
-                               // TODO: Determine metric preference from 
locale information
-                               polyline: defaultShapeOptions,
-                               polygon: defaultShapeOptions,
-                               rectangle: defaultShapeOptions,
-                               marker: { icon: L.mapbox.marker.icon( {} ) }
+                       dialog.updateGeoJson();
+                       dialog.onDimensionsChange();
+                       dialog.resetMapPosition();
+
+                       geoJsonLayer = kartoEditing.getKartographerLayer( map );
+                       drawControl = new L.Control.Draw( {
+                               edit: { featureGroup: geoJsonLayer },
+                               draw: {
+                                       circle: false,
+                                       // TODO: Determine metric preference 
from locale information
+                                       polyline: defaultShapeOptions,
+                                       polygon: defaultShapeOptions,
+                                       rectangle: defaultShapeOptions,
+                                       marker: { icon: L.mapbox.marker.icon( 
{} ) }
+                               }
+                       } ).addTo( map );
+
+                       function update() {
+                               // Prevent circular update of map
+                               dialog.updatingGeoJson = true;
+                               try {
+                                       dialog.input.setValue( JSON.stringify( 
geoJsonLayer.toGeoJSON(), null, '  ' ) );
+                               } finally {
+                                       dialog.updatingGeoJson = false;
+                               }
+                               dialog.updateActions();
                        }
-               } ).addTo( dialog.map );
 
-               function update() {
-                       // Prevent circular update of map
-                       dialog.updatingGeoJson = true;
-                       try {
-                               dialog.input.setValue( JSON.stringify( 
geoJsonLayer.toGeoJSON(), null, '  ' ) );
-                       } finally {
-                               dialog.updatingGeoJson = false;
+                       function created( e ) {
+                               e.layer.addTo( geoJsonLayer );
+                               update();
                        }
-                       dialog.updateActions();
-               }
 
-               function created( e ) {
-                       e.layer.addTo( geoJsonLayer );
-                       update();
-               }
+                       map
+                               .on( 'draw:edited', update )
+                               .on( 'draw:deleted', update )
+                               .on( 'draw:created', created );
 
-               dialog.map
-                       .on( 'draw:edited', update )
-                       .on( 'draw:deleted', update )
-                       .on( 'draw:created', created );
+               } );
        } );
 };
 
@@ -389,7 +392,6 @@
                        if ( this.map ) {
                                this.map.remove();
                                this.map = null;
-                               this.mapPromise = null;
                        }
                }, this );
 };

-- 
To view, visit https://gerrit.wikimedia.org/r/297107
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I534ad66ff2d0bb1bdfd8721b590c717dc808d58f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Kartographer
Gerrit-Branch: master
Gerrit-Owner: JGirault <julien.inbox.w...@gmail.com>
Gerrit-Reviewer: MaxSem <maxsem.w...@gmail.com>
Gerrit-Reviewer: Yurik <yu...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to