Skip to main content

Improved widgets for Django's PointField

Project description

django-osm-widgets

Improved widgets for Django's PointField.

LatLonOpenlayersOSMWidget handles latitude and longitude inputs synced with the point on the map.

Example of the LatLonOpenlayersOSMWidget on a page

Requirements

  • Python 3.10+
  • Django >=3.0, <5.2

Installation

  • run pip install django-osm-widgets
  • add django_osm_widgets to your INSTALLED_APPS

Usage

In your forms, use the widget like this:

from django.contrib.gis.forms.fields import PointField
from django_osm_widgets.fields import LatLonOpenlayersOSMWidget


class MyForm(forms.Form):
  location = PointField(widget=LatLonOpenlayersOSMWidget)

The latitute and longitude fields will be automatically added in your page.

Customizations

You can define some options as in the example below.

When using "must_display_latlon_fields": False, your are responsible for providing two input fields in your page. These fields must have ids corresponding to latitude_field_id and longitude_field_id values (defaults to id_osm_widget_latitude and id_osm_widget_longitude).

import json
from django.contrib.gis.forms.fields import PointField
from django_osm_widgets.fields import LatLonOpenlayersOSMWidget


class MyForm(forms.Form):
  location = PointField(
    widget=LatLonOpenlayersOSMWidget(
      attrs={
        "must_display_latlon_fields": False,
        "map_width": "auto",
        "map_height": "auto",
        "default_lat": 45,
        "default_lon": 5,
        "default_zoom": 8,
        "latitude_field_id": "id_osm_widget_latitude",
        "longitude_field_id": "id_osm_widget_longitude",
        "listened_events": "input",
        "marker_options": json.dumps({
          "src": "/static/django_osm_widgets/marker.svg",
          "scale": 1.5,
          "anchor": [0.5, 1],
        })
        "precision": 4,
      }
    )
  )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_osm_widgets-0.0.2.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_osm_widgets-0.0.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file django_osm_widgets-0.0.2.tar.gz.

File metadata

  • Download URL: django_osm_widgets-0.0.2.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for django_osm_widgets-0.0.2.tar.gz
Algorithm Hash digest
SHA256 6c24c753322f35eacbb1766fa67c9176cb8fa44de556f1f575e2e3378ccd8a72
MD5 f29b4f77e7410ef825b03a25e2c27cb0
BLAKE2b-256 fa8db25a23ab982bcbcfe15784c6bc6be51d93bdaf5871c3a6d648e1c51f2d83

See more details on using hashes here.

File details

Details for the file django_osm_widgets-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_osm_widgets-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6897a58970685ac4645790b1592d425f39d421c2d98cb66f44c62fdfcc21886c
MD5 7cf9e1718cc9ce6a2c3228c1f0dd3263
BLAKE2b-256 3a336380d4d39811c78851a113cedd8e676b4e74a5743f064945b7e5efec1981

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page