Created
March 26, 2020 16:11
-
-
Save karnzx/b55a6a7b5f2fb8c7f8ca2b4d998813a5 to your computer and use it in GitHub Desktop.
Medium Brython map add OpenStreetTileLayer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% extends '/base-map.html' %} | |
{% block body %} | |
<div> | |
<p id="coords"></p> | |
<div id="mapid" style="margin: 1em;"></div> | |
</div> | |
<script type="text/python"> | |
from browser import alert, document, window, html | |
world_map = document["mapid"] | |
center = (7.0166666, 100.4666648) # hatyai coords | |
zoom = 10 | |
# Access the leaflet.js API | |
leaflet = window.L | |
def click(ev): | |
print('click') | |
# Display coordinates | |
ul = html.UL(id="nav") | |
ul <= html.LI(f'latitude: {center[0]}') | |
ul <= html.LI(f'longitude: {center[1]}') | |
document["coords"] <= ul | |
# Create world map | |
mymap = leaflet.map('mapid').setView(center, zoom) | |
leaflet.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { | |
"maxZoom": 19, | |
"attribution": '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' | |
}).addTo(mymap) | |
# Put marker on map | |
leaflet.marker([center[0],center[1]]).addTo(mymap).bindPopup(f'''ใจกลางหาดใหญ่ คือ <b>{center}</b> </br> | |
ไก่ทอดอร่อยมาก แต่ชานมไข่มุกอร่อยกว่า''') | |
</script> | |
{% endblock body %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment