Procházet zdrojové kódy

[core] Made Leaflet tile layer and attribution configurable

Enrico Berti před 10 roky
rodič
revize
c00a4474a7

+ 7 - 0
desktop/conf.dist/hue.ini

@@ -111,6 +111,13 @@
   # Use Google Analytics to see how many times an application or specific section of an application is used, nothing more.
   ## collect_usage=true
 
+  # Tile layer server URL for the Leaflet map charts
+  # Read more on http://leafletjs.com/reference.html#tilelayer
+  ## leaflet_tile_layer=http://{s}.tile.osm.org/{z}/{x}/{y}.png
+
+  # The copyright message for the specified Leaflet maps Tile Layer
+  ## leaflet_tile_layer_attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
+
   # Enable X-Forwarded-Host header if the load balancer requires it.
   ## use_x_forwarded_host=false
 

+ 7 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -115,6 +115,13 @@
   # Use Google Analytics to see how many times an application or specific section of an application is used, nothing more.
   ## collect_usage=true
 
+  # Tile layer server URL for the Leaflet map charts
+  # Read more on http://leafletjs.com/reference.html#tilelayer
+  ## leaflet_tile_layer=http://{s}.tile.osm.org/{z}/{x}/{y}.png
+
+  # The copyright message for the specified Leaflet maps Tile Layer
+  ## leaflet_tile_layer_attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
+
   # Enable X-Forwarded-Host header if the load balancer requires it.
   ## use_x_forwarded_host=false
 

+ 12 - 0
desktop/core/src/desktop/conf.py

@@ -269,6 +269,18 @@ COLLECT_USAGE = Config(
   type=coerce_bool,
   default=True)
 
+LEAFLET_TILE_LAYER = Config(
+  key="leaflet_tile_layer",
+  help=_("Tile layer server URL for the Leaflet map charts. Read more on http://leafletjs.com/reference.html#tilelayer"),
+  type=coerce_str_lowercase,
+  default="http://{s}.tile.osm.org/{z}/{x}/{y}.png")
+
+LEAFLET_TILE_LAYER_ATTRIBUTION = Config(
+  key="leaflet_tile_layer_attribution",
+  help=_("The copyright message for the specified Leaflet maps Tile Layer"),
+  type=coerce_str_lowercase,
+  default="&copy; <a href='http://osm.org/copyright'>OpenStreetMap</a> contributors")
+
 POLL_ENABLED = Config(
   key="poll_enabled",
   help=_("Use poll(2) in Hue thrift pool."),

+ 9 - 2
desktop/core/src/desktop/static/desktop/js/ko.charts.js

@@ -373,8 +373,15 @@
           try {
             if (_map == null) {
               _map = L.map(element);
-              L.tileLayer("http://{s}.tile.osm.org/{z}/{x}/{y}.png", {
-                attribution: $(element).width() > 300 ? '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' : ''
+              var tileLayerOptions = {
+                layer: 'http://{s}.tile.osm.org/{z}/{x}/{y}.png',
+                attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
+              }
+              if (LeafletGlobals) {
+                tileLayerOptions = LeafletGlobals
+              }
+              L.tileLayer(tileLayerOptions.layer, {
+                attribution: $(element).width() > 300 ? tileLayerOptions.attribution : ''
               }).addTo(_map);
 
               if (L.control.zoomBox) {

+ 5 - 0
desktop/core/src/desktop/templates/common_header.mako

@@ -141,6 +141,11 @@ from django.utils.translation import ugettext as _
       }
     };
 
+    LeafletGlobals = {
+      layer: '${ leaflet['layer'] |n,unicode }',
+      attribution: '${ leaflet['attribution'] |n,unicode }'
+    };
+
   </script>
 
   <!--[if lt IE 9]>

+ 4 - 0
desktop/core/src/desktop/views.py

@@ -389,6 +389,10 @@ def commonheader(title, section, user, padding="90px", skip_topbar=False):
     'padding': padding,
     'user': user,
     'skip_topbar': skip_topbar,
+    'leaflet': {
+      'layer': desktop.conf.LEAFLET_TILE_LAYER.get(),
+      'attribution': desktop.conf.LEAFLET_TILE_LAYER_ATTRIBUTION.get()
+    },
     'is_demo': desktop.conf.DEMO_ENABLED.get(),
     'is_ldap_setup': 'desktop.auth.backend.LdapBackend' in desktop.conf.AUTH.BACKEND.get()
   })