Lucas Werkmeister (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/361208 )

Change subject: Add support for linestring geo literals
......................................................................

Add support for linestring geo literals

_extractLongLat is changed to _extractLongLats and returns an array of
coordinate pairs instead of a single pair, and learns to parse
linestring literals into such a list of coordinate pairs.
_createMarkerGroups turns a single coordinate pair into a circle marker
(as before) and more pairs into a polyline. Since polylines need
slightly different styles than cirle markers, two new methods for their
styles are added, and _createMarkerGroups stores all circle markers in
one feature group and all polyline markers in another; the zoomend event
handler then updates the styles of those two feature groups instead of
the default layer group.

There are no linestring literals on Wikidata, but they can be obtained
via federation (e. g. LinkedGeoData.org). The distinction between
multiple marker styles introduced here may also be useful for geoshape
support later.

Change-Id: I414ecb3c49328829ae13ae34e8b3f4a76efc6d92
---
M wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
1 file changed, 70 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/wikidata/query/gui 
refs/changes/08/361208/1

diff --git a/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js 
b/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
index e753556..b761611 100644
--- a/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
+++ b/wikibase/queryService/ui/resultBrowser/CoordinateResultBrowser.js
@@ -87,6 +87,18 @@
        SELF.prototype._getMarkerGroupColor = null;
 
        /**
+        * Contains all map markers that are circles.
+        * @private
+        */
+       SELF.prototype._circleMarkers = null;
+
+       /**
+        * Contains all map markers that are polylines.
+        * @private
+        */
+       SELF.prototype._polylineMarkers = null;
+
+       /**
         * Draw a map to the given element
         *
         * @param {jQuery} $element target element
@@ -161,8 +173,11 @@
                }
 
                var resize = function() {
-                       self._markerGroups[LAYER_DEFAULT_GROUP].setStyle( {
+                       self._circleMarkers.setStyle( {
                                radius: self._getMarkerRadius()
+                       } );
+                       self._polylineMarkers.setStyle( {
+                               weight: 2 * self._getMarkerRadius()
                        } );
                };
 
@@ -208,23 +223,36 @@
         */
        SELF.prototype._createMarkerGroups = function() {
                var self = this,
-                       markers = {};
+                       markers = {},
+                       circleMarkers = [],
+                       polylineMarkers = [];
                markers[ LAYER_DEFAULT_GROUP ] = [];
 
                this._iterateResult( function( field, key, row ) {
                        if ( field && field.datatype === MAP_DATATYPE ) {
-                               var longLat = self._extractLongLat( field.value 
);
-                               if ( longLat === null || !longLat[0] || 
!longLat[1] ) {
+                               var longLats = self._extractLongLats( 
field.value );
+                               if ( longLats === null || longLats.length === 0 
) {
                                        return true;
                                }
 
                                var popup = L.popup(),
-                                       lon = longLat[0],
-                                       lat = longLat[1];
+                                       layer = self._getMarkerGroupsLayer( row 
),
+                                       marker;
 
-                               var layer = self._getMarkerGroupsLayer( row );
-                               var marker = L.circleMarker( [ lat, lon ], 
self._getMarkerStyle( layer ) )
-                                       .bindPopup( popup );
+                               if ( longLats.length === 1 ) {
+                                       var lon = longLats[0][0],
+                                               lat = longLats[0][1];
+                                       marker = L.circleMarker( [ lat, lon ], 
self._getCircleMarkerStyle( layer ) );
+                                       circleMarkers.push( marker );
+                               } else {
+                                       var latLongs = [];
+                                       $.each( longLats, function( index, 
longLat ) {
+                                               latLongs.push( [ longLat[1], 
longLat[0] ] );
+                                       } );
+                                       marker = L.polyline( latLongs, 
self._getPolylineMarkerStyle( layer ) );
+                                       polylineMarkers.push( marker );
+                               }
+                               marker.bindPopup( popup );
 
                                marker.on( 'click', function() {
                                        var info = self._getItemDescription( 
row );
@@ -249,6 +277,8 @@
                } );
 
                this._markerGroups = markers;
+               this._circleMarkers = L.featureGroup( circleMarkers );
+               this._polylineMarkers = L.featureGroup( polylineMarkers );
        };
 
        /**
@@ -284,21 +314,45 @@
 
        /**
         * @private
+        * @param {string} group
         */
-       SELF.prototype._extractLongLat = function( point ) {
-               var globe = this._extractGlobe( point );
+       SELF.prototype._getCircleMarkerStyle = function( group ) {
+               var style = this._getMarkerStyle( group );
+               style.radius = this._getMarkerRadius();
+               return style;
+       };
+
+       /**
+        * @private
+        * @param {string} group
+        */
+       SELF.prototype._getPolylineMarkerStyle = function( group ) {
+               var style = this._getMarkerStyle( group );
+               style.weight = 2 * this._getMarkerRadius();
+               return style;
+       };
+
+       /**
+        * @private
+        */
+       SELF.prototype._extractLongLats = function( point ) {
+               var globe = this._extractGlobe( point ),
+                       match;
 
                if ( globe !== null && globe !== GLOBE_EARTH ) {
                        return null;
                }
 
-               var match = point.match( /Point\((.*)\)/i );
-
-               if ( !match ) {
-                       return null;
+               if ( ( match = point.match( /Point\((.*)\)/i ) ) ) {
+                       return [ match.pop().split( ' ' ) ];
+               }
+               if ( ( match = point.match( /Linestring\((.*)\)/i ) ) ) {
+                       return $.map( match.pop().split( ',' ), function( s ) {
+                               return [ s.split( ' ' ) ]; // extra [] because 
jQuery flattens returned arrays into one
+                       } );
                }
 
-               return match.pop().split( ' ' );
+               return null;
        };
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I414ecb3c49328829ae13ae34e8b3f4a76efc6d92
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

Reply via email to