Skip to content

Commit

Permalink
Mapbox point field widget (#131)
Browse files Browse the repository at this point in the history
* Add Mapbox poing field widget
* Fix undefined place object binding issue in javascript triggers
* Update documentation for MapBox widget
* Tidy up localization files
  • Loading branch information
erdem authored May 16, 2022

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
1 parent 2aaa088 commit 495d985
Showing 68 changed files with 10,807 additions and 449 deletions.
58 changes: 15 additions & 43 deletions README.md
Original file line number Diff line number Diff line change
@@ -9,7 +9,10 @@ Configurable, pluggable and more user friendly map widgets for Django PostGIS fi
* **Project Home Page**: <a href="https://github.com/erdem/django-map-widgets">https://github.com/erdem/django-map-widgets/</a>

### Achievements
The aim of the Django map widgets is to make all Geo Django widgets more user friendly and configurable. Map widgets are currently supporting only Google Map services, but we are planning to add other major map services.
The aim of the Django map widgets is to make all Geo Django widgets more user-friendly and configurable.

Django map widgets package has support for Mapbox and Google Map services currently, if you want to see more widgets and think you can help, feel free to contribute to the project.
We would be happy to review and merge your contributions. :)

### Installation

@@ -94,63 +97,32 @@ This widget is working with <a href="http://dimsemenov.com/plugins/magnific-popu

### Release Notes

