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

144 lines
4.1 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>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/leaflet.css"/>
<style>
body {
margin: 0;
}
html, body, #map {
height: 100%;
}
2016-10-01 20:41:29 +02:00
#search {
pointer-events: auto;
}
#search input {
margin:20px;
}
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>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"
integrity="sha256-BbhdlvQf/xTY9gja0Dq3HiwQF8LaCRTXxZKRutelT44=" crossorigin="anonymous"></script>
2016-06-02 15:31:03 +02:00
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.0.0-rc.1/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,
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",
iconAnchor: [16, 16],
popupAnchor: [0, -16]
}
});
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-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) {
var layer = e.target;
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) {
layer.bindPopup(stations[feature.properties.nodes[0]] + " - " + stations[feature.properties.nodes[1]]);
onEachFeature(feature, layer);
layer.nodes = feature.properties.nodes;
// layer._leaflet_id = feature.properties.id;
},
style: {
weight: 5
}
});
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>