Example #1
0
class AlienActivityForm(forms.Form):
    """ Example of olwidget in a custom form. """
    incident_name = forms.CharField()
    # Old style single field invocation
    landings = MapField([EditableLayerField({
            'geometry': 'point',
            'is_collection': True,
            'overlay_style': {
                'external_graphic': settings.MEDIA_URL+"alien.png",
                'graphic_width': 21,
                'graphic_height': 25,
            },
            'name': 'Landings',
        })])
    # Define a map to edit two geometry fields
    other_stuff = MapField([
            EditableLayerField({'geometry': ['point', 'linestring', 'polygon'],
                'is_collection': True, 'name': "Strange lights",
                'overlay_style': {
                    'fill_color': '#FFFF00',
                    'stroke_color': '#FFFF00',
                    'stroke_width': 6,
                }
            }),
            EditableLayerField({'geometry': 'linestring',
                'is_collection': True, 'name': "Chemtrails",
                'overlay_style': {
                    'fill_color': '#ffffff',
                    'stroke_color': '#ffffff',
                    'stroke_width': 6,
                },
            }),
        ])
Example #2
0
class RequirednessForm(forms.Form):
    optional = MapField(
            fields=[EditableLayerField(required=False, options={
                'geometry': 'point',
                'name': 'optional',
            })],
            options={
                'overlay_style': {'fill_color': '#00ff00'},
            })
    required = MapField(
            fields=[EditableLayerField(required=True, options={
                'geometry': 'point',
                'name': 'required',
            })],
            options={
                'overlay_style': {'fill_color': '#00ff00'},
            })
    unspecified = MapField(
            fields=[EditableLayerField({
                'geometry': 'point',
                'name': 'unspecified',
            })],
            options={
                'overlay_style': {'fill_color': '#00ff00'},
            })
Example #3
0
 class MyInfoModelForm(MapModelForm):
     start = MapField([
         EditableLayerField({'name': 'start'}),
         InfoLayerField([[Point(0, 0, srid=4326), "Of interest"]]),
     ])
     class Meta:
         model = MyModel
Example #4
0
class TestAdminForm(forms.ModelForm):
    boundary = MapField([
        EditableLayerField({'geometry': 'polygon', 'name': 'boundary', 'is_collection': True}),
        InfoLayerField([["SRID=4326;POINT (0 0)", "Of Interest"]], {"name": "Test"}),
    ], { 'overlay_style': { 'fill_color': '#00ff00' }}, 
    template="olwidget/admin_olwidget.html")

    def clean(self):
        self.cleaned_data['boundary'] = self.cleaned_data['boundary'][0]
        return self.cleaned_data

    class Meta:
        model = Country
Example #5
0
 def __init__(self, fields=None, options=None, layer_names=None,
              template=None, **kwargs):
     merged_options = deepcopy(OLWIDGET_DEFAULT_OPTIONS)
     if options:
         merged_options.update(options)
     if not fields:
         fields = [EditableLayerField(required=kwargs.get('required'))]
     layers = [field.widget for field in fields]
     self.fields = fields
     kwargs['widget'] = kwargs.get(
         'widget',
         OBMapWidget(layers, merged_options, template, layer_names))
     super(OBMapField, self).__init__(fields=fields, options=merged_options,
                                      layer_names=layer_names,
                                      template=template, **kwargs)
Example #6
0
class MixedForm(forms.Form):
    capitals = MapField([
        InfoLayerField([[c.boundary, c.about] for c in Country.objects.all()],
            {
                'overlay_style': {
                    'fill_opacity': 0,
                    'stroke_color': "white",
                    'stroke_width': 6,
                }, 
                'name': "Country boundaries",
            }),
        EditableLayerField({
            'geometry': 'point',
            'name': "Country capitals",
            'is_collection': True,
        }),
        ], {'layers': ['google.satellite']})
Example #7
0
class CustomTreeForm(MapModelForm):
    # set options for individual geometry fields by explicitly declaring the
    # field type.  If not declared, defaults will be used.
    location = EditableLayerField(
        {'overlay_style': {
            'stroke_color': '#ffff00',
        }})

    class Meta:
        model = Tree
        # Define a single map to edit two geometry fields, with options.
        maps = ((('root_spread', 'location'), {
            'layers': ['google.streets', 'osm.mapnik'],
            'overlay_style': {
                'fill_color': 'brown',
                'fill_opacity': 0.2,
                'stroke_color': 'green',
            }
        }), )
Example #8
0
class PolySearchForm(forms.Form):
    poly = MapField(
        fields=[
            EditableLayerField({
                'geometry': 'polygon',
                'name': _('polygon')
            }),
        ],
        options={
            "default_lat": 41.6,
            "default_lon": 22,
            "default_zoom": 8,
            "map_div_style": {
                "width": "600px",
                "height": "300px",
            }
        },
        label="",
        required=False,
    )
Example #9
0
 class MyMultiForm(forms.Form):
     mymap = MapField((
         EditableLayerField({'name': 'Fun'}),
         InfoLayerField([[Point(0, 0, srid=4326), "that"]]),
         EditableLayerField(),
     ))
Example #10
0
 class MixedForm(forms.Form):
     stuff = MapField([
         InfoLayerField([["SRID=4326;POINT(0 0)", "Origin"]]),
         EditableLayerField({'geometry': 'point'}),
     ])