Lucas Werkmeister (WMDE) has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/384078 )
Change subject: WIP: handle geoshape loading errors more gracefully ...................................................................... WIP: handle geoshape loading errors more gracefully When a geoshape can’t be loaded, we should still draw a map with all the other layers. Change-Id: I219ac53e269bbf25e026eedba95c830c4b3f4fb6 --- M wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js 1 file changed, 50 insertions(+), 34 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui refs/changes/78/384078/1 diff --git a/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js b/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js index 3b3ef63..62747fe 100644 --- a/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js +++ b/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js @@ -138,11 +138,41 @@ */ SELF.prototype.draw = function( $element ) { var self = this, - container = $( '<div>' ).attr( 'id', 'map' ).height( '100vh' ); + container = $( '<div>' ).attr( 'id', 'map' ).height( '100vh' ), + interval; $element.html( container ); - this._createMarkerGroups().done( function() { + function clearProgress() { + clearInterval( interval ); + $( '#map-progress' ).remove(); + } + function updateProgress() { + if ( self._markerGroupsProgress > 0 && self._markerGroupsProgress < 1 ) { + var percent = ( 100 * self._markerGroupsProgress ).toFixed( 2 ), + message = self._i18n( + 'wdqs-result-map-progress', + 'Loading map data: $1%', + [ percent ] ); + container.html( + $( '<div>' ) + .attr( 'id', 'map-progress' ) + .css( { + position: 'relative', + top: '20%', + width: '100%', + textAlign: 'center' + } ) + .text( message ) + ); + } else if ( self._markerGroupsProgress >= 1 ) { + clearProgress(); + } + } + setInterval( updateProgress, 200 ); + + function drawMap() { + clearProgress(); self._map = L.map( 'map', { center: [ 0, 0 ], maxZoom: 18, @@ -157,34 +187,9 @@ self._createMarkerZoomResize(); $element.html( container ); - } ); + } - var interval = setInterval( - function() { - if ( self._markerGroupsProgress > 0 && self._markerGroupsProgress < 1 ) { - var percent = ( 100 * self._markerGroupsProgress ).toFixed( 2 ), - message = self._i18n( - 'wdqs-result-map-progress', - 'Loading map data: $1%', - [ percent ] ); - container.html( - $( '<div>' ) - .attr( 'id', 'map-progress' ) - .css( { - position: 'relative', - top: '20%', - width: '100%', - textAlign: 'center' - } ) - .text( message ) - ); - } else if ( self._markerGroupsProgress === 1 ) { - clearInterval( interval ); - $( '#map-progress' ).remove(); - } - }, - 200 - ); + this._createMarkerGroups().done( drawMap ).fail( drawMap ); }; /** @@ -319,23 +324,34 @@ } ); } } ); - markers[ layer ].push( marker ); + try { + markers[ layer ].push( marker ); + } catch ( e ) { + debugger; + } markers[ LAYER_DEFAULT_GROUP ].push( marker ); + } ).fail( function() { + // make sure no later success results in an apparently-valid donePromises <= 1 + // TODO why is this necessary? + // updateProgress should never run after the big $.when promise fails, + // but apparently it does + donePromises += promises.length; } ); } ); - return $.when.apply( $, promises ).done( function() { + function createMarkers() { if ( Object.keys( markers ).length === 0 ) { var marker = L.marker( [ 0, 0 ] ).bindPopup( 'Nothing found!' ).openPopup(); return { null: L.featureGroup( [marker] ) }; } + self._markerGroups = {}; $.each( markers, function( key ) { - markers[ key ] = L.featureGroup( markers[ key ] ); + self._markerGroups[ key ] = L.featureGroup( markers[ key ] ); } ); + } - self._markerGroups = markers; - } ); + return $.when.apply( $, promises ).done( createMarkers ).fail( createMarkers ); }; /** -- To view, visit https://gerrit.wikimedia.org/r/384078 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I219ac53e269bbf25e026eedba95c830c4b3f4fb6 Gerrit-PatchSet: 1 Gerrit-Project: wikidata/query/gui Gerrit-Branch: master Gerrit-Owner: Lucas Werkmeister (WMDE) <lucas.werkmeis...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits