datasette-leaflet 0.2.2__tar.gz → 0.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- datasette_leaflet-0.3/.github/workflows/publish.yml +58 -0
- datasette_leaflet-0.3/.github/workflows/test.yml +35 -0
- datasette_leaflet-0.3/.gitignore +11 -0
- datasette_leaflet-0.3/LICENSE +201 -0
- datasette_leaflet-0.3/PKG-INFO +157 -0
- {datasette-leaflet-0.2.2 → datasette_leaflet-0.3}/README.md +47 -1
- datasette_leaflet-0.3/datasette_leaflet/__init__.py +51 -0
- datasette_leaflet-0.3/datasette_leaflet/static/Leaflet-LICENSE +26 -0
- datasette-leaflet-0.2.2/datasette_leaflet/static/leaflet-v1.7.1.css → datasette_leaflet-0.3/datasette_leaflet/static/leaflet-v1.9.4.css +661 -640
- datasette_leaflet-0.3/datasette_leaflet/static/leaflet-v1.9.4.js +14436 -0
- datasette_leaflet-0.3/datasette_leaflet/static/leaflet-v1.9.4.min.js +19 -0
- datasette_leaflet-0.3/pyproject.toml +32 -0
- datasette_leaflet-0.3/tests/conftest.py +54 -0
- datasette_leaflet-0.3/tests/test_leaflet.py +90 -0
- datasette_leaflet-0.3/tests/test_playwright.py +157 -0
- datasette_leaflet-0.3/update_leaflet.py +166 -0
- datasette-leaflet-0.2.2/PKG-INFO +0 -109
- datasette-leaflet-0.2.2/datasette_leaflet/__init__.py +0 -32
- datasette-leaflet-0.2.2/datasette_leaflet/static/leaflet-v1.7.1.js +0 -7851
- datasette-leaflet-0.2.2/datasette_leaflet/static/leaflet-v1.7.1.min.js +0 -4
- datasette-leaflet-0.2.2/datasette_leaflet.egg-info/PKG-INFO +0 -109
- datasette-leaflet-0.2.2/datasette_leaflet.egg-info/SOURCES.txt +0 -17
- datasette-leaflet-0.2.2/datasette_leaflet.egg-info/dependency_links.txt +0 -1
- datasette-leaflet-0.2.2/datasette_leaflet.egg-info/entry_points.txt +0 -3
- datasette-leaflet-0.2.2/datasette_leaflet.egg-info/requires.txt +0 -5
- datasette-leaflet-0.2.2/datasette_leaflet.egg-info/top_level.txt +0 -1
- datasette-leaflet-0.2.2/setup.cfg +0 -4
- datasette-leaflet-0.2.2/setup.py +0 -42
- {datasette-leaflet-0.2.2 → datasette_leaflet-0.3}/datasette_leaflet/static/images/layers-2x.png +0 -0
- {datasette-leaflet-0.2.2 → datasette_leaflet-0.3}/datasette_leaflet/static/images/layers.png +0 -0
- {datasette-leaflet-0.2.2 → datasette_leaflet-0.3}/datasette_leaflet/static/images/marker-icon-2x.png +0 -0
- {datasette-leaflet-0.2.2 → datasette_leaflet-0.3}/datasette_leaflet/static/images/marker-icon.png +0 -0
- {datasette-leaflet-0.2.2 → datasette_leaflet-0.3}/datasette_leaflet/static/images/marker-shadow.png +0 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
name: Publish Python Package
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
release:
|
|
5
|
+
types: [created]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
test:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
|
|
13
|
+
steps:
|
|
14
|
+
- uses: actions/checkout@v7
|
|
15
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
16
|
+
uses: actions/setup-python@v7
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- uses: actions/cache@v6
|
|
20
|
+
name: Configure pip caching
|
|
21
|
+
with:
|
|
22
|
+
path: ~/.cache/pip
|
|
23
|
+
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
|
|
24
|
+
restore-keys: |
|
|
25
|
+
${{ runner.os }}-pip-
|
|
26
|
+
- name: Install dependencies
|
|
27
|
+
run: |
|
|
28
|
+
pip install . --group dev
|
|
29
|
+
- name: Run tests
|
|
30
|
+
run: |
|
|
31
|
+
pytest
|
|
32
|
+
deploy:
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
needs: [test]
|
|
35
|
+
environment: release
|
|
36
|
+
permissions:
|
|
37
|
+
id-token: write
|
|
38
|
+
steps:
|
|
39
|
+
- uses: actions/checkout@v7
|
|
40
|
+
- name: Set up Python
|
|
41
|
+
uses: actions/setup-python@v7
|
|
42
|
+
with:
|
|
43
|
+
python-version: '3.15'
|
|
44
|
+
- uses: actions/cache@v6
|
|
45
|
+
name: Configure pip caching
|
|
46
|
+
with:
|
|
47
|
+
path: ~/.cache/pip
|
|
48
|
+
key: ${{ runner.os }}-publish-pip-${{ hashFiles('**/pyproject.toml') }}
|
|
49
|
+
restore-keys: |
|
|
50
|
+
${{ runner.os }}-publish-pip-
|
|
51
|
+
- name: Install dependencies
|
|
52
|
+
run: |
|
|
53
|
+
pip install build
|
|
54
|
+
- name: Build
|
|
55
|
+
run: |
|
|
56
|
+
python -m build
|
|
57
|
+
- name: Publish
|
|
58
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
name: Test
|
|
2
|
+
|
|
3
|
+
on: [push]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
test:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
strategy:
|
|
9
|
+
matrix:
|
|
10
|
+
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
|
|
11
|
+
steps:
|
|
12
|
+
- uses: actions/checkout@v7
|
|
13
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
14
|
+
uses: actions/setup-python@v7
|
|
15
|
+
with:
|
|
16
|
+
python-version: ${{ matrix.python-version }}
|
|
17
|
+
- uses: actions/cache@v6
|
|
18
|
+
name: Configure pip caching
|
|
19
|
+
with:
|
|
20
|
+
path: ~/.cache/pip
|
|
21
|
+
key: ${{ runner.os }}-pip-${{ hashFiles('**/pyproject.toml') }}
|
|
22
|
+
restore-keys: |
|
|
23
|
+
${{ runner.os }}-pip-
|
|
24
|
+
- name: Cache Playwright browsers
|
|
25
|
+
uses: actions/cache@v6
|
|
26
|
+
with:
|
|
27
|
+
path: ~/.cache/ms-playwright/
|
|
28
|
+
key: ${{ runner.os }}-browsers
|
|
29
|
+
- name: Install dependencies
|
|
30
|
+
run: |
|
|
31
|
+
pip install -e '.[playwright]' --group dev
|
|
32
|
+
playwright install chromium
|
|
33
|
+
- name: Run tests
|
|
34
|
+
run: |
|
|
35
|
+
pytest
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2024 Simon Willison
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: datasette-leaflet
|
|
3
|
+
Version: 0.3
|
|
4
|
+
Summary: A plugin that bundles Leaflet.js for Datasette
|
|
5
|
+
Project-URL: Homepage, https://github.com/simonw/datasette-leaflet
|
|
6
|
+
Project-URL: Issues, https://github.com/simonw/datasette-leaflet/issues
|
|
7
|
+
Project-URL: CI, https://github.com/simonw/datasette-leaflet/actions
|
|
8
|
+
Project-URL: Changelog, https://github.com/simonw/datasette-leaflet/releases
|
|
9
|
+
Author: Simon Willison
|
|
10
|
+
License-Expression: Apache-2.0
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Requires-Dist: datasette
|
|
14
|
+
Provides-Extra: playwright
|
|
15
|
+
Requires-Dist: pytest-playwright; extra == 'playwright'
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# datasette-leaflet
|
|
19
|
+
|
|
20
|
+
[](https://pypi.org/project/datasette-leaflet/)
|
|
21
|
+
[](https://github.com/simonw/datasette-leaflet/releases)
|
|
22
|
+
[](https://github.com/simonw/datasette-leaflet/actions?query=workflow%3ATest)
|
|
23
|
+
[](https://github.com/simonw/datasette-leaflet/blob/main/LICENSE)
|
|
24
|
+
|
|
25
|
+
Datasette plugin adding the [Leaflet](https://leafletjs.com/) JavaScript library.
|
|
26
|
+
|
|
27
|
+
A growing number of Datasette plugins depend on the Leaflet JavaScript mapping library. They each have their own way of loading Leaflet, which could result in loading it multiple times (with multiple versions) if more than one plugin is installed.
|
|
28
|
+
|
|
29
|
+
This library is intended to solve this problem, by providing a single plugin they can all depend on that loads Leaflet in a reusable way.
|
|
30
|
+
|
|
31
|
+
Plugins that use this:
|
|
32
|
+
|
|
33
|
+
- [datasette-leaflet-freedraw](https://datasette.io/plugins/datasette-leaflet-freedraw)
|
|
34
|
+
- [datasette-leaflet-geojson](https://datasette.io/plugins/datasette-leaflet-geojson)
|
|
35
|
+
- [datasette-cluster-map](https://datasette.io/plugins/datasette-cluster-map)
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
You can install this plugin like so:
|
|
40
|
+
|
|
41
|
+
datasette install datasette-leaflet
|
|
42
|
+
|
|
43
|
+
Usually this plugin will be a dependency of other plugins, so it should be installed automatically when you install them.
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
The plugin makes `leaflet.js` and `leaflet.css` available as static files. It provides two custom template variables with the URLs of those two files.
|
|
48
|
+
|
|
49
|
+
- `{{ datasette_leaflet_url }}` is the URL to the JavaScript
|
|
50
|
+
- `{{ datasette_leaflet_css_url }}` is the URL to the CSS
|
|
51
|
+
|
|
52
|
+
These URLs are also made available as global JavaScript constants:
|
|
53
|
+
|
|
54
|
+
- `datasette.leaflet.JAVASCRIPT_URL`
|
|
55
|
+
- `datasette.leaflet.CSS_URL`
|
|
56
|
+
|
|
57
|
+
The JavaScript is packaged as a [JavaScript module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). You can dynamically import the JavaScript from a custom template like this:
|
|
58
|
+
|
|
59
|
+
```html+jinja
|
|
60
|
+
<script type="module">
|
|
61
|
+
import('{{ datasette_leaflet_url }}')
|
|
62
|
+
.then((leaflet) => {
|
|
63
|
+
/* Use leaflet here */
|
|
64
|
+
});
|
|
65
|
+
</script>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Importing the module also sets a global `window.L` object with the same contents. Leaflet plugins that expect that global, such as [Leaflet.markercluster](https://github.com/Leaflet/Leaflet.markercluster), can be loaded once the import has completed. Anything a plugin adds to `L` is available on that global, not on the imported `leaflet` module.
|
|
69
|
+
|
|
70
|
+
The bundled copy of Leaflet differs from the official release in one other way: tile layers send a `Referer` header by default. See [Tile layers and the Referer header](#tile-layers-and-the-referer-header).
|
|
71
|
+
|
|
72
|
+
You can load the CSS like this:
|
|
73
|
+
|
|
74
|
+
```html+jinja
|
|
75
|
+
<link rel="stylesheet" href="{{ datasette_leaflet_css_url }}">
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Or dynamically like this:
|
|
79
|
+
|
|
80
|
+
```html+jinja
|
|
81
|
+
<script>
|
|
82
|
+
let link = document.createElement('link');
|
|
83
|
+
link.rel = 'stylesheet';
|
|
84
|
+
link.href = '{{ datasette_leaflet_css_url }}';
|
|
85
|
+
document.head.appendChild(link);
|
|
86
|
+
</script>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Here's a full example that loads the JavaScript and CSS and renders a map:
|
|
90
|
+
|
|
91
|
+
```html+jinja
|
|
92
|
+
<script type="module">
|
|
93
|
+
window.DATASETTE_CLUSTER_MAP_TILE_LAYER = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
|
|
94
|
+
window.DATASETTE_CLUSTER_MAP_TILE_LAYER_OPTIONS = {"maxZoom": 19, "detectRetina": true, "attribution": "© <a href=\"https://www.openstreetmap.org/copyright\">OpenStreetMap</a> contributors"};
|
|
95
|
+
let link = document.createElement('link');
|
|
96
|
+
link.rel = 'stylesheet';
|
|
97
|
+
link.href = '{{ datasette_leaflet_css_url }}';
|
|
98
|
+
document.head.appendChild(link);
|
|
99
|
+
import('{{ datasette_leaflet_url }}')
|
|
100
|
+
.then((leaflet) => {
|
|
101
|
+
let div = document.createElement('div');
|
|
102
|
+
div.style.height = '400px';
|
|
103
|
+
document.querySelector('.content').appendChild(div);
|
|
104
|
+
let tiles = leaflet.tileLayer(
|
|
105
|
+
window.DATASETTE_CLUSTER_MAP_TILE_LAYER,
|
|
106
|
+
window.DATASETTE_CLUSTER_MAP_TILE_LAYER_OPTIONS
|
|
107
|
+
);
|
|
108
|
+
let map = leaflet.map(div, {
|
|
109
|
+
center: leaflet.latLng(0, 0),
|
|
110
|
+
zoom: 2,
|
|
111
|
+
layers: [tiles]
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
</script>
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Tile layers and the Referer header
|
|
118
|
+
|
|
119
|
+
Datasette serves many of its pages, including table pages, with a `Referrer-Policy: no-referrer` header, so by default a browser will not send a `Referer` header when it loads map tiles for those pages. Some tile servers block requests like that. The OpenStreetMap tile server at `tile.openstreetmap.org` is one of them: its [usage policy](https://operations.osmfoundation.org/policies/tiles/) requires a valid `Referer`, and it returns "Access blocked" tiles without one.
|
|
120
|
+
|
|
121
|
+
To avoid this, the copy of Leaflet bundled with this plugin changes the default for the [referrerPolicy](https://leafletjs.com/reference.html#tilelayer-referrerpolicy) tile layer option from `false` to `"strict-origin-when-cross-origin"`. Tile requests then include a `Referer` header containing just the origin of your Datasette instance, such as `https://example.com/`. The path and query string of the page showing the map are never sent.
|
|
122
|
+
|
|
123
|
+
This applies to every `L.tileLayer()` and `L.tileLayer.wms()` created using the bundled Leaflet, including those created by other plugins.
|
|
124
|
+
|
|
125
|
+
### Changing the policy for a Datasette instance
|
|
126
|
+
|
|
127
|
+
Use the `tile_referrer_policy` plugin setting. Set it to `false` to go back to sending no `Referer` header for tiles:
|
|
128
|
+
|
|
129
|
+
```yaml
|
|
130
|
+
plugins:
|
|
131
|
+
datasette-leaflet:
|
|
132
|
+
tile_referrer_policy: false
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Or set it to any other [referrer policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy#directives), such as `origin`:
|
|
136
|
+
|
|
137
|
+
```yaml
|
|
138
|
+
plugins:
|
|
139
|
+
datasette-leaflet:
|
|
140
|
+
tile_referrer_policy: origin
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
This goes in `datasette.yaml` for Datasette 1.0, or in `metadata.yaml` for earlier versions.
|
|
144
|
+
|
|
145
|
+
The value in use is available to JavaScript as `datasette.leaflet.TILE_REFERRER_POLICY`. Leaflet reads it once, when the JavaScript is first loaded.
|
|
146
|
+
|
|
147
|
+
### Changing the policy for a single tile layer
|
|
148
|
+
|
|
149
|
+
Pass the `referrerPolicy` option when you create the layer. This takes precedence over the plugin setting:
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
let tiles = leaflet.tileLayer("https://tiles.example.com/{z}/{x}/{y}.png", {
|
|
153
|
+
referrerPolicy: false
|
|
154
|
+
});
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
To change the default for every layer created after that point, use `leaflet.TileLayer.mergeOptions({referrerPolicy: false})`.
|
|
@@ -37,7 +37,7 @@ These URLs are also made available as global JavaScript constants:
|
|
|
37
37
|
- `datasette.leaflet.JAVASCRIPT_URL`
|
|
38
38
|
- `datasette.leaflet.CSS_URL`
|
|
39
39
|
|
|
40
|
-
The JavaScript is
|
|
40
|
+
The JavaScript is packaged as a [JavaScript module](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules). You can dynamically import the JavaScript from a custom template like this:
|
|
41
41
|
|
|
42
42
|
```html+jinja
|
|
43
43
|
<script type="module">
|
|
@@ -48,6 +48,10 @@ import('{{ datasette_leaflet_url }}')
|
|
|
48
48
|
</script>
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
+
Importing the module also sets a global `window.L` object with the same contents. Leaflet plugins that expect that global, such as [Leaflet.markercluster](https://github.com/Leaflet/Leaflet.markercluster), can be loaded once the import has completed. Anything a plugin adds to `L` is available on that global, not on the imported `leaflet` module.
|
|
52
|
+
|
|
53
|
+
The bundled copy of Leaflet differs from the official release in one other way: tile layers send a `Referer` header by default. See [Tile layers and the Referer header](#tile-layers-and-the-referer-header).
|
|
54
|
+
|
|
51
55
|
You can load the CSS like this:
|
|
52
56
|
|
|
53
57
|
```html+jinja
|
|
@@ -92,3 +96,45 @@ import('{{ datasette_leaflet_url }}')
|
|
|
92
96
|
});
|
|
93
97
|
</script>
|
|
94
98
|
```
|
|
99
|
+
|
|
100
|
+
## Tile layers and the Referer header
|
|
101
|
+
|
|
102
|
+
Datasette serves many of its pages, including table pages, with a `Referrer-Policy: no-referrer` header, so by default a browser will not send a `Referer` header when it loads map tiles for those pages. Some tile servers block requests like that. The OpenStreetMap tile server at `tile.openstreetmap.org` is one of them: its [usage policy](https://operations.osmfoundation.org/policies/tiles/) requires a valid `Referer`, and it returns "Access blocked" tiles without one.
|
|
103
|
+
|
|
104
|
+
To avoid this, the copy of Leaflet bundled with this plugin changes the default for the [referrerPolicy](https://leafletjs.com/reference.html#tilelayer-referrerpolicy) tile layer option from `false` to `"strict-origin-when-cross-origin"`. Tile requests then include a `Referer` header containing just the origin of your Datasette instance, such as `https://example.com/`. The path and query string of the page showing the map are never sent.
|
|
105
|
+
|
|
106
|
+
This applies to every `L.tileLayer()` and `L.tileLayer.wms()` created using the bundled Leaflet, including those created by other plugins.
|
|
107
|
+
|
|
108
|
+
### Changing the policy for a Datasette instance
|
|
109
|
+
|
|
110
|
+
Use the `tile_referrer_policy` plugin setting. Set it to `false` to go back to sending no `Referer` header for tiles:
|
|
111
|
+
|
|
112
|
+
```yaml
|
|
113
|
+
plugins:
|
|
114
|
+
datasette-leaflet:
|
|
115
|
+
tile_referrer_policy: false
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Or set it to any other [referrer policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy#directives), such as `origin`:
|
|
119
|
+
|
|
120
|
+
```yaml
|
|
121
|
+
plugins:
|
|
122
|
+
datasette-leaflet:
|
|
123
|
+
tile_referrer_policy: origin
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
This goes in `datasette.yaml` for Datasette 1.0, or in `metadata.yaml` for earlier versions.
|
|
127
|
+
|
|
128
|
+
The value in use is available to JavaScript as `datasette.leaflet.TILE_REFERRER_POLICY`. Leaflet reads it once, when the JavaScript is first loaded.
|
|
129
|
+
|
|
130
|
+
### Changing the policy for a single tile layer
|
|
131
|
+
|
|
132
|
+
Pass the `referrerPolicy` option when you create the layer. This takes precedence over the plugin setting:
|
|
133
|
+
|
|
134
|
+
```javascript
|
|
135
|
+
let tiles = leaflet.tileLayer("https://tiles.example.com/{z}/{x}/{y}.png", {
|
|
136
|
+
referrerPolicy: false
|
|
137
|
+
});
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
To change the default for every layer created after that point, use `leaflet.TileLayer.mergeOptions({referrerPolicy: false})`.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from datasette import hookimpl
|
|
2
|
+
import json
|
|
3
|
+
import textwrap
|
|
4
|
+
|
|
5
|
+
JS_FILE = "leaflet-v1.9.4.js"
|
|
6
|
+
CSS_FILE = "leaflet-v1.9.4.css"
|
|
7
|
+
|
|
8
|
+
# Datasette serves pages with "Referrer-Policy: no-referrer", but tile servers
|
|
9
|
+
# such as tile.openstreetmap.org block requests that have no Referer header.
|
|
10
|
+
# The bundled Leaflet uses this as the default referrerPolicy for tile layers,
|
|
11
|
+
# which sends the origin of the site to the tile server but never the full URL.
|
|
12
|
+
DEFAULT_TILE_REFERRER_POLICY = "strict-origin-when-cross-origin"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def tile_referrer_policy(datasette):
|
|
16
|
+
"The tile_referrer_policy plugin setting: a policy string, or False for none"
|
|
17
|
+
config = datasette.plugin_config("datasette-leaflet") or {}
|
|
18
|
+
policy = config.get("tile_referrer_policy")
|
|
19
|
+
if policy is None:
|
|
20
|
+
return DEFAULT_TILE_REFERRER_POLICY
|
|
21
|
+
return policy
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@hookimpl
|
|
25
|
+
def extra_template_vars(datasette):
|
|
26
|
+
return {
|
|
27
|
+
name: datasette.urls.static_plugins("datasette-leaflet", file)
|
|
28
|
+
for name, file in {
|
|
29
|
+
"datasette_leaflet_url": JS_FILE,
|
|
30
|
+
"datasette_leaflet_css_url": CSS_FILE,
|
|
31
|
+
}.items()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@hookimpl
|
|
36
|
+
def extra_body_script(datasette):
|
|
37
|
+
return textwrap.dedent(
|
|
38
|
+
"""
|
|
39
|
+
window.datasette = window.datasette || {{}};
|
|
40
|
+
datasette.leaflet = {{
|
|
41
|
+
JAVASCRIPT_URL: '{}',
|
|
42
|
+
CSS_URL: '{}',
|
|
43
|
+
TILE_REFERRER_POLICY: {}
|
|
44
|
+
}};
|
|
45
|
+
""".format(
|
|
46
|
+
datasette.urls.static_plugins("datasette-leaflet", JS_FILE),
|
|
47
|
+
datasette.urls.static_plugins("datasette-leaflet", CSS_FILE),
|
|
48
|
+
# < is escaped so the value cannot close the <script> element
|
|
49
|
+
json.dumps(tile_referrer_policy(datasette)).replace("<", "\\u003c"),
|
|
50
|
+
)
|
|
51
|
+
)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
BSD 2-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2010-2023, Volodymyr Agafonkin
|
|
4
|
+
Copyright (c) 2010-2011, CloudMade
|
|
5
|
+
All rights reserved.
|
|
6
|
+
|
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
|
8
|
+
modification, are permitted provided that the following conditions are met:
|
|
9
|
+
|
|
10
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
11
|
+
list of conditions and the following disclaimer.
|
|
12
|
+
|
|
13
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
+
this list of conditions and the following disclaimer in the documentation
|
|
15
|
+
and/or other materials provided with the distribution.
|
|
16
|
+
|
|
17
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
18
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
19
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
20
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
21
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
22
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
23
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
24
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
25
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
26
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|