270 lines
No EOL
9.7 KiB
HTML
270 lines
No EOL
9.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="de">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>CityBikes</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<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">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"
|
|
integrity="sha256-t2/7smZfgrST4FS1DT0bs/KotCM74XlcqZN5Vu7xlrw=" crossorigin="anonymous"/>
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/0.6.0/tables-min.css"
|
|
integrity="sha256-4NzXOZY2l6V9ObAblwSPfn2wI5kyZbUMaMVVbMrZDXA=" crossorigin="anonymous"/>
|
|
<link rel="stylesheet" href="https://cdn.rawgit.com/superRaytin/paginationjs/master/dist/pagination.css"
|
|
integrity="sha384-SyzpxoHHs3cdQUpp7RLURB573W8ag6zDuRI4rs1ABbQijt3iRQg/RTXgX5/nFQiT" 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 src="https://cdn.rawgit.com/superRaytin/paginationjs/master/dist/pagination.min.js"
|
|
integrity="sha384-lGxAij8Xpweqxbi492MA2DByvagtSxqar4o0QzS0eMOq2gvV49F3UgqBhX8q4S1r"
|
|
crossorigin="anonymous"></script>
|
|
<script>
|
|
var map = L.map('map', {zoomSnap: 0.5}).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 basemap = L.tileLayer('http://maps{s}.wien.gv.at/basemap/geolandbasemap/normal/google3857/{z}/{y}/{x}.{format}', {
|
|
maxZoom: 19,
|
|
attribution: 'Datenquelle: <a href="www.basemap.at">basemap.at</a>',
|
|
subdomains: ["", "1", "2", "3", "4"],
|
|
format: 'png',
|
|
bounds: [[46.35877, 8.782379], [49.037872, 17.189532]]
|
|
});
|
|
var emptyLayer = L.tileLayer("", {maxZoom: 19}).addTo(map);
|
|
|
|
var citybikeIconClass = L.Icon.extend({
|
|
options: {
|
|
iconUrl: "citybike.png",
|
|
iconAnchor: [8, 8],
|
|
popupAnchor: [0, -8],
|
|
iconSize: [16, 16]
|
|
}
|
|
});
|
|
var citybikeIcon = new citybikeIconClass;
|
|
var altCitybikeIconClass = citybikeIconClass.extend({
|
|
options: {
|
|
iconUrl: "citybikeAlt.png"
|
|
}
|
|
});
|
|
var altCitybikeIcon = new altCitybikeIconClass;
|
|
|
|
var stations = {};
|
|
|
|
var stationLayer = L.geoJson(null, {
|
|
pointToLayer: function (feature, latlng) {
|
|
return L.marker(latlng, {icon: 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(altCitybikeIcon);
|
|
},
|
|
mouseout: function (e) {
|
|
layer.setIcon(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(altCitybikeIcon);
|
|
stationLayer.getLayer(stations[layer.nodes[1]]["leafletId"]).setIcon(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(citybikeIcon);
|
|
stationLayer.getLayer(stations[layer.nodes[1]]["leafletId"]).setIcon(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);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
|
|
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,
|
|
"basemap.at": basemap,
|
|
"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("/api/connection/", {
|
|
from: fromId,
|
|
to: toId
|
|
}).done(function (data) {
|
|
lines.addData(data);
|
|
var id = data.features[0].properties.id;
|
|
if (map.hasLayer(lines)) {
|
|
lines.getLayer(linesArray[id]["leafletId"]).openPopup();
|
|
}
|
|
var bounds = lines.getLayer(linesArray[id]["leafletId"]).getBounds();
|
|
map.flyToBounds(bounds);
|
|
});
|
|
$(".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>
|
|
<script src="sidebar.js"></script>
|
|
</html> |