Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
flask-admin
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Python-Dev
flask-admin
Commits
aaa59800
Commit
aaa59800
authored
May 23, 2018
by
joost
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added custom tilelayers leaflet
parent
745620ad
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
33 additions
and
8 deletions
+33
-8
fields.py
flask_admin/contrib/geoa/fields.py
+6
-2
form.py
flask_admin/contrib/geoa/form.py
+2
-0
typefmt.py
flask_admin/contrib/geoa/typefmt.py
+2
-0
view.py
flask_admin/contrib/geoa/view.py
+2
-0
widgets.py
flask_admin/contrib/geoa/widgets.py
+8
-1
form.js
flask_admin/static/admin/js/form.js
+13
-5
No files found.
flask_admin/contrib/geoa/fields.py
View file @
aaa59800
...
...
@@ -8,10 +8,14 @@ from .widgets import LeafletWidget
class
GeoJSONField
(
JSONField
):
widget
=
LeafletWidget
()
def
__init__
(
self
,
label
=
None
,
validators
=
None
,
geometry_type
=
"GEOMETRY"
,
srid
=
'-1'
,
session
=
None
,
**
kwargs
):
srid
=
'-1'
,
session
=
None
,
tile_layer_url
=
None
,
tile_layer_attribution
=
None
,
**
kwargs
):
self
.
widget
=
LeafletWidget
(
tile_layer_url
=
tile_layer_url
,
tile_layer_attribution
=
tile_layer_attribution
)
super
(
GeoJSONField
,
self
)
.
__init__
(
label
,
validators
,
**
kwargs
)
self
.
web_srid
=
4326
self
.
srid
=
srid
...
...
flask_admin/contrib/geoa/form.py
View file @
aaa59800
...
...
@@ -9,4 +9,6 @@ class AdminModelConverter(SQLAAdminConverter):
field_args
[
'geometry_type'
]
=
column
.
type
.
geometry_type
field_args
[
'srid'
]
=
column
.
type
.
srid
field_args
[
'session'
]
=
self
.
session
field_args
[
'tile_layer_url'
]
=
self
.
view
.
tile_layer_url
field_args
[
'tile_layer_attribution'
]
=
self
.
view
.
tile_layer_attribution
return
GeoJSONField
(
**
field_args
)
flask_admin/contrib/geoa/typefmt.py
View file @
aaa59800
...
...
@@ -14,6 +14,8 @@ def geom_formatter(view, value):
"data-height"
:
70
,
"data-geometry-type"
:
to_shape
(
value
)
.
geom_type
,
"data-zoom"
:
15
,
"data-tile-layer-url"
:
view
.
tile_layer_url
,
"data-tile-layer-attribution"
:
view
.
tile_layer_attribution
})
if
value
.
srid
is
-
1
:
value
.
srid
=
4326
...
...
flask_admin/contrib/geoa/view.py
View file @
aaa59800
...
...
@@ -5,3 +5,5 @@ from flask_admin.contrib.geoa import form, typefmt
class
ModelView
(
SQLAModelView
):
model_form_converter
=
form
.
AdminModelConverter
column_type_formatters
=
typefmt
.
DEFAULT_FORMATTERS
tile_layer_url
=
None
tile_layer_attribution
=
None
flask_admin/contrib/geoa/widgets.py
View file @
aaa59800
...
...
@@ -23,7 +23,8 @@ class LeafletWidget(TextArea):
"""
def
__init__
(
self
,
width
=
'auto'
,
height
=
350
,
center
=
None
,
zoom
=
None
,
min_zoom
=
None
,
max_zoom
=
None
,
max_bounds
=
None
):
zoom
=
None
,
min_zoom
=
None
,
max_zoom
=
None
,
max_bounds
=
None
,
tile_layer_url
=
None
,
tile_layer_attribution
=
None
):
self
.
width
=
width
self
.
height
=
height
self
.
center
=
center
...
...
@@ -31,6 +32,8 @@ class LeafletWidget(TextArea):
self
.
min_zoom
=
min_zoom
self
.
max_zoom
=
max_zoom
self
.
max_bounds
=
max_bounds
self
.
tile_layer_url
=
tile_layer_url
self
.
tile_layer_attribution
=
tile_layer_attribution
def
__call__
(
self
,
field
,
**
kwargs
):
kwargs
.
setdefault
(
'data-role'
,
self
.
data_role
)
...
...
@@ -38,6 +41,10 @@ class LeafletWidget(TextArea):
kwargs
.
setdefault
(
'data-geometry-type'
,
gtype
)
# set optional values from constructor
if
self
.
tile_layer_url
:
kwargs
[
'data-tile-layer-url'
]
=
self
.
tile_layer_url
if
self
.
tile_layer_attribution
:
kwargs
[
'data-tile-layer-attribution'
]
=
self
.
tile_layer_attribution
if
"data-width"
not
in
kwargs
:
kwargs
[
"data-width"
]
=
self
.
width
if
"data-height"
not
in
kwargs
:
...
...
flask_admin/static/admin/js/form.js
View file @
aaa59800
...
...
@@ -157,11 +157,19 @@
}
// set up tiles
var
mapboxVersion
=
window
.
MAPBOX_ACCESS_TOKEN
?
4
:
3
;
L
.
tileLayer
(
'//{s}.tiles.mapbox.com/v'
+
mapboxVersion
+
'/'
+
MAPBOX_MAP_ID
+
'/{z}/{x}/{y}.png?access_token='
+
window
.
MAPBOX_ACCESS_TOKEN
,
{
attribution
:
'Map data © <a href="//openstreetmap.org">OpenStreetMap</a> contributors, <a href="//creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="//mapbox.com">Mapbox</a>'
,
maxZoom
:
18
}).
addTo
(
map
);
if
(
$el
.
data
(
'tile-layer-url'
)){
var
attribution
=
$el
.
data
(
'tile-layer-attribution'
)
||
''
L
.
tileLayer
(
'//'
+
$el
.
data
(
'tile-layer-url'
),
{
attribution
:
attribution
,
maxZoom
:
18
}).
addTo
(
map
)
}
else
{
var
mapboxVersion
=
window
.
MAPBOX_ACCESS_TOKEN
?
4
:
3
;
L
.
tileLayer
(
'//{s}.tiles.mapbox.com/v'
+
mapboxVersion
+
'/'
+
MAPBOX_MAP_ID
+
'/{z}/{x}/{y}.png?access_token='
+
window
.
MAPBOX_ACCESS_TOKEN
,
{
attribution
:
'Map data © <a href="//openstreetmap.org">OpenStreetMap</a> contributors, <a href="//creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="//mapbox.com">Mapbox</a>'
,
maxZoom
:
18
}).
addTo
(
map
);
}
// everything below here is to set up editing, so if we're not editable,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment