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).

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": {
          "src": "https://cdn.jsdelivr.net/npm/leaflet@1.9.4/dist/images/marker-icon.png",
          "scale": 1,
          "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.3.tar.gz (5.8 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.3-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_osm_widgets-0.0.3.tar.gz
  • Upload date:
  • Size: 5.8 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.3.tar.gz
Algorithm Hash digest
SHA256 3e747e31660c865c232dd420d3f8eba3629b8f5d15eae827cbed8712bcf74db0
MD5 37c6ada78bb77337afcef442b18b9425
BLAKE2b-256 c2061e66e438a0e5af4198c86b44a1714f0af309f097743753658fb291bff55a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_osm_widgets-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bc08a05d9940cf53fcdb36b6c7e95970765476f6dd2f57bc4654130c4b65cabe
MD5 5c075b2786b327cfafe2dcce51da8357
BLAKE2b-256 65a7ef84322a3080ec2133fca1dd949ccf15241828749d9b33f0fcfc92dd1a62

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