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

Change subject: Added geomask backend support
......................................................................


Added geomask backend support

Bug: T146582
Change-Id: I487cfb199f361ea3555d7b8179b7ee39c52cf1d7
---
M includes/SimpleStyleParser.php
M lib/wikimedia-mapdata.js
M tests/phpunit/data/good-schemas/08-externaldata.json
3 files changed, 49 insertions(+), 6 deletions(-)

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



diff --git a/includes/SimpleStyleParser.php b/includes/SimpleStyleParser.php
index 5d942c9..28f1299 100644
--- a/includes/SimpleStyleParser.php
+++ b/includes/SimpleStyleParser.php
@@ -16,7 +16,7 @@
 class SimpleStyleParser {
        private static $parsedProps = [ 'title', 'description' ];
 
-       private static $services = [ 'geoshape', 'geoline' ];
+       private static $services = [ 'geoshape', 'geoline', 'geomask' ];
 
        /** @var Parser */
        private $parser;
@@ -218,7 +218,10 @@
                        $query['query'] = $object->query;
                }
 
-               $ret->url = "{$this->mapService}/{$object->service}?" . 
wfArrayToCgi( $query );
+               // 'geomask' service is the same as inverted geoshape service
+               // Kartotherian does not support it, request it as geoshape
+               $service = $object->service === 'geomask' ? 'geoshape' : 
$object->service;
+               $ret->url = "{$this->mapService}/{$service}?" . wfArrayToCgi( 
$query );
                if ( property_exists( $object, 'properties' ) ) {
                        $ret->properties = $object->properties;
                }
diff --git a/lib/wikimedia-mapdata.js b/lib/wikimedia-mapdata.js
index 75dc64c..c007739 100644
--- a/lib/wikimedia-mapdata.js
+++ b/lib/wikimedia-mapdata.js
@@ -189,9 +189,40 @@
 
     group.promise = getJSON( data.url ).then( function ( geodata ) {
       var baseProps = data.properties,
-          i;
+          geometry,
+          coordinates,
+          i, j;
 
       switch ( data.service ) {
+
+        case 'geomask':
+          // Mask-out the entire world 10 times east and west,
+          // and add each result geometry as a hole
+          coordinates = [ [ [ 3600, -180 ], [ 3600, 180 ], [ -3600, 180 ], [ 
-3600, -180 ], [ 3600, -180 ] ] ];
+          for ( i = 0; i < geodata.features.length; i++ ) {
+            geometry = geodata.features[ i ].geometry;
+            if ( !geometry ) {
+              continue;
+            }
+            // Only add the very first (outer) polygon
+            switch ( geometry.type ) {
+              case 'Polygon':
+                coordinates.push( geometry.coordinates[ 0 ] );
+                break;
+              case 'MultiPolygon':
+                for ( j = 0; j < geometry.coordinates.length; j++ ) {
+                  coordinates.push( geometry.coordinates[ j ][ 0 ] );
+                }
+                break;
+            }
+          }
+          data.type = 'Feature';
+          data.geometry = {
+            type: 'Polygon',
+            coordinates: coordinates
+          };
+          break;
+
         case 'geoshape':
         case 'geoline':
 
@@ -220,6 +251,9 @@
         default:
           throw new Error( 'Unknown externalData service ' + data.service );
       }
+
+      delete data.service;
+      delete data.url;
 
       if ( mwMsg ) {
         group.parseAttribution();
@@ -259,9 +293,9 @@
           }
         }
         group.attribution = mwMsg(
-          'kartographer-attribution-externaldata',
-          mwMsg( 'project-localized-name-wikidatawiki' ),
-          links
+            'kartographer-attribution-externaldata',
+            mwMsg( 'project-localized-name-wikidatawiki' ),
+            links
         );
         break;
     }
diff --git a/tests/phpunit/data/good-schemas/08-externaldata.json 
b/tests/phpunit/data/good-schemas/08-externaldata.json
index 5666746..945069b 100644
--- a/tests/phpunit/data/good-schemas/08-externaldata.json
+++ b/tests/phpunit/data/good-schemas/08-externaldata.json
@@ -68,5 +68,11 @@
                "service": "geoline",
                "query": "lalala",
                "ids": "Q1,Q2 , Q3"
+       },
+       {
+               "type": "ExternalData",
+               "service": "geomask",
+               "query": "lalala",
+               "ids": "Q1"
        }
 ]

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I487cfb199f361ea3555d7b8179b7ee39c52cf1d7
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/extensions/Kartographer
Gerrit-Branch: master
Gerrit-Owner: Yurik <[email protected]>
Gerrit-Reviewer: MaxSem <[email protected]>
Gerrit-Reviewer: Yurik <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to