Commits

Yohan Boniface committed 9badd5f

Preparing new tilelayer switcher

cf yohanboniface/Leaflet.Storage#56

Comments (0)

Files changed (4)

leaflet_storage/base_models.py

         """
         return cls.objects.order_by('rank')[0]  # FIXME, make it administrable
 
+    @classmethod
+    def get_list(cls, selected=None):
+        l = []
+        for t in cls.objects.all():
+            fields = t.json
+            if selected and selected.pk == t.pk:
+                fields['selected'] = True
+            l.append(fields)
+        return l
+
     class Meta:
         ordering = ('rank', 'name', )
 

leaflet_storage/forms.py

         ("embedControl", _("Do you want to display the embed control?"), True),
         ("scaleControl", _("Do you want to display the scale control?"), True),
         ("locateOnLoad", _("Do you want to locate user on load?"), False),
+        ("tileLayersControl", _("Do you want to display a tilelayer switcher?"), True),
         ("displayCaptionOnLoad", _("Do you want to display map caption on load?"), False),
         ("displayDataBrowserOnLoad", _("Do you want to display data browser on load?"), False),
         ("displayPopupFooter", _("Do you want to display popup footer?"), False),

leaflet_storage/urls.py

     url(r'^polygon/json/(?P<pk>[\d]+)/$', views.PolygonGeoJSON.as_view(), name='polygon_geojson'),
     url(r'^map/(?P<map_id>[\d]+)/export/iframe/$', views.EmbedMap.as_view(), name='map_embed'),
     url(r'^map/(?P<map_id>[\d]+)/infos/caption/$', views.MapInfos.as_view(), name='map_infos'),
-    url(r'^pictogram/json/$', views.PictogramJsonList.as_view(), name='pictogram_list_json'),
+    url(r'^pictogram/json/$', views.PictogramJSONList.as_view(), name='pictogram_list_json'),
     url(r'^map/(?P<map_id>[\d]+)/export/data/$', views.DownloadData.as_view(), name='download_data'),
 )
 urlpatterns += decorated_patterns('', [login_required_if_not_anonymous_allowed, never_cache, ],

leaflet_storage/views.py

         datalayer_data = [l.json for l in datalayers]
         map_settings['datalayers'] = datalayer_data
         map_settings['urls'] = _urls_for_js()
-        map_settings['tilelayers'] = self.object.tilelayers_data
+        map_settings['tilelayers'] = TileLayer.get_list(selected=self.object.tilelayers.all()[0])
         map_settings['name'] = self.object.name
         map_settings['description'] = self.object.description
         if settings.USE_I18N:
             'editInOSMControl': 0,
             'scaleControl': 0,
             'miniMap': 0,
+            'tileLayersControl': 0,
         }
         query_string = "&".join("%s=%s" % (k, v) for k, v in qs_kwargs.iteritems())
         iframe_url = "%s?%s" % (iframe_url, query_string)
 #     Picto      #
 # ############## #
 
-class PictogramJsonList(ListView):
+class PictogramJSONList(ListView):
     model = Pictogram
 
     def render_to_response(self, context, **response_kwargs):