Archived
1
0
Fork 0
This repository has been archived on 2024-06-28. You can view files and clone it, but cannot push or open issues or pull requests.
citybike/www/map.html

159 lines
4.8 KiB
HTML
Raw Normal View History

2016-06-02 15:14:51 +02:00
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>CityBikes</title>
2016-10-02 11:50:24 +02:00
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.1/dist/leaflet.css"/>
2016-06-02 15:14:51 +02:00
<style>
body {
margin: 0;
}
html, body, #map {
height: 100%;
}
2016-10-01 20:41:29 +02:00
#search {
pointer-events: auto;
}
2016-10-02 11:50:24 +02:00
2016-10-01 20:41:29 +02:00
#search input {
2016-10-02 11:50:24 +02:00
margin: 20px;
}
.leaflet-popup-content {
font-size: medium;
2016-10-01 20:41:29 +02:00
}
2016-06-02 15:14:51 +02:00
</style>
</head>
<body>
2016-10-01 20:41:29 +02:00
<div id="map">
</div>
<div class="leaflet-bottom" id="search">
<input type="text" placeholder="Search" autocomplete="off">
<input type="text" placeholder="Search" autocomplete="off">
</div>
2016-06-02 15:14:51 +02:00
</body>
2016-10-02 11:50:24 +02:00
<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>
2016-06-02 15:14:51 +02:00
<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,
2016-10-02 11:50:24 +02:00
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
2016-06-07 15:22:03 +02:00
});
var emptyLayer = L.tileLayer("").addTo(map);
2016-06-02 15:14:51 +02:00
2016-06-07 15:22:03 +02:00
var citybikeIcon = L.Icon.extend({
2016-06-02 15:14:51 +02:00
options: {
iconUrl: "citybike.png",
2016-10-02 11:50:24 +02:00
iconAnchor: [8, 8],
popupAnchor: [0, -8],
iconSize: [16, 16]
2016-06-02 15:14:51 +02:00
}
});
2016-06-07 15:22:03 +02:00
var altCitybikeIcon = citybikeIcon.extend({
options: {
iconUrl: "citybikeAlt.png"
2016-06-02 15:14:51 +02:00
}
});
2016-06-07 15:22:03 +02:00
2016-06-02 15:14:51 +02:00
$.ajax({
dataType: "json",
2016-10-01 20:41:29 +02:00
url: "nearest.json",
2016-06-02 15:14:51 +02:00
success: function (data) {
lines.addData(data);
lines.addTo(map);
}
});
2016-06-07 15:22:03 +02:00
var stations = {};
2016-06-02 15:14:51 +02:00
2016-06-07 15:22:03 +02:00
var stationLayer = L.geoJson(null, {
2016-06-02 15:14:51 +02:00
pointToLayer: function (feature, latlng) {
2016-06-07 15:22:03 +02:00
return L.marker(latlng, {icon: new citybikeIcon()});
2016-06-02 15:14:51 +02:00
},
onEachFeature: function (feature, layer) {
// layer._leaflet_id = feature.properties.ref;
// console.log(feature.properties.ref);
2016-06-07 15:22:03 +02:00
// console.log(feature.properties);
stations[feature.properties.ref] = feature.properties.name;
2016-06-02 15:14:51 +02:00
layer.bindPopup(feature.properties.name);
2016-06-07 15:22:03 +02:00
layer._leaflet_id = 10000 + feature.properties.ref;
2016-10-02 11:50:24 +02:00
layer.on({ //Icons beim hover verdunkeln
mouseover: function (e) {
layer.setIcon(new altCitybikeIcon());
},
mouseout: function (e) {
layer.setIcon(new citybikeIcon());
}
})
2016-06-02 15:14:51 +02:00
}
});
$.ajax({
dataType: "json",
2016-10-01 20:41:29 +02:00
url: "stationLayer.json",
2016-06-02 15:14:51 +02:00
success: function (data) {
2016-06-07 15:22:03 +02:00
stationLayer.addData(data);
stationLayer.addTo(map);
map.fitBounds(stationLayer.getBounds());
2016-06-02 15:14:51 +02:00
}
});
2016-06-07 15:22:03 +02:00
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) {
2016-10-02 11:50:24 +02:00
var popupText = stations[feature.properties.nodes[0]] + " &xharr; " + stations[feature.properties.nodes[1]] + "<br>" +
feature.properties.wayLength / 1000 + " km";
layer.bindPopup(popupText);
2016-06-07 15:22:03 +02:00
onEachFeature(feature, layer);
layer.nodes = feature.properties.nodes;
// layer._leaflet_id = feature.properties.id;
},
style: {
weight: 5
}
});
2016-10-02 11:50:24 +02:00
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>)";
};
2016-06-07 15:22:03 +02:00
var mapLayers = {
'Standard': layer,
"Leer": emptyLayer
};
2016-06-02 15:14:51 +02:00
var overlays = {
"Wege": lines,
2016-06-07 15:22:03 +02:00
"Stationen": stationLayer
2016-06-02 15:14:51 +02:00
};
var control = L.control.layers(mapLayers, overlays, {collapsed: false}).addTo(map);
</script>
</html>