#### v0.3.3
#### 0.4.0
> - Supported MapBox Map for Django Geo Point Field.
> - Fixed undefined place object binding issue in javascript triggers. (#125)
> - Documented MapBox point field map widget features.
> - Updated various localize files.
#### 0.3.3

> - Replaced [ugettext_lazy](https://github.com/erdem/django-map-widgets/pull/127) usages with [gettext_lazy](https://docs.djangoproject.com/en/4.0/releases/4.0/#features-removed-in-4-0) for Django 4.0. (#127)
> - Updated [Travis CI file](https://github.com/erdem/django-map-widgets/pull/129). (#129)

#### v0.3.2
#### 0.3.2

> - Added [streetViewControl](https://developers.google.com/maps/documentation/javascript/streetview#StreetViewMapUsage) switch to GooglePointFieldWidget settings. (#124)
#### v0.3.1
#### 0.3.1

> - Removed `six` package usages. (#117)
> - Added a new general widget setting in order to specify Google JS libraries. (#119)
> - Implemented some improvements for the demo project.
#### v0.3.0
#### 0.3.0

> - Implemented a new demo project with Django 2.x.
> - Fixed Django Admin jQuery conflicts. (#100)
> - Fixed a new widget JS instance initialising issue for Django Admin Inlines. (#84)
> - Added Python 3.8 env settings to TravisCI configuration.

#### v0.2.3

> - Fixed python `six` module import issue.
> - Fixed PostGIS setup errors in CI pipeline.
> - Added Estonian language support.
#### v0.2.0

> - Fixed Python 3.6, Django 2.x compatible issues.
> - Fixed SRID format converter issues.
> - Removed `pyproj` package dependency.
> - Various development infrastructure updates. (Docker, Fabric files etc.)
> - Point map widget JS objects associated to the map HTML elements with jQuey `$.data` method.
> - Passing Google Place AutoComplete full response object to jQuery triggers.
#### v0.1.9

> - Google Place Autocomplete object binding to jQuery triggers.
> - Implemented Google Geocoding support for the marker coordinates.
> - Added custom widget settings feature for each widget.
> - Added Portuguese localisation support.
> - Fixed Google Place Autocomplete widget bugs in Django Admin Inlines.
> - Fixed Python 3.6 errors.
> - Fixed Javascript bugs.
> - The GitHub repository Integrated with Travis CI.
> - Implemented unit tests for backend code. (%100 code coverage)
> - Change development environment from Vagrant to Docker.

#### v0.1.8

> - Full documentation integrated to readthedocs.org.
> - Fixed Google Map static widget issues.
> - Added Russian localisation support.
> - Added [Google Places Autocomplete] options support.
> - Fixed CSS issues.
[See release notes](https://django-map-widgets.readthedocs.io/en/mapbox_widget_fixes/releases/index.html) for all versions.
64 changes: 17 additions & 47 deletions README.rst
Original file line number Diff line number Diff line change
@@ -15,14 +15,19 @@ Django Map Widgets

Configurable, pluggable and more user friendly map widgets for Django PostGIS fields.

.. note::
Check the `project home page <https://github.com/erdem/django-map-widgets/>`_ for latest updates.

* **Project Home Page** : `https://github.com/erdem/django-map-widgets <https://github.com/erdem/django-map-widgets/>`_.
* **Documentation**: `http://django-map-widgets.readthedocs.io <http://django-map-widgets.readthedocs.io/>`_.

Achievements
^^^^^^^^^^^^

The aim of the Django map widgets is to make all Geo Django widgets more user friendly and configurable. Map widgets are currently supporting only Google Map services, but we are planning to add other major map services.

| The aim of the Django map widgets is to make all Geo Django widgets more user-friendly and configurable.
|
| Django map widgets package has support for Mapbox and Google Map services currently, if you want to see more widgets and think you can help, feel free to contribute to the project.
| We would be happy to review and merge your contributions. :)
Installation
^^^^^^^^^^^^
@@ -100,6 +105,16 @@ Google Map Static Overlay Widget
Release Notes
^^^^^^^^^^^^^

=====
0.4.0
=====

* Supported MapBox Map for Geo Point Field
* Fixed undefined place object binding issue in javascript triggers. (#125)
* Documented MapBox point field map widget
* Updated various localize files.


======
v0.3.2
======
@@ -122,48 +137,3 @@ v0.3.0
* Fixed Django Admin jQuery conflicts. (#100)
* Fixed a new widget JS instance initialising issue for Django Admin Inlines. (#84)
* Added Python 3.8 env settings to TravisCI configuration.

======
v0.2.3
======

* Fixed python `six` module import issue.
* Fixed PostGIS setup errors in CI pipeline.
* Added Estonian language support.

======
v0.2.0
======

* Fixed Python 3.6, Django 2.x compatible issues.
* Fixed SRID format converter issues.
* Removed pyproj package dependency.
* Various development infrastructure updates. (Docker, Fabric files etc.)
* Fixed Google Place Autocomplete widget bugs in Django Admin Inlines.
* Point map widget JS objects associated to the map HTML elements with jQuey $.data method.
* Passing Google Place AutoComplete full response object to jQuery triggers.

======
v0.1.9
======

* Google Place Autocomplete object binding to jQuery triggers.
* Implemented Google Geocoding support for the marker coordinates.
* Added custom widget settings feature for each widget.
* Added Portuguese localisation support.
* Fixed Google Place Autocomplete widget bugs in Django Admin Inlines.
* Fixed Python 3.6 errors.
* Fixed Javascript bugs.
* The GitHub repository Integrated with Travis CI.
* Implemented unit tests for backend code. (%100 code coverage)
* Change development environment from Vagrant to Docker.

======
v0.1.8
======

* Full documentation integrated to readthedocs.org.
* Fixed Google Map static widget issues.
* Added Russian localisation support.
* Added `Google Places Autocomplete <https://developers.google.com/maps/documentation/javascript/places-autocomplete>`_ options support.
* Fixed CSS issues.
4 changes: 2 additions & 2 deletions conf/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ Django
psycopg2==2.8.4
selenium==3.3.1
coverage==4.4
Fabric==1.14.0
Fabric<2.0
coveralls==1.3.0
backports.zoneinfo
tzdata
tzdata
23 changes: 8 additions & 15 deletions demo/cities/admin.py
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
from .models import House, Neighbour
from django.contrib.gis.db import models
from mapwidgets.widgets import GooglePointFieldWidget, GooglePointFieldInlineWidget, GoogleStaticMapWidget, \
GoogleStaticOverlayMapWidget
GoogleStaticOverlayMapWidget, MapboxPointFieldWidget


class NeighbourAdminInline(admin.TabularInline):
@@ -14,35 +14,28 @@ class NeighbourAdminInline(admin.TabularInline):
}


class HouseAdminForm(forms.ModelForm):
class Meta:
model = House
fields = "__all__"
widgets = {
'location': GooglePointFieldWidget(settings={"GooglePointFieldWidget": (("zoom", 1),)}),
'location_has_default': GooglePointFieldWidget,
}


class HouseAdminStaticForm(forms.ModelForm):

class Meta:
model = House
fields = "__all__"
widgets = {
'location': GoogleStaticMapWidget,
'location_has_default': GoogleStaticOverlayMapWidget,
'location': GoogleStaticOverlayMapWidget,
'location_has_default': GoogleStaticMapWidget,
}


class HouseAdmin(admin.ModelAdmin):
search_fields = ('name', )
list_display = ("name", "location")
inlines = (NeighbourAdminInline,)
form = HouseAdminStaticForm

def get_form(self, request, obj=None, **kwargs):
form = super(HouseAdmin, self).get_form(request, obj, **kwargs)
form.base_fields['location'].widget = GooglePointFieldWidget()
if obj is None: # manipulate page form
form.base_fields['location'].widget = MapboxPointFieldWidget()
form.base_fields['location_has_default'].widget = GooglePointFieldWidget()
return form

@property
@@ -57,7 +50,7 @@ def _changeform_view(self, request, object_id, form_url, extra_context):
class NeighbourAdmin(admin.ModelAdmin):
autocomplete_fields = ('neighbour_of_house',)
formfield_overrides = {
models.PointField: {"widget": GoogleStaticOverlayMapWidget}
models.PointField: {"widget": MapboxPointFieldWidget}
}


2 changes: 1 addition & 1 deletion demo/cities/forms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms

from cities.models import City
from mapwidgets.widgets import GooglePointFieldWidget, GoogleStaticMapWidget, GoogleStaticOverlayMapWidget
from mapwidgets.widgets import MapboxPointFieldWidget, GoogleStaticMapWidget, GoogleStaticOverlayMapWidget, GooglePointFieldWidget


class CityCreateForm(forms.ModelForm):
2 changes: 1 addition & 1 deletion demo/cities/urls.py
Original file line number Diff line number Diff line change
@@ -7,4 +7,4 @@
path('', CityListView.as_view(), name="list"),
re_path(r'^(?P<pk>\d+)/$', CityDetailView.as_view(), name="detail"),
re_path(r'^create/$', CityCreateView.as_view(), name="create"),
]
]
22 changes: 18 additions & 4 deletions demo/demo/settings.py
Original file line number Diff line number Diff line change
@@ -59,9 +59,12 @@
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

STATIC_URL = 'static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static"),
]
ROOT_URLCONF = 'demo.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
@@ -130,12 +133,15 @@

USE_TZ = True

LOCALE_PATHS = (
"/django-map-widgets/mapwidgets/locale",
)

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/

STATIC_URL = '/static/'
GOOGLE_MAP_API_KEY = os.getenv('GOOGLE_MAP_API_KEY', None)
MAPBOX_API_KEY = os.getenv('MAPBOX_API_KEY', None)
MAP_WIDGETS = {
"GooglePointFieldWidget": (
("zoom", 15),
@@ -144,5 +150,13 @@
("GooglePlaceAutocompleteOptions", {'componentRestrictions': {'country': 'uk'}}),
("streetViewControl", False)
),
"GOOGLE_MAP_API_KEY": GOOGLE_MAP_API_KEY,
"MapboxPointFieldWidget": {
"access_token": MAPBOX_API_KEY,
"mapOptions": {
"zoom": 10,
"center": (51.515618, -0.091998)
}
},
"GOOGLE_MAP_API_KEY": GOOGLE_MAP_API_KEY
}

4 changes: 3 additions & 1 deletion demo/demo/urls.py
Original file line number Diff line number Diff line change
@@ -13,10 +13,12 @@
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.conf import settings
from django.contrib import admin
from django.urls import path, include
from django.conf.urls.static import static

urlpatterns = [
path('admin/', admin.site.urls),
path('cities/', include('cities.urls'))
]
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Loading

0 comments on commit 495d985

Please sign in to comment.