Yohan Boniface avatar Yohan Boniface committed e51a9e6

Handle path styling options (see yohanboniface/Leaflet.Storage#26)

Comments (0)

Files changed (4)

+# django-leaflet-storage changelog
+
+## 0.1.x
+
+- handle map settings management from front-end
+- handle path styling options (https://github.com/yohanboniface/Leaflet.Storage/issues/26)
+
+## 0.1.0
+
+- first packaged version

leaflet_storage/CHANGELOG.md

-# django-leaflet-storage changelog
-
-## 0.1.x
-
-- handle map settings management from front-end
-
-## 0.1.0
-
-- first packaged version

leaflet_storage/forms.py

 
 from vectorformats.formats import geojson, kml, gpx
 
-from .models import Map, Category
+from .models import Map, Category, Polyline, Polygon, Marker
 
 
 class PlaceholderForm(forms.ModelForm):
         fields = ('edit_status', 'editors')
 
 
-class CategoryForm(OptionsForm):
-
-    options_color = forms.CharField(
-        required=False,
-        label=_('color'),
-        help_text=_("Must be a CSS valid name (eg.: DarkBlue or #123456)")
-    )
-
-    class Meta:
-        model = Category
-        widgets = {
-            "map": forms.HiddenInput()
-        }
-
-
 class UploadDataForm(forms.Form):
 
     JSON = "json"
         return features
 
 
+class PathStyleMixin(forms.ModelForm):
+    options_smoothFactor = forms.FloatField(
+        required=False,
+        label=_('Path smooth factor'),
+        help_text=_("How much to simplify the polyline on each zoom level "
+                    "(more = better performance and smoother look, less = more accurate)")
+    )
+    options_opacity = forms.FloatField(
+        required=False,
+        min_value=0.1,
+        max_value=10,
+        label=_('Path opacity'),
+        help_text=_("Opacity, from 0.1 to 1.0 (opaque).")
+    )
+    options_stroke = forms.BooleanField(
+        required=False,
+        initial=True,
+        label=_('Polygon stroke'),
+        help_text=_("Whether to display or not the Polygon path.")
+    )
+    options_weight = forms.IntegerField(
+        required=False,
+        min_value=0,
+        max_value=10,
+        label=_('Path weight'),
+        help_text=_("Path weight in pixels. Max: 10.")
+    )
+    options_fill = forms.BooleanField(
+        required=False,
+        initial=True,
+        label=_('Path fill'),
+        help_text=_("Whether to fill the path with color.")
+    )
+    options_fillOpacity = forms.FloatField(
+        required=False,
+        min_value=0.1,
+        max_value=10,
+        label=_('Fill opacity'),
+        help_text=_("Fill opacity, from 0.1 to 1.0 (opaque).")
+    )
+    options_fillColor = forms.CharField(
+        required=False,
+        label=_('Fill color'),
+        help_text=_("Optional. Same as color if not set.")
+    )
+    options_dashArray = forms.CharField(
+        required=False,
+        label=_('Dash array'),
+        help_text=_("A string that defines the stroke dash pattern. Ex.: '5, 10, 15'.")
+    )
+
+
+class CategoryForm(OptionsForm, PathStyleMixin):
+
+    options_color = forms.CharField(
+        required=False,
+        label=_('color'),
+        help_text=_("Must be a CSS valid name (eg.: DarkBlue or #123456)")
+    )
+
+    class Meta:
+        model = Category
+        widgets = {
+            "map": forms.HiddenInput()
+        }
+
+
 class FeatureForm(OptionsForm):
 
     options_color = forms.CharField(
         required=False,
         label=_('color'),
-        help_text=_("Optional. Uses category color if not set. ")
+        help_text=_("Optional. Category color is used if not set.")
     )
 
+
+class PolygonForm(FeatureForm, PathStyleMixin):
+
+    class Meta:
+        model = Polygon
+        fields = ('name', 'description', 'category', 'latlng')
+        widgets = {
+            'latlng': forms.HiddenInput(),
+        }
+
+
+class PolylineForm(FeatureForm, PathStyleMixin):
+
+    def __init__(self, *args, **kwargs):
+        super(PolylineForm, self).__init__(*args, **kwargs)
+        self.fields["options_fill"].initial = False
+
+    class Meta:
+        fields = ('name', 'description', 'category', 'latlng')
+        model = Polyline
+        widgets = {
+            'latlng': forms.HiddenInput(),
+        }
+
+
+class MarkerForm(FeatureForm):
+
     class Meta:
-        # model is added at runtime by the views
         fields = ('name', 'description', 'category', 'latlng')
+        model = Marker
         widgets = {
             'latlng': forms.HiddenInput(),
         }

leaflet_storage/views.py

                      MapToTileLayer, Polygon)
 from .utils import get_uri_template
 from .forms import (QuickMapCreateForm, UpdateMapExtentForm, CategoryForm,
-                    UploadDataForm, UpdateMapPermissionsForm, FeatureForm,
-                    MapSettingsForm)
+                    UploadDataForm, UpdateMapPermissionsForm, MapSettingsForm,
+                    MarkerForm, PolygonForm, PolylineForm)
 
 
 # ############## #
 
 
 class FeatureAdd(CreateView):
-    form_class = FeatureForm
 
     def get_success_url(self):
         return reverse_lazy(self.geojson_url, kwargs={"pk": self.object.pk})
         return render_to_json(self.get_template_names(), response_kwargs, context, self.request)
 
     def get_form(self, form_class):
-        form_class = modelform_factory(self.model, form=form_class)
         form = super(FeatureAdd, self).get_form(form_class)
         map_inst = self.kwargs['map_inst']
         categories = Category.objects.filter(map=map_inst)
 
 
 class FeatureUpdate(UpdateView):
-    form_class = FeatureForm
 
     def get_success_url(self):
         return reverse_lazy(self.geojson_url, kwargs={"pk": self.object.pk})
 
     # TODO: factorize with FeatureAdd!
     def get_form(self, form_class):
-        form_class = modelform_factory(self.model, form=form_class)
         form = super(FeatureUpdate, self).get_form(form_class)
         map_inst = self.kwargs['map_inst']
         form.fields['category'].queryset = Category.objects.filter(map=map_inst)
     model = Marker
     geojson_url = 'marker_geojson'
     delete_url = "marker_delete"
+    form_class = MarkerForm
 
 
 class MarkerAdd(FeatureAdd):
     model = Marker
     geojson_url = 'marker_geojson'
+    form_class = MarkerForm
 
 
 class PolylineView(FeatureView):
 class PolylineAdd(FeatureAdd):
     model = Polyline
     geojson_url = 'polyline_geojson'
+    form_class = PolylineForm
 
 
 class PolylineUpdate(FeatureUpdate):
     model = Polyline
     geojson_url = 'polyline_geojson'
     delete_url = "polyline_delete"
+    form_class = PolylineForm
 
 
 class PolylineDelete(FeatureDelete):
 class PolygonAdd(FeatureAdd):
     model = Polygon
     geojson_url = 'polygon_geojson'
+    form_class = PolygonForm
 
 
 class PolygonUpdate(FeatureUpdate):
     model = Polygon
     geojson_url = 'polygon_geojson'
     delete_url = "polygon_delete"
+    form_class = PolygonForm
 
 
 class PolygonDelete(FeatureDelete):
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.