Skip to content

Commit 49f9225

Browse files
committed
Add button for copy to clipboard bounding box
1 parent 5e072db commit 49f9225

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

assets/css/app.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@ html, body, #map {
3232
top: 3px;
3333
box-shadow: none;
3434
color: #333;
35+
}
36+
37+
#bbox-copy
38+
{
39+
font-size: 4px;
40+
color: white;
3541
}

assets/js/app.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ basemap.addTo(map);
2121
var coordinatesdiv = new L.Control();
2222
coordinatesdiv.onAdd = function (map) {
2323
this._div = L.DomUtil.create('div', 'coordinates-info');
24-
this._div.innerHTML = 'Center Coordinates<hr><div id="coordinates">-2.61119,118.65234</div><button id="copy" onclick="CopyToClipboard()">Copy Coordinates</button><br><br><div id="zoom">Zoom: 5</div><hr>Bounding Box<hr><div id="bbox">Move the map</div>';
24+
this._div.innerHTML = 'Center Coordinates<hr><div id="coordinates">-2.61119,118.65234</div><button id="copy" onclick="CopyToClipboard()">Copy Coordinates</button><br><br><div id="zoom">Zoom: 5</div><hr>Bounding Box<hr><div id="bbox">Move the map</div><div id="bbox-copy"></div><button id="copy" onclick="CopyToClipboardBbox()">Copy Bounding Box</button>';
2525
return this._div;
2626
};
2727
coordinatesdiv.addTo(map);
@@ -44,6 +44,7 @@ function mapMovement (e) {
4444
document.getElementById("coordinates").innerHTML = mapcenter.lat.toFixed(precisionLatLng) + "," + mapcenter.lng.toFixed(precisionLatLng);
4545
document.getElementById("zoom").innerHTML = "Zoom: " + map.getZoom();
4646
document.getElementById("bbox").innerHTML = "Left &nbsp;: " + map.getBounds().getWest().toFixed(precisionBbox) + "<br>Bottom: " + map.getBounds().getSouth().toFixed(precisionBbox) + "<br>Right : " + map.getBounds().getEast().toFixed(precisionBbox) + "<br>Top &nbsp;&nbsp;: " + map.getBounds().getNorth().toFixed(precisionBbox);
47+
document.getElementById("bbox-copy").innerHTML = map.getBounds().getWest().toFixed(precisionBbox) + "," + map.getBounds().getSouth().toFixed(precisionBbox) + "," + map.getBounds().getEast().toFixed(precisionBbox) + "," + map.getBounds().getNorth().toFixed(precisionBbox);
4748

4849
marker.remove();
4950

@@ -66,4 +67,21 @@ function CopyToClipboard() {
6667
timer: 1000,
6768
backdrop: false,
6869
})
70+
}
71+
72+
function CopyToClipboardBbox() {
73+
var text = document.getElementById("bbox-copy");
74+
var r = document.createRange();
75+
r.selectNode(text);
76+
window.getSelection().removeAllRanges();
77+
window.getSelection().addRange(r);
78+
document.execCommand('copy');
79+
window.getSelection().removeAllRanges();
80+
Swal.fire({
81+
icon: 'success',
82+
text: 'Bounding box copied to clipboard',
83+
showConfirmButton: false,
84+
timer: 1000,
85+
backdrop: false,
86+
})
6987
}

0 commit comments

Comments
 (0)