Skip to content

Commit

Permalink
polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
xrotwang committed May 23, 2024
1 parent 67c77e9 commit a35a000
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,18 @@ pip install cldfgeojson

The functionality in [`cldfgeojson.create`](src/cldfgeojson/create.py) helps adding speaker area
information when creating CLDF datasets (e.g. with [`cldfbench`](https://github.com/cldf/cldfbench)).



## `leaflet.draw`

This package contains the [`leaflet.draw`](https://github.com/Leaflet/Leaflet.draw) plugin in the form of `data://` URLs in
[a mako template](src/cldfgeojson/commands/templates/leaflet.draw.mako). `leaflet.draw` is
distributed under a MIT license:

> Copyright 2012-2017 Jon West, Jacob Toye, and Leaflet
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
2 changes: 1 addition & 1 deletion src/cldfgeojson/commands/overlay.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def run(args):

html = tmpl.render(
img=data_url(img, 'image/jpeg') if isinstance(img, pathlib.Path) else img,
bounds = bounds['bbox'],
bounds=bounds['bbox'],
geojson=json.dumps(dict({n.stem: load(n) for n in args.geojson})),
with_draw=args.with_draw,
)
Expand Down
32 changes: 16 additions & 16 deletions src/cldfgeojson/commands/templates/index.html.mako
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,20 @@
</div>
</div>
<script>
const draw = ${'true' if with_draw else 'false'};
const map = L.map('map').setView([37.8, -96], 4);
var drawnItems = L.featureGroup().addTo(map);
const geojson = ${geojson};
const layers = {};
var draw = ${'true' if with_draw else 'false'},
map = L.map('map').setView([37.8, -96], 4),
drawnItems = L.featureGroup(),
geojson = ${geojson},
layers = {},
latLngBounds = L.latLngBounds([[${bounds[1]}, ${bounds[0]}], [${bounds[3]}, ${bounds[2]}]]);
const latLngBounds = L.latLngBounds([[${bounds[1]}, ${bounds[0]}], [${bounds[3]}, ${bounds[2]}]]);
var osmUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
osmAttrib = '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors',
osm = L.tileLayer(osmUrl, {maxZoom: 20, attribution: osmAttrib});
osm.addTo(map);
drawnItems.addTo(map)
L.tileLayer(
'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',
{
maxZoom: 20,
attribution: '&copy; <a href="http://openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
if (draw) {
map.addControl(new L.Control.Draw({
edit: {featureGroup: drawnItems, poly: {allowIntersection: false}},
Expand All @@ -83,8 +85,7 @@
input.addEventListener("input", (event) => {imageOverlay.setOpacity(event.target.value / 100)});
if (draw) {
map.on(L.Draw.Event.CREATED, function (event) {
var layer = event.layer;
drawnItems.addLayer(layer);
drawnItems.addLayer(event.layer);
});
document.getElementById('delete').onclick = function (e) {
drawnItems.clearLayers();
Expand All @@ -94,9 +95,8 @@
}
}
for (const name in geojson) {
var layer = L.geoJSON(geojson[name]);
layers[name] = layer;
layer.addTo(map)
layers[name] = L.geoJSON(geojson[name]);
layers[name].addTo(map)
}
L.control.layers({}, layers).addTo(map);
L.rectangle(latLngBounds).addTo(map);
Expand Down

0 comments on commit a35a000

Please sign in to comment.