-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
280 lines (254 loc) · 11.9 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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<title>Hackathon - Random turku tour</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-0.5/leaflet.js"></script>
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" href="css/leaflet.awesome-markers.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-44233275-1', 'koopee.github.io');
ga('send', 'pageview');
</script>
<script src="js/leaflet.awesome-markers.js"></script>
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.5/leaflet.ie.css" />
<![endif]-->
<style type="text/css">
body {
padding: 0;
margin: 0;
}
html, body, #map {
height: 100%;
}
#newTourOnArea {
display: block;
position: absolute;
bottom: 15px;
left: 15px;
z-index: 2000;
}
</style>
</head>
<body>
<!-- HTML Div that contains our Leaflet-map --->
<div id="map"></div>
<button id="newTourOnArea" name="newTour"> New Tour from Area </button>
<script>
// <link rel="stylesheet" href="leaflet.awesome-markers.css">
// <script src="leaflet.awesome-markers.js">
var datalayer_style = {
"color": "#ff7800",
"weight": 5,
"opacity": 0.65
};
var hereMarker = L.AwesomeMarkers.icon({
color: 'red'
});
var areaFilter = false;
var tourBounds = null;
var bounds = new L.LatLngBounds();
var fileCount = 0;
var maxDist = 1000;
var nearestDist = null;
var nearestFeature = null;
var map = new L.Map('map', {doubleClickZoom: false});
var myLocation = null;
var randomLocations = 4;
var locationList = [];
var visibleLocations = [];
var discardedLocations = [];
var geojsonLayer = L.geoJson(null, {
style: datalayer_style,
onEachFeature: pushToList, // Bind popup to feature
filter: nearMe
});
var turkudata = "data/turku touring museot yms.txt";
var dataLists = ["data/Suihkukaivotaideteokset_epsg4326.geojson",
"data/Ulkoveistokset_epsg4326.geojson",
"data/Ymparistotaideteokset_epsg4326.geojson",
"data/museot_yms.geojson"
];
$("#newTourOnArea").click(function(){
console.log("New Tour");
var oldMarker;
while (oldMarker = visibleLocations.pop()) {
map.removeLayer(oldMarker);
}
console.log(locationList);
locationList=[];
discardedLocations = [];
fileCount = 0;
areaFilter = true;
tourBounds = map.getBounds();
bounds = new L.LatLngBounds();
console.log(tourBounds);
getNewLocationList();
console.log(locationList);
});
function updateRndLocation(e) {
}
function locationDblClick(e) {
var index = $.inArray(e.target, visibleLocations);
var newLocation = newRndLocation();
if (newLocation) {
var oldMarker = visibleLocations.splice(index,1)[0];
discardedLocations.push(oldMarker);
map.removeLayer(oldMarker);
map.fitBounds(bounds);
} else {
// Put the discardedlocationlist into locationlist
alert ("Sorry - run out of points of interests. Starting to select the old ones again.");
locationList = discardedLocations;
discardedLocations = [];
if (locationList.length) {
// Get one new venue from the locationpile
locationDblClick(e);
}
}
}
function locationClick(e) {
}
function updateLocationList() {
}
function initmap() {
// Set up the map
// Create baselayer using Open Street Map
var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
var osmAttrib='Map data © OpenStreetMap contributors </br> Random Tour by Kari-Pekka Pyylampi & Juho Loukonen';
var osm = new L.TileLayer(osmUrl, {minZoom: 8, maxZoom: 20, attribution: osmAttrib});
// Set coordinates and zoom for the map view
map.locate({setView: true, maxZoom: 15, watch: true});
map.on('locationfound', onLocationFound);
map.on('locationerror', onLocationError);
map.addLayer(osm);
//$.map(dataLists, readDataList);
// GeoJSON is stored inside a file, fetch data using Ajax-request.
}
function readDataList(e, i){
$.ajax({
type: "GET",
url: e,
dataType: 'json',
success: function (response, dataLen, i) {
geojsonLayer.addData(response);
if (dataLists.length === ++fileCount){
initRandomData();
}
}
});
}
function newRndLocation() {
if (locationList.length > 0) {
var index = Math.floor(Math.random() * locationList.length);
var marker = locationList.splice(index,1)[0];
map.addLayer(marker);
//marker.openPopup();
bounds.extend(marker.getLatLng());
visibleLocations.push(marker);
return marker;
} else {
return false;
}
}
function initRandomData(){
console.log("Points of interest "+ locationList.length);
for (i=0; i< randomLocations; i++){
if (!newRndLocation()) break;
}
if (visibleLocations.length > 0) {
map.fitBounds(bounds);
} else {
if (areaFilter) {
alert("No points of interest within area");
} else {
if (nearestFeature) {
pushToList(nearestFeature, null);
alert("No points within " + maxDist +"meters. Showing the nearest one.");
initRandomData();
}
}
}
}
function nearMe(feature, layer){
if (areaFilter) {
return tourBounds.contains([feature.geometry.coordinates[1],
feature.geometry.coordinates[0]]);
} else {
var dist = myLocation.getLatLng().distanceTo([feature.geometry.coordinates[1],
feature.geometry.coordinates[0]]);
// Get nearest feature.
if ((!nearestDist) || (dist < nearestDist)) {
nearestDist = dist;
nearestFeature = feature;
}
return (dist < maxDist);
}
}
function pushToList(feature, layer){
var new_marker = new L.Marker([feature.geometry.coordinates[1],
feature.geometry.coordinates[0]]);
new_marker.bindPopup(feature.properties.ttj_teokse); // Set name as popup
new_marker.on('click', locationClick);
new_marker.on('dblclick', locationDblClick);
locationList.push(new_marker);
}
function showText(feature, layer){
feature.target.openPopup();
}
// Adds name of the area as popup
function displayName(feature, layer){
if (feature.properties.Teksti) {
layer.bindPopup(feature.properties.Teksti);
}
}
function getNewPoint(feature, layer){
console.log(feature);
}
function onLocationFound(e) {
console.log(e.latlng);
//Calculate radius
var radius = e.accuracy / 2;
//Where you are!
if (myLocation) {
myLocation.setLatLng(e.latlng).update();
} else {
(myLocation = L.marker(e.latlng, {icon: hereMarker}).addTo(map)).bindPopup(
"You are within " + radius + " meters from this point").openPopup();
console.log(bounds);
bounds.extend(myLocation.getLatLng());
console.log(bounds)
getNewLocationList();
}
}
function getNewLocationList(){
$.map(dataLists, readDataList);
}
/**
* Users location is not defined or blocked
*/
function onLocationError(e) {
console.log(e.message);
// Set coordinates and zoom for the map view
// if (myLocation) {
//
// }
map.setView(new L.LatLng(60.457218, 22.256584),12);
//drawRestaurantMarkers(false);
}
// Run initmap-function when site is loaded
initmap();
</script>
</body>
</html>
</body>
</html>