208 lines
No EOL
6.7 KiB
HTML
208 lines
No EOL
6.7 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%;
|
|
}
|
|
|
|
#search {
|
|
pointer-events: auto;
|
|
}
|
|
|
|
#search select {
|
|
margin: 20px;
|
|
}
|
|
|
|
.leaflet-popup-content {
|
|
font-size: medium;
|
|
}
|
|
</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"
|
|
}
|
|
});
|
|
|
|
$.ajax({
|
|
dataType: "json",
|
|
url: "nearest.json",
|
|
success: function (data) {
|
|
lines.addData(data);
|
|
lines.addTo(map);
|
|
}
|
|
});
|
|
var stations = {};
|
|
|
|
var stationLayer = L.geoJson(null, {
|
|
pointToLayer: function (feature, latlng) {
|
|
return L.marker(latlng, {icon: new citybikeIcon()});
|
|
},
|
|
onEachFeature: function (feature, layer) {
|
|
// layer._leaflet_id = feature.properties.ref;
|
|
// console.log(feature.properties.ref);
|
|
// console.log(feature.properties);
|
|
stations[feature.properties.ref] = feature.properties.name;
|
|
layer.bindPopup(feature.properties.name);
|
|
layer._leaflet_id = 10000 + feature.properties.ref;
|
|
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)
|
|
}
|
|
});
|
|
|
|
$.ajax({
|
|
dataType: "json",
|
|
url: "stationLayer.json",
|
|
success: function (data) {
|
|
stationLayer.addData(data);
|
|
stationLayer.addTo(map);
|
|
map.fitBounds(stationLayer.getBounds());
|
|
}
|
|
});
|
|
|
|
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(10000 + layer.nodes[0]).setIcon(new altCitybikeIcon());
|
|
stationLayer.getLayer(10000 + layer.nodes[1]).setIcon(new altCitybikeIcon());
|
|
},
|
|
mouseout: function (e) {
|
|
lines.resetStyle(e.target);
|
|
stationLayer.getLayer(10000 + layer.nodes[0]).setIcon(new citybikeIcon());
|
|
stationLayer.getLayer(10000 + layer.nodes[1]).setIcon(new citybikeIcon());
|
|
}
|
|
});
|
|
}
|
|
|
|
var lines = L.geoJson(null, {
|
|
onEachFeature: function (feature, layer) {
|
|
var popupText = stations[feature.properties.nodes[0]] + " ⟷ " + stations[feature.properties.nodes[1]] + "<br>" +
|
|
feature.properties.wayLength / 1000 + " km";
|
|
layer.bindPopup(popupText);
|
|
|
|
onEachFeature(feature, layer);
|
|
layer.nodes = feature.properties.nodes;
|
|
// layer._leaflet_id = feature.properties.id;
|
|
|
|
},
|
|
style: {
|
|
weight: 5
|
|
}
|
|
});
|
|
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.backgroundColor = 'white';
|
|
container.style.width = '50vw';
|
|
var select1 = L.DomUtil.create("select", 'stationSelect', container);
|
|
var select2 = L.DomUtil.create("select", 'stationSelect', container);
|
|
select1.style.width = "50%";
|
|
select2.style.width = "50%";
|
|
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);
|
|
})
|
|
|
|
|
|
</script>
|
|
</html> |