-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
146 lines (129 loc) · 5.65 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title>OSM: Overpass + Leaflet</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/css/bootstrap.min.css" integrity="sha384-y3tfxAZXuh4HwSYylfB+J125MxIs6mR5FOHamPBG064zB+AFeWH94NdvaCBm8qnd" crossorigin="anonymous">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.3/dist/leaflet.css"
integrity="sha512-Rksm5RenBEKSKFjgI3a41vrjkw4EVPlJ3+OiI65vTjIdo9brlAacEuKOiQ5OFh7cOI1bkDwLqdLw3Zg0cRJAAQ=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.3.3/dist/leaflet.js"
integrity="sha512-tAGcCfR4Sc5ZP5ZoVz0quoZDYX5aCtEm/eu1KhSLj2c9eFrylXZknQYmxUssFaVJKvvc0dJQixhGjG2yXWiV9Q=="
crossorigin=""></script>
<style media="screen">
#mapid { height: 400px; }
</style>
</head>
<body>
<div class="container">
<h1>OSM: Overpass + Leaflet</h1>
<div id="mapid"></div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.2/js/bootstrap.min.js" integrity="sha384-vZ2WRJMwsjRMW/8U7i6PWi6AlO1L79snBrmgiDpgIWJ82z8eA5lenwvxbMV1PAh7" crossorigin="anonymous"></script>
<script src="assets/js/osmtogeojson.js" charset="utf-8"></script>
<script type="text/javascript">
var mymap;
var geoLayer;
var icon_unmarked = 'https://github.com/yopaseopor/accessibilitat/raw/master/icons/crossing_unmarked.png';
var icon_obstacle_wheelchair = 'https://github.com/yopaseopor/accessibilitat/raw/master/icons/obstacle_wheelchair_yes.png';
var icon_shop_no_wheelchair = 'https://github.com/yopaseopor/accessibilitat/raw/master/icons/wheelchair_no_shop.png';
var icon_shop_yes_wheelchair = 'https://github.com/yopaseopor/accessibilitat/raw/master/icons/wheelchair_yes_shop.png';
var icon_shop_limited_wheelchair = 'https://github.com/yopaseopor/accessibilitat/raw/master/icons/wheelchair_limited_shop.png';
var setupMap = function () {
mymap = L.map('mapid').setView([41.4441608, 2.2234922], 13);
var osmUrl='https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors';
var osm = new L.TileLayer(osmUrl, {minZoom: 8, maxZoom: 18, attribution: osmAttrib});
mymap.addLayer(osm);
geoLayer = L.geoJson().addTo(mymap);
};
var getData = function () {
var query = `
[out:json][timeout:35];
// fetch area “Badalona” to search in
area(3600347954)->.searchArea;
// gather results
(
// query part for: “crossing=unmarked”
node["crossing"="unmarked"](area.searchArea);
// query part for: “"obstacle:wheelchair"=yes”
node["obstacle:wheelchair"="yes"](area.searchArea);
// query part for: “wheelchair=no and highway=footway”
way["wheelchair"="no"]["highway"="footway"](area.searchArea);
// query part for: “wheelchair=no and shop=*”
node["wheelchair"="no"]["shop"](area.searchArea);
// query part for: “wheelchair=yes and shop=*”
node["wheelchair"="yes"]["shop"](area.searchArea);
// query part for: “wheelchair=limited and shop=*”
node["wheelchair"="limited"]["shop"](area.searchArea);
);
(._;>;);out;
`;
//query = "data=[out:json];way[building=residential](41.878660,12.562383,41.883125,12.571663);(._;>;);out;";
$.ajax({
data: query,
type: 'post',
dataType: 'json',
url: 'http://overpass-api.de/api/interpreter',
success: function(json) {
mymap.removeLayer(geoLayer);
var geojson = osmtogeojson(json);
geoLayer = L.geoJson(geojson, {
filter: function (feature, layer) {
return feature.properties.type === "node";
},
pointToLayer: function(feature, latlng) {
//console.log(feature);
var icon = null;
if (feature.properties.tags.shop) {
if (feature.properties.tags.wheelchair == "yes") {
icon = L.icon({
iconSize: [27, 27],
iconAnchor: [13, 27],
popupAnchor: [1, -24],
iconUrl: icon_shop_yes_wheelchair
});
} else if (feature.properties.tags.wheelchair == "no") {
icon = L.icon({
iconSize: [27, 27],
iconAnchor: [13, 27],
popupAnchor: [1, -24],
iconUrl: icon_shop_no_wheelchair
});
} else if (feature.properties.tags.wheelchair == "limited") {
icon = L.icon({
iconSize: [27, 27],
iconAnchor: [13, 27],
popupAnchor: [1, -24],
iconUrl: icon_shop_limited_wheelchair
});
}
}
if (icon) {
return L.marker(latlng, {icon: icon});
}
},
onEachFeature: function (feature, layer) {
if (feature.properties.tags.name) {
layer.bindPopup(feature.properties.tags.name);
}
}
}).addTo(mymap);
mymap.fitBounds( geoLayer.getBounds() );
//geoList.reload( geoLayer );
},
error: function (xhr, status, data) {
console.log(xhr, status, data);
}
});
};
$(document).ready(function () {
setupMap();
getData();
});
</script>
</body>
</html>