Basic code, still needs some layout changes
This commit is contained in:
parent
2314ec0e3b
commit
1f3c480967
4 changed files with 55 additions and 10 deletions
|
@ -1,4 +1,9 @@
|
||||||
#mapid {
|
.large-map {
|
||||||
min-height: 400px;
|
min-height: 400px;
|
||||||
height: 600px;
|
height: 600px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.small-map {
|
||||||
|
min-height: 150px;
|
||||||
|
height: 250px;
|
||||||
|
}
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
var map = L.map('mapid').setView([
|
var map = L.map('mapid');
|
||||||
51.0231119, 3.7102741
|
|
||||||
], 14);
|
|
||||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||||
}).addTo(map);
|
}).addTo(map);
|
||||||
|
|
||||||
|
|
||||||
|
let base_request_uri = "https://photon.komoot.de/api/?limit=1&q=";
|
||||||
|
|
||||||
function performRequest(url, location, success_callback) {
|
function performRequest(url, location, success_callback) {
|
||||||
var request = new XMLHttpRequest();
|
var request = new XMLHttpRequest();
|
||||||
request.open('GET', url, true);
|
request.open('GET', url, true);
|
||||||
|
@ -52,6 +52,10 @@ let callback = function OSMCallBack(location, data) {
|
||||||
marker.on('mouseout', function(env) {
|
marker.on('mouseout', function(env) {
|
||||||
marker.closePopup();
|
marker.closePopup();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (location.center) {
|
||||||
|
map.setView([lat, lon], 14);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log(`Location ${JSON.stringify(location, null, 2)} returned no features, are you sure this is a valid address?`);
|
console.log(`Location ${JSON.stringify(location, null, 2)} returned no features, are you sure this is a valid address?`);
|
||||||
}
|
}
|
||||||
|
@ -59,7 +63,7 @@ let callback = function OSMCallBack(location, data) {
|
||||||
|
|
||||||
function loadmap(locations) {
|
function loadmap(locations) {
|
||||||
for (let loc of locations) {
|
for (let loc of locations) {
|
||||||
let request_uri = "https://photon.komoot.de/api/?limit=1&q=" + loc.address;
|
let request_uri = base_request_uri + loc.address;
|
||||||
performRequest(request_uri, loc, callback);
|
performRequest(request_uri, loc, callback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,19 @@
|
||||||
|
|
||||||
{% block container %}
|
{% block container %}
|
||||||
<div class="row" xmlns="http://www.w3.org/1999/html">
|
<div class="row" xmlns="http://www.w3.org/1999/html">
|
||||||
<div class="col-md-push-1 col-md-10 darker">
|
<div class="col-md-push-1 col-md-5 darker">
|
||||||
<h3>Location: {{ location.name }}</h3>
|
<h3>{{ location.name }}</h3>
|
||||||
<span class="glyphicon glyphicon-home"></span>: {{ location.address }} <br/>
|
<span class="glyphicon glyphicon-home"></span>: {{ location.address }} <br/>
|
||||||
<span class="glyphicon glyphicon-phone"></span>: {{ location.telephone }} <br/>
|
<span class="glyphicon glyphicon-phone"></span>: {{ location.telephone }} <br/>
|
||||||
<span class="glyphicon glyphicon-link"></span>: <a href="{{ location.website}}">{{ location.website }}</a>
|
<span class="glyphicon glyphicon-link"></span>: <a href="{{ location.website}}">{{ location.website }}</a>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-md-push-1 col-md-5 darker">
|
||||||
|
{% if location.address %}
|
||||||
|
<div class="small-map" id="mapid"></div>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
<div class="col-md-push-1 col-md-10 darker">
|
<div class="col-md-push-1 col-md-10 darker">
|
||||||
<h3 id="order-title">Products</h3>
|
<h3 id="order-title">Products</h3>
|
||||||
<table class="table table-hover table-condensed">
|
<table class="table table-hover table-condensed">
|
||||||
|
@ -29,3 +36,30 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block styles %}
|
||||||
|
{{ super() }}
|
||||||
|
<link rel="stylesheet" href="{{ url_for('static', filename='css/leaflet.css') }}">
|
||||||
|
<link rel="stylesheet" href="{{url_for('static', filename='css/map.css')}}">
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block scripts %}
|
||||||
|
{{super()}}
|
||||||
|
|
||||||
|
{% if location.address %}
|
||||||
|
<script src="{{ url_for('static', filename='js/leaflet.js')}}"></script>
|
||||||
|
<script src="{{ url_for('static', filename='js/map.js' ) }}"></script>
|
||||||
|
<script>
|
||||||
|
let locations = [];
|
||||||
|
|
||||||
|
loc = {
|
||||||
|
"address": "{{location.address}}",
|
||||||
|
"name": "{{location.name}}",
|
||||||
|
"center": true,
|
||||||
|
};
|
||||||
|
locations.push(loc);
|
||||||
|
|
||||||
|
loadmap(locations);
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
{% import "utils.html" as util %}
|
{% import "utils.html" as util %}
|
||||||
|
|
||||||
{% block container %}
|
{% block container %}
|
||||||
<div id="mapid"></div>
|
<div id="mapid" class="large-map"></div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block styles %}
|
{% block styles %}
|
||||||
|
@ -35,6 +35,8 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
|
|
||||||
|
map.setView([51.0231119, 3.7102741], 14);
|
||||||
|
|
||||||
loadmap(locations);
|
loadmap(locations);
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in a new issue