From bf4928326fa0d318ba80ea9551aa70a41316d16b Mon Sep 17 00:00:00 2001
From: blavenie <benoit.lavenier@e-is.pro>
Date: Thu, 8 Feb 2018 16:07:08 +0100
Subject: [PATCH] [fix] Add freegeopip IP geo-resolution attribution, at the
 bottom-right of the map -fix #670

---
 www/plugins/es/js/services/geo-services.js    | 22 ++++++++++++++-----
 .../map/js/controllers/network-controllers.js |  9 +++++++-
 2 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/www/plugins/es/js/services/geo-services.js b/www/plugins/es/js/services/geo-services.js
index f3591568a..960977828 100644
--- a/www/plugins/es/js/services/geo-services.js
+++ b/www/plugins/es/js/services/geo-services.js
@@ -28,7 +28,13 @@ angular.module('cesium.es.geo.services', ['cesium.services', 'cesium.es.http.ser
         apiKey: undefined,
         search: csHttp.get('maps.google.com', 443, '/maps/api/geocode/json')
       },
-      searchByIP: csHttp.get('freegeoip.net', 443, '/json/:ip')
+      freegeoip: {
+        search: csHttp.get('freegeoip.net', 443, '/json/:ip'),
+        license: {
+          name: 'freegeoip',
+          url: 'https://freegeoip.net'
+        }
+      }
     };
 
     function _normalizeAddressString(text) {
@@ -148,10 +154,13 @@ angular.module('cesium.es.geo.services', ['cesium.services', 'cesium.es.http.ser
       //var now = new Date();
       //console.debug('[ES] [geo] Searching IP position [{0}]...'.format(ip));
 
-      return that.raw.searchByIP({ip: ip})
+      return that.raw.freegeoip.search({ip: ip})
         .then(function(res) {
           //console.debug('[ES] [geo] Found IP {0} position in {0}ms'.format(res ? 1 : 0, new Date().getTime() - now.getTime()));
-          return res ? {lat: res.latitude,lng: res.longitude} : undefined;
+          return res ? {
+            lat: res.latitude,
+            lng: res.longitude
+          } : undefined;
         });
     }
 
@@ -196,8 +205,11 @@ angular.module('cesium.es.geo.services', ['cesium.services', 'cesium.es.http.ser
       point: {
         current: getCurrentPosition,
         searchByAddress: searchPositionByAddress,
-        searchByIP: searchPositionByIP,
-        distance: getDistance
+        distance: getDistance,
+        ip: {
+          search: searchPositionByIP,
+          license: that.raw.freegeoip.license
+        }
       },
       google: {
         isEnable: function() {
diff --git a/www/plugins/map/js/controllers/network-controllers.js b/www/plugins/map/js/controllers/network-controllers.js
index 7af3489df..6ee819bc7 100644
--- a/www/plugins/map/js/controllers/network-controllers.js
+++ b/www/plugins/map/js/controllers/network-controllers.js
@@ -221,6 +221,13 @@ angular.module('cesium.map.network.controllers', ['cesium.services', 'cesium.map
             angular.extend(layer, L.featureGroup.subGroup(markerClusterLayer));
           }
         });
+        if (esGeo.point.ip.license) {
+          markerClusterLayer.getAttribution = function() {
+            return '<a target=\"_blank\" href="{0}">{1}</a>'.format(
+              esGeo.point.ip.license.url,
+              esGeo.point.ip.license.name);
+          };
+        }
         markerClusterLayer.addTo(map);
 
         //$scope.map.layers.overlays['offline'].visible=false;
@@ -255,7 +262,7 @@ angular.module('cesium.map.network.controllers', ['cesium.services', 'cesium.map
         // Get position by IP
         var bma = peer.bma;
         var address = peer.hasValid4(bma) ? bma.ipv4 : (bma.dns || bma.ipv6);
-        esGeo.point.searchByIP(address)
+        esGeo.point.ip.search(address)
 
         // Create the marker
           .then(function(position){// Add marker to list
-- 
GitLab