Skip to content

Commit

Permalink
Merge 7028848 into d7f7b8f
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhigal committed May 14, 2020
2 parents d7f7b8f + 7028848 commit b5e8fe1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
6 changes: 6 additions & 0 deletions leaflet/__init__.py
Expand Up @@ -50,6 +50,7 @@
'MIN_ZOOM': None,
'MAX_ZOOM': None,
'DEFAULT_CENTER': None,
'DEFAULT_PRECISION': 6,
'FORCE_IMAGE_PATH': False,
'SRID': None,
'TILES_EXTENT': [],
Expand Down Expand Up @@ -123,6 +124,11 @@
raise ImproperlyConfigured("LEAFLET_CONFIG['DEFAULT_ZOOM'] must be an int between 1 and 24.")


DEFAULT_PRECISION = app_settings['DEFAULT_PRECISION']
if DEFAULT_PRECISION is not None and not (isinstance(DEFAULT_PRECISION, six.integer_types) and (4 <= DEFAULT_PRECISION <= 12)):
raise ImproperlyConfigured("LEAFLET_CONFIG['DEFAULT_PRECISION'] must be an int between 4 and 12.")


PLUGINS = app_settings['PLUGINS']
if not (isinstance(PLUGINS, dict) and all([isinstance(el, dict) for el in PLUGINS.values()])):
error_msg = """LEAFLET_CONFIG['PLUGINS'] must be dict of dicts in the format:
Expand Down
10 changes: 7 additions & 3 deletions leaflet/static/leaflet/leaflet.css
Expand Up @@ -634,7 +634,11 @@
border-right-color: #fff;
}

/* Resize the "display_raw" textbox */
.django-leaflet-raw-textarea {
width: 100%;
/* Circle editing markers */
.leaflet-editing-icon {
margin-left: -5px!important;
margin-top: -5px!important;
width: 10px!important;
height: 10px!important;
border-radius: 10px!important;
}
7 changes: 5 additions & 2 deletions leaflet/static/leaflet/leaflet.forms.js
Expand Up @@ -35,7 +35,7 @@ L.FieldStore = L.Class.extend({
geom.feature = {geometry: {type: this.options.geom_type}};
}

var geojson = geom.toGeoJSON();
var geojson = geom.toGeoJSON(this.options.precision);
var is_geometrycollection = (geojson.geometry && geojson.geometry.type == 'GeometryCollection');
if (is_multi && is_generic && !is_geometrycollection) {
var flat = {type: 'GeometryCollection', geometries: []};
Expand All @@ -62,7 +62,7 @@ L.FieldStore = L.Class.extend({
latlngs.push(latlng);
}
geom = L[collection_type](latlngs);
geojson = geom.toGeoJSON().geometry;
geojson = geom.toGeoJSON(this.options.precision).geometry;
}
// In order to make multipoint work, it seems we need to treat it similarly to the GeometryCollections
else if (this.options.geom_type == 'MULTIPOINT') {
Expand All @@ -82,6 +82,8 @@ L.FieldStore = L.Class.extend({
if (/^\s*$/.test(value)) {
return null;
}
// Helps to get rid of the float value conversion error
document.querySelector('#id_geom').value = JSON.stringify(JSON.parse(value));
return L.GeoJSON.geometryToLayer(JSON.parse(value));
},
});
Expand Down Expand Up @@ -109,6 +111,7 @@ L.GeometryField = L.Class.extend({
'multipolygon': 'polygon',
})[geom_type] || 'featureGroup';


L.setOptions(this, options);

this._drawControl = null;
Expand Down
1 change: 1 addition & 0 deletions leaflet/templates/leaflet/widget.html
Expand Up @@ -17,6 +17,7 @@

function {{ id_map_callback }}(map, options) {
{{ module }}.store_class = {{ field_store_class }};
{{ module }}.precision = options.djoptions.precision;
(new {{ geometry_field_class}}({{ module }})).addTo(map);
{% block callback %}{% endblock callback %}
};
Expand Down
1 change: 1 addition & 0 deletions leaflet/templatetags/leaflet_tags.py
Expand Up @@ -99,6 +99,7 @@ def leaflet_map(name, callback=None, fitextent=True, creatediv=True,
fitextent=fitextent,
center=instance_app_settings['DEFAULT_CENTER'],
zoom=instance_app_settings['DEFAULT_ZOOM'],
precision=instance_app_settings['DEFAULT_PRECISION'],
minzoom=instance_app_settings['MIN_ZOOM'],
maxzoom=instance_app_settings['MAX_ZOOM'],
layers=[(force_text(label), url, attrs) for (label, url, attrs) in instance_app_settings.get('TILES')],
Expand Down

0 comments on commit b5e8fe1

Please sign in to comment.