erdem / django-map-widgets Goto Github PK
View Code? Open in Web Editor NEWHighly customizable, intuitive, and user-friendly map widgets for GeoDjango applications.
License: MIT License
Highly customizable, intuitive, and user-friendly map widgets for GeoDjango applications.
License: MIT License
Guys, sorry to trouble you but I've followed the instructions in the docs and when my browser renders the page the debugger says 'ReferenceError: DjangoGooglePointFieldWidget is not defined'
in the following line: new DjangoGooglePointFieldWidget(mapWidgetOptions);
.
My template already has jQuery and Bootstrap setted, and inside Django settings the app 'mapwidgets',
is placed, I don't know if this is an issue? The following image shows how the page is displayed:
The Map is not working. Please add a way to add API_KEY in setttings
I followed the installation instructions and got the following error.
I'm on Python 3.5 and Django 1.11.4
Any clue what could be going on or how to fix this?
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10793a950>
Traceback (most recent call last):
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
autoreload.raise_last_exception()
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
six.reraise(*_exception)
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
fn(*args, **kwargs)
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
File "/usr/local/Cellar/python3/3.5.2_1/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/mapwidgets/__init__.py", line 4, in <module>
from .widgets import GooglePointFieldWidget, GooglePointFieldInlineWidget, \
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/mapwidgets/widgets.py", line 4, in <module>
from django.contrib.gis.forms import BaseGeometryWidget
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
from .fields import ( # NOQA
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/contrib/gis/forms/fields.py", line 4, in <module>
from django.contrib.gis.geos import GEOSException, GEOSGeometry
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/contrib/gis/geos/__init__.py", line 5, in <module>
from .collections import ( # NOQA
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/contrib/gis/geos/collections.py", line 11, in <module>
from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/contrib/gis/geos/geometry.py", line 11, in <module>
from django.contrib.gis import gdal
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/contrib/gis/gdal/datasource.py", line 39, in <module>
from django.contrib.gis.gdal.driver import Driver
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
File "/Users/santiago/Programming/comedydir/myvenv/lib/python3.5/site-packages/django/contrib/gis/gdal/libgdal.py", line 45, in <module>
% '", "'.join(lib_names)
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.1.0", "gdal2.0.0", "gdal1.11.0", "gdal1.10.0", "gdal1.9.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.
Google Maps API error: MissingKeyMapError https://developers.google.com/maps/documentation/javascript/error-messages#missing-key-map-error
Hi, when I drag the markup on the map it returns undefined the place parameter. But this does not happen when I write in the search field. The place parameter contains address information.
Do you know what could be happening?
Hello, I run your example from git. In admin on add/edit place page I can see only 3 text fields instead of map widget. What I am doing wrong? Thanks for any help.
David
I spent all day trying to run some of google map widget on admin. No result :-(
Mac OS, django.VERSION
(1, 11, 0, u'final', 1)
Safari
In the admin view of the GooglePointFieldWidget the Map and Satellite buttons are not visible when fieldsets are set with the collapse class. For example:
fieldsets = [
...
('Provenience', {
'fields': [
('easting', 'northing'),
('geom',)],
'classes': ['collapse'],
})
]
They reappear when collapse is removed. I'm using django 1.11 with python 3.6.2. Not sure if it happens with the other widgets as well.
There is an exception:
File "...mapwidgets/mapwidgets/widgets.py", line 45, in render
if value and isinstance(value, basestring):
NameError: name 'basestring' is not defined
basestring
does not work for Python3
My settings are configured with language-code pt-BR, but the texts of the map don't translate.
Hi. This is my settings. But its dosent work. When i comment the map still works.
MAP_WIDGETS = {
"GooglePointFieldWidget": (
("zoom", 15),
("size", "320x320"),
),
"GOOGLE_MAP_API_KEY": "KEY",
}`
And one more question. How i can make map responsible ?
Maybe this is out of the scope for this project, anyway could be useful to use the widgets without geodjango, for example Google Map Point Field Widget could be used inside admin to let the users pick a position. Actually the position is stored inside models.PointField it could be store for example as json inside a textfield using a model field provided by this library.
I was searching for a widget to pick position from map, this seems one of the most curated but I don't want to add a spatial database to my app only to pick lat/long from map.
Please close if out of scope, thanks!
The included CSS styles override the bootstrap theming and causes problems for existing applications.
If i create a pull request that renames the django-map-widgets css styles will it be accepted?
Proposed css class prefix: mw-
For example
rename .btn-default to .mw-btn-default
Hi :)
In my Sign up form I want my mapwidget to attempt to center as near as possible to the user.
I use GeoIP.
The code inside my RegisterView looks something like this:
def get_client_ip(request):
x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR')
if x_forwarded_for:
ip = x_forwarded_for.split(',')[0]
else:
ip = request.META.get('REMOTE_ADDR')
return ip
from django.contrib.gis.geoip import GeoIP
def RegisterView(request):
center_here = False
initial = {'language': to_locale(get_language())}
ip = get_client_ip(request)
if ip:
g = GeoIP()
c = g.city(ip)
if c:
if c['country_code']:
initial['country'] = c['country_code']
if c['latitude'] and c['longitude']:
center_here = Point(c['longitude'], c['latitude'])
form = RegisterForm(request.POST or None, request.FILES or None, initial=initial)
if request.method == 'POST':
if form.is_valid():
.............saving stuff............
else:
messages.error(request, _("Please correct the error below."))
if not form.cleaned_data['location']:
center_here = False
return render(request, 'registration/register.html', {
'form': form,
'center_here': center_here,
})
so now i need to find a way to implement center_here in my html template form and how to trigger mapwidget to center the map there.
anyone have an idea how to trigger map to be centered on center_here point
thanks :)
By the way if anybody want to copy my method above, remember to download the data files from:
https://dev.maxmind.com/geoip/legacy/geolite/
and add GEOIP_PATH to your settings file
read more about GeoIP here: https://docs.djangoproject.com/en/1.11/ref/contrib/gis/geoip/
or GeoIP2 read here: https://docs.djangoproject.com/en/2.0/ref/contrib/gis/geoip2/
I am a web developer who is doing a personal project and this project is in the development phase, which is why I am still working in a local environment (localhost). I have a GoogleMaps API Key created, but for its use it is necessary to create credentials to the URLs that are going to make use of the API key. The problem comes when a localhost address is not addressable from the Key API.
That is why I am writing to you to ask you how I can do to be able to use your widget in a local environment. Is there any way?
Thank you very much for providing such a useful widget to facilitate the use of the Google Maps API. A cordial greeting.
My Settings:
MAP_WIDGETS = { "GooglePointFieldWidget": ( ("zoom", 1), ("markerFitZoom", 12) ), "GOOGLE_MAP_API_KEY": GOOGLE_MAPS_API_KEY }
No matter what I set the zoom to (tried 1 thru 15), I am always completely zoomed in. Also tried changing the markerFitZoom but it does not make a difference.
Hi, I'm using django-jet as Django admin theme and when I use django-map-widgets all my other icons dissapear because a collision in CSS selectors.
It would be nice that the CSS selectors in django-map-widgets only affect the map widget itself.
This can be easily solved by adding .mw-wrap
to the selector in map_widgets.css
:
.mw-wrap [class^="icon-"]:before, .mw-wrap [class*=" icon-"]:before {
font-family: "fontello";
font-style: normal;
font-weight: normal;
...
When I wish to check - https://coveralls.io/builds/13894261/source?filename=%2Fhome%2Ftravis%2Fbuild%2Ferdem%2Fdjango-map-widgets%2Fmapwidgets%2Fwidgets.py
I get the following error -
Hi, I'm using this widget on a django 2.0 website.
The map is working with geolocation and when I click or move a marker the input field is updated with correct address.
But if I try to use the autocomplete field it raises some errors:
On focus change: Uncaught TypeError: b.get is not a function
On click: Uncaught TypeError: Cannot read property 'location' of undefined
Any thoughts?
Getting this error for all widgets.
TypeError: render () got an unexpected keyword argument 'renderer'
Django 2.1 release says, Feature removed in 2.1:
"Support for Widget.render ( ) methods without the renderer argument is removed. "
Adding renderer=None to all widget methods in widgets.py solves this problem.
Hi. I am not exactly sure how can I use the functions of DjangoGooglePointFieldWidget
.
For example, I want to use removeMarker()
.
This is my JS code:
var map = $('.mw-map').data('map');
console.log(map);
map.removeMarker();
output:
Hg {gm_bindings_: {…}, __gm: Gf, gm_accessors_: {…}, center: _.E, scrollwheel: false, …}
stkpro.js:16 Uncaught TypeError: map.removeMarker is not a function
at HTMLDocument.<anonymous> (stkpro.js:16)
at fire (jquery.js:3187)
at Object.fireWith [as resolveWith] (jquery.js:3317)
at Function.ready (jquery.js:3536)
at HTMLDocument.completed (jquery.js:3552)
screenshot:
Hi and thank you all for this great package :)
I am trying to make my signup form more user friendly and i would like user first to write his address etc, and then (i hope) that this widget can find address automaticlly for most users.
This is what I have done so far.. some jquery that insert the address in the widget autocomplete address field. But it doesnt work the magic. I need the last little bit, please help me :)
<script type="text/javascript">
$( document ).ready(function() {
$(document).on("click", "#id_street, #id_zipcode, #id_city, #id_country", function(event){
if ($("#id_street").val() && $("#id_zipcode").val() && $("#id_city").val() && $("#id_country").val()){
$("#location-mw-google-address-input").val($("#id_street").val() + ", " + $("#id_zipcode").val() + " " + $("#id_city").val() + ", " + $("#id_country option:selected").text())
}
});
});
</script>
The widget always expect a point in mercator projection. It should transform the point respecting the django field srid.
Hello,
I have the following settings
MAP_WIDGETS = { "GooglePointFieldWidget": ( ("zoom", 0), ), "GOOGLE_MAP_API_KEY": 'MY-GOOGLE-MAPS-API-KEY' }
however, The zoom parameter is not working. I have change it from 15, to 0 and other values and it keeps rendering the map with the same zoom. Do you know how to make it work?
I have printed the values that the widget gets, and they are correct. The problem seems to be when the js is rendered, apparently it is not getting the zoom value correctly.
Thank you
Please consider implementing a widgets.PolygonFieldInlineWidgetMixin
The latest version on Pypi (0.2.0) is out of sync with the latest release here (0.2.1)
Hello,
Is there a way to display the map as terrain only? Or atleast terrain by default?
Thank you,
Natalie
I updated to django 2.1 and get some error
I think is because the rendered param: https://docs.djangoproject.com/es/2.1/releases/2.1/#features-removed-in-2-1
I want use django-map-widgets in inline style.
class TransportAdminForm(forms.ModelForm):
class Meta:
fields = (
"coordinate",
"destination",
'type_transport',
'date_loading',
'valid',
'is_published'
)
widgets = {
'coordinate': GooglePointFieldInlineWidget,
}
class TransportAdminStackedInline(admin.StackedInline):
model = Transport
form = TransportAdminForm
extra = 0
# formfield_overrides = {
# models.PointField: {"widget": GooglePointFieldInlineWidget}
# }
@admin.register(Carrier)
class CarrierAdmin(admin.ModelAdmin):
form = CarrierAdminForm
list_display = ('company_name', 'is_published')
list_display_links = ('company_name',)
list_editable = ('is_published', )
inlines = [TransportAdminStackedInline]
but it does not works, I get empty map without scrolls, point and opportunity write and change coordinates. It seems like this:
Hi, Love map-widget. Nice and easy to implement and looks good.
I would like to capture what was entered in the Address Field in a field in my MySQL database. Any help with that? Cheers, Mykl
Might be an issue with how I am loading static files. This is the ouput from the JavaScript console when trying to render GooglePointFieldWidget
:
jquery_class.js:72 Uncaught ReferenceError: jQuery is not defined at jquery_class.js:72 django_mw_base.js:202 Uncaught ReferenceError: jQuery is not defined at django_mw_base.js:202 mw_google_point_field.js:102 Uncaught ReferenceError: jQuery is not defined at mw_google_point_field.js:102 127.0.0.1/:308 Uncaught ReferenceError: DjangoGooglePointFieldWidget is not defined at 127.0.0.1/:308 at 127.0.0.1/:312
Hi,
The javascript triggers should be able to get the full response from geocoding an address (if that process is happening). The google geocoder often includes extra information such as country: this can be valuable for other values in the form.
Currently a place object is given, which seems to be a shorthand or partial response. (in 0.1.9 the lat value is given in the place parameter, the place object is not sent at all).
Would such a feature add value to the widget?
Regards,
Elger
Does this only work for Google Maps ($$$)? If so could you remove the references to OpenStreetMap? Otherwise, provide an example using that. Thanks.,
The Map does not initialize correctly in the Admin if it's inside a hidden fieldset.
Great widget by the way!
Hi.
I am referring to line:
(also in other templates).
It would be nice to have point field widget instance in a variable like:
var widget = new DjangoGooglePointFieldWidget(mapWidgetOptions);
so we can use it in our custom templates within {% block extra_javascript %}{% endblock %}
block.
I have implemented form like this
widgets = {
'point': GooglePointFieldWidget,
'address': forms.HiddenInput
}
But i have to hide info window, how i can do this can any one help me please.
Hi! I came across this package for the promise to use it with Openstreetmaps, but it hasn't support for this now. Are you planning you planning to implement this soon?
Greetings!
Hi!
I trying to install package with virtualenv on ubuntu 14.04.5 LTS. I have python 3.5.2.
After
pip install django-map-widgets
i have this traceback:
Collecting django-map-widgets
Downloading django-map-widgets-0.1.7.tar.gz (143kB)
100% |################################| 143kB 31.9MB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-4zpnyqzn/django-map-widgets/setup.py", line 10, in <module>
long_description = open(readme_rst).read()
File "/home/ubuntu/www/punkapp/venv/lib/python3.5/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 424: ordinal not in range(128)
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-4zpnyqzn/django-map-widgets/
But center of the map center is still in Denver. The same with custom style.
settings.py
MAP_WIDGETS = {
"GooglePointFieldWidget": (
("zoom", 15),
("mapCenterLocation", [57.7177013, -16.6300491]),
),
"GOOGLE_MAP_API_KEY": "KeyHere",
}
The Map Widget Inline does not render while adding a new inline to the form.
I am using django-map-widgets
in my Django Admin for storing series of coordinates/positions more easily. The first mandatory point appears automatically while loading the form and its map is loading fine. However, when I click the "Add" button for getting more inlines maps, the form loads but the map is not rendered.
I have noticed that django-map-widgets
loads a template (google-point-field-inline-widget.html
) dynamically and that template only contains a <script type="application/javascript"> ... </script>
, so it looks like it is not running the script when the template loads with the "Add" button.
I find it weird since in the docs, the inlines apparently work just fine (as shown in the example), so I do not know what is wrong.
I am using the latest version of both Django (v2.1.2) and django-map-widgets (v0.20.0). I am using Django Suit, but it does not look like it is the problem, since I tried removing it and had the same behavior.
I have created a workaround by adding an extra js file to the admin class, that contains the javascript in the template, but with hardcoded settings, since it is not possible to load them dynamically. But I understand that this is not the expected behavior and would need a better solution.
Hello Erdem;
how can I show the map in the template? if you have template tags, how can you share?by the way if you know turkish; çok iyi bir iş çıkarmışsın :)
The static map widget is rendering with message "the image map is not found"
I don't know what form field to use for the city.
Where am I going wrong?
class JobForm(forms.ModelForm):
title = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'title'}))
location = forms.CharField(widget=GooglePointFieldWidget)
category = forms.ModelChoiceField(queryset=Category.objects.all(), empty_label=None, widget=forms.Select())
class Meta:
model = Job
fields = ('title','city', 'location', 'category')
widgets = {
'city': GoogleStaticMapWidget
}
A few suggestions for the mapwidget future versions.
a way to dynamically localize the map. maybe by setting a language variable 'mapwidget_language' in the view (https://developers.google.com/maps/documentation/javascript/localization). or maybe add a javascript example to the documentation, how to change map language.
a way to dynamically (or automaitacally) center the map (if no point is selected) by guessing the user location from IP address or something smarter. or by setting a 'mapwidget_center' variable in the view. or maybe add a javascript example to the documentation, how to center the map.
I hope you understand my suggestion :)
Thank You
$(document).on("google_point_map_widget:marker_create", function (e, lat, lng, locationInputElem, mapWrapID) { console.log(locationInputElem); // django widget textarea widget (hidden) console.log(lat, lng); // created marker coordinates console.log(mapWrapID); // map widget wrapper element ID });
I tried the above code following the docs , I am unable to trigger the event. Please do help?
Hello!
I'm using this library on one of my projects and I'd like to enable scrollWheel
on the generated maps. I have tried to do it dynamically after map is created, but I haven't found any way to access to the map object saved at DjangoGooglePointFieldWidget.map
, as it is created inside anonymous closures. Is it possible to add some method to be able to change map options, either at creation time or dynamically? For better pluggable system, I suppose a dynamic way to get map object should be the better option. This way, one could add layers, markers, bubbles and whatever GMap offers.
Thanks a lot in advance!!
The GooglePointFieldWidget doesn't seem to be working for me. The API key has been entered and the missing API key warning in the console is gone but there appears to be an error in the JS that is stopping the map from loading. This is using Django 1.11 LTS.
Uncaught TypeError: Cannot read property '0' of null
at Class.initializeMap (mw_google_point_field.js:32)
at Class.init (django_mw_base.js:16)
at new Class (jquery_class.js:33)
at [redacted]/:317
at [redacted]/:321
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.