250 lines
No EOL
8.1 KiB
HTML
250 lines
No EOL
8.1 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>CityBikes</title>
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css"/>
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/select2/4.0.3/css/select2.min.css"
|
|
integrity="sha256-xJOZHfpxLR/uhh1BwYFS5fhmOAdIRQaiOul5F/b7v3s=" crossorigin="anonymous">
|
|
<style>
|
|
body {
|
|
margin: 0;
|
|
}
|
|
|
|
html, body, #map {
|
|
height: 100%;
|
|
}
|
|
|
|
.leaflet-control-custom {
|
|
pointer-events: auto;
|
|
}
|
|
|
|
#search select {
|
|
margin: 20px;
|
|
}
|
|
|
|
.leaflet-popup-content {
|
|
font-size: medium;
|
|
}
|
|
|
|
.clearButton {
|
|
width: 10%;
|
|
background-color: white;
|
|
display: inline-block;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
|
|
</head>
|
|
<body>
|
|
<div id="map">
|
|
</div>
|
|
<!--
|
|
<div class="leaflet-bottom" id="search">
|
|
<select class="stationSelect" multiple="multiple" style="width: 150%;">
|
|
<option value="1234">Testort</option>
|
|
<option value="1235">Noch eine Station</option>
|
|
</select>
|
|
</div>
|
|
-->
|
|
</body>
|
|
<script src="https://code.jquery.com/jquery-3.1.1.min.js"
|
|
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
|
|
<script src="https://unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script>
|
|
<script src="https://cdn.jsdelivr.net/select2/4.0.3/js/select2.min.js"
|
|
integrity="sha256-+mWd/G69S4qtgPowSELIeVAv7+FuL871WXaolgXnrwQ=" crossorigin="anonymous"></script>
|
|
<script src="https://cdn.jsdelivr.net/select2/4.0.3/js/i18n/de.js"
|
|
integrity="sha256-mtjCIpmIYVw5CLf7IpjBWp6VtFzdKh/YtZFtpIeIStc=" crossorigin="anonymous"></script>
|
|
|
|
<script>
|
|
var map = L.map('map').setView([48.51579416571888, 15.6255304813385], 16);
|
|
var layer = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
maxZoom: 19,
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
|
});
|
|
var emptyLayer = L.tileLayer("").addTo(map);
|
|
|
|
var citybikeIcon = L.Icon.extend({
|
|
options: {
|
|
iconUrl: "citybike.png",
|
|
iconAnchor: [8, 8],
|
|
popupAnchor: [0, -8],
|
|
iconSize: [16, 16]
|
|
}
|
|
});
|
|
var altCitybikeIcon = citybikeIcon.extend({
|
|
options: {
|
|
iconUrl: "citybikeAlt.png"
|
|
}
|
|
});
|
|
|
|
var stations = {};
|
|
|
|
var stationLayer = L.geoJson(null, {
|
|
pointToLayer: function (feature, latlng) {
|
|
return L.marker(latlng, {icon: new citybikeIcon()});
|
|
},
|
|
onEachFeature: function (feature, layer) {
|
|
stations[feature.properties.ref] = {name: feature.properties.name, leafletId: L.stamp(layer)};
|
|
layer.bindPopup(feature.properties.name);
|
|
layer.on({ //Icons beim hover verdunkeln
|
|
mouseover: function (e) {
|
|
layer.setIcon(new altCitybikeIcon());
|
|
},
|
|
mouseout: function (e) {
|
|
layer.setIcon(new citybikeIcon());
|
|
}
|
|
});
|
|
var option = new Option(feature.properties.name, feature.properties.ref);
|
|
$("select").append(option)
|
|
}
|
|
});
|
|
|
|
function onEachFeature(feature, layer) {
|
|
layer.on({
|
|
mouseover: function (e) {
|
|
layer.setStyle({
|
|
weight: 10,
|
|
color: '#666'
|
|
});
|
|
|
|
if (!L.Browser.ie && !L.Browser.opera) {
|
|
layer.bringToFront();
|
|
}
|
|
stationLayer.getLayer(stations[layer.nodes[0]]["leafletId"]).setIcon(new altCitybikeIcon());
|
|
stationLayer.getLayer(stations[layer.nodes[1]]["leafletId"]).setIcon(new altCitybikeIcon());
|
|
},
|
|
mouseout: function (e) {
|
|
lines.resetStyle(e.target);
|
|
if (!feature.properties.nearest) {
|
|
layer.setStyle({
|
|
weight: 10,
|
|
color: '#E82C0C'
|
|
});
|
|
}
|
|
stationLayer.getLayer(stations[layer.nodes[0]]["leafletId"]).setIcon(new citybikeIcon());
|
|
stationLayer.getLayer(stations[layer.nodes[1]]["leafletId"]).setIcon(new citybikeIcon());
|
|
}
|
|
});
|
|
}
|
|
var linesArray = {};
|
|
var lines = L.geoJson(null, {
|
|
onEachFeature: function (feature, layer) {
|
|
var popupText = stations[feature.properties.nodes[0]]["name"] +
|
|
" ⟷ " + stations[feature.properties.nodes[1]]["name"]
|
|
+ "<br>" +
|
|
feature.properties.wayLength / 1000 + " km";
|
|
layer.bindPopup(popupText);
|
|
linesArray[feature.properties.id] = {leafletId: L.stamp(layer)};
|
|
|
|
if (!feature.properties.nearest) {
|
|
layer.setStyle({
|
|
weight: 10,
|
|
color: '#E82C0C'
|
|
});
|
|
}
|
|
|
|
onEachFeature(feature, layer);
|
|
layer.nodes = feature.properties.nodes;
|
|
|
|
},
|
|
style: {
|
|
weight: 5
|
|
}
|
|
});
|
|
|
|
$.ajax({
|
|
dataType: "json",
|
|
url: "stationLayer.json",
|
|
success: function (data) {
|
|
stationLayer.addData(data);
|
|
stationLayer.addTo(map);
|
|
map.fitBounds(stationLayer.getBounds());
|
|
$.ajax({
|
|
dataType: "json",
|
|
url: "nearest.json",
|
|
success: function (data) {
|
|
lines.addData(data);
|
|
lines.addTo(map);
|
|
console.log(linesArray);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
lines.getAttribution = function () {
|
|
return "Routing mit <a href='http://www.routino.org/'>Routino</a>";
|
|
};
|
|
stationLayer.getAttribution = function () {
|
|
return "Icon Open Data Wien (<a href='http://creativecommons.org/licenses/by/3.0/at/deed.de'>CC BY 3.0 AT</a>)";
|
|
};
|
|
|
|
var mapLayers = {
|
|
'Standard': layer,
|
|
"Leer": emptyLayer
|
|
};
|
|
var overlays = {
|
|
"Wege": lines,
|
|
"Stationen": stationLayer
|
|
};
|
|
var control = L.control.layers(mapLayers, overlays, {collapsed: false}).addTo(map);
|
|
|
|
|
|
var customControl = L.Control.extend({
|
|
options: {
|
|
position: 'bottomleft'
|
|
},
|
|
onAdd: function (map) {
|
|
var container = L.DomUtil.create('div', 'leaflet-bar leaflet-control leaflet-control-custom');
|
|
|
|
container.style.width = '50vw';
|
|
var select1 = L.DomUtil.create("select", 'stationSelect', container);
|
|
var select2 = L.DomUtil.create("select", 'stationSelect', container);
|
|
var clearButton = L.DomUtil.create("div", 'clearButton', container);
|
|
select1.style.width = "45%";
|
|
select2.style.width = "45%";
|
|
clearButton.style.width = "10%";
|
|
clearButton.textContent = "Clear";
|
|
|
|
select1.appendChild(new Option);
|
|
select2.appendChild(new Option);
|
|
return container;
|
|
}
|
|
});
|
|
map.addControl(new customControl);
|
|
var stationSelect = $(".stationSelect");
|
|
stationSelect.select2({
|
|
placeholder: "Stationen auswählen",
|
|
allowClear: true
|
|
});
|
|
stationSelect.on("select2:select", function (event) {
|
|
var fromId = stationSelect.first().val();
|
|
var toId = stationSelect.last().val();
|
|
if (!fromId || !toId) {
|
|
return false;
|
|
}
|
|
console.info(fromId + "->" + toId);
|
|
$.getJSON("http://127.0.0.1:5000/api/connection/", {
|
|
from: fromId,
|
|
to: toId
|
|
}).done(function (data) {
|
|
|
|
lines.addData(data);
|
|
|
|
});
|
|
$(".clearButton").on("click", function () {
|
|
var allLines = lines.getLayers();
|
|
for (i = 1; i < allLines.length; i++) {
|
|
var currentLine = allLines[i];
|
|
if (!currentLine.feature.properties.nearest) {
|
|
lines.removeLayer(currentLine);
|
|
}
|
|
}
|
|
}
|
|
)
|
|
})
|
|
|
|
|
|
</script>
|
|
</html> |