-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdump.php
More file actions
254 lines (235 loc) · 12.2 KB
/
Copy pathdump.php
File metadata and controls
254 lines (235 loc) · 12.2 KB
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
<!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">
<title>Cheeeeese</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;500;700&display=swap" rel="stylesheet">
<script>
tailwind.config = {
theme: {
extend: {
colors: {
'navy-blue': '#18324F',
'light-pink': '#F5DCDC',
'soft-orange': '#F9A48B',
'light-teal': '#8ABEBD',
'japan-red': '#BC002D',
'mid-gray': '#444444',
'section-gray': '#f7f7f7'
},
fontFamily: {
'sans': ['Noto Sans JP', 'sans-serif']
}
}
}
}
</script>
</head>
<body class="font-sans bg-light-pink text-mid-gray overflow-x-hidden">
<?php include 'header.php'; ?>
<main class="pb-20">
<div class="relative">
<div class="max-w-4xl mx-auto absolute top-4 left-1/2 transform -translate-x-1/2 z-40 w-4/5 flex items-center">
<input type="text" placeholder="検索..." class="flex-1 p-2 rounded-l-md shadow bg-white text-[#173953] border border-gray-300" />
<button class="bg-[#18324F] text-white px-4 py-2 rounded-r-md hover:bg-[#14263a]">
<i class="fas fa-search"></i>
</button>
</div>
<div id="map" class="w-full h-[600px] z-0"></div>
</div>
<div class="absolute bottom-24 right-4 z-40 space-y-2">
<button onclick="map.zoomIn()" class="bg-white border border-gray-300 rounded p-2 shadow hover:bg-gray-100">+</button>
<button onclick="map.zoomOut()" class="bg-white border border-gray-300 rounded p-2 shadow hover:bg-gray-100">−</button>
</div>
<div class="absolute bottom-40 right-4 z-40">
<button id="gotoUserLocation" class="bg-white border border-gray-300 rounded p-2 shadow hover:bg-gray-100 flex items-center">
<i class="fas fa-location-crosshairs mr-1"></i>
</button>
</div>
</main>
<?php include 'footer.php'; ?>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
<script>
// Mobile menu and language toggle scripts (unchanged for map functionality)
const menuToggle = document.getElementById('menuToggle');
const closeMenu = document.getElementById('closeMenu');
const mobileMenu = document.getElementById('mobileMenu');
menuToggle.addEventListener('click', () => {
mobileMenu.classList.add('open');
});
closeMenu.addEventListener('click', () => {
mobileMenu.classList.remove('open');
});
document.addEventListener('click', (e) => {
if (!mobileMenu.contains(e.target) && e.target !== menuToggle && mobileMenu.classList.contains('open')) {
mobileMenu.classList.remove('open');
}
});
const langButton = document.getElementById('langButton');
const langMenu = document.getElementById('langMenu');
langButton.addEventListener('click', function (e) {
e.stopPropagation();
langMenu.classList.toggle('hidden');
});
document.addEventListener('click', function () {
langMenu.classList.add('hidden');
});
// Leaflet Map Specific Scripts
let userLatLng = null; // Store user location
let userMarker = null; // Marker for user's current location
let currentRoute = null; // Store the current route polyline
let nambaMarker = null; // Marker for Namba
// IMPORTANT: Replace with your actual GraphHopper API Key
const GH_KEY = "48056ade-9f61-49bc-820b-980d7facb179"; //
const map = L.map('map', { zoomControl: false }).setView([34.6937, 135.5023], 14); // Centered on Osaka
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© OpenStreetMap contributors'
}).addTo(map);
// Detect user location
function setupGeolocation() {
if (navigator.geolocation) {
navigator.geolocation.watchPosition(
function(position) {
const lat = position.coords.latitude;
const lng = position.coords.longitude;
userLatLng = [lat, lng];
if (userMarker) {
userMarker.setLatLng(userLatLng);
} else {
userMarker = L.marker(userLatLng, {
icon: L.icon({
iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
})
}).addTo(map)
.bindPopup("現在地").openPopup();
}
// Optional: Center map on user location initially
// map.setView(userLatLng, 16);
},
function(error) {
console.error("Error getting user location:", error);
// Fallback to Osaka default if geolocation fails
if (!userLatLng) { // Only set if not already set by a successful watchPosition
userLatLng = [34.6937, 135.5023]; // Default to Osaka
if (!userMarker) {
userMarker = L.marker(userLatLng, {
icon: L.icon({
iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
})
}).addTo(map)
.bindPopup("現在地 (位置情報取得失敗)").openPopup();
}
}
},
{ enableHighAccuracy: true, timeout: 10000, maximumAge: 0 } // Increased timeout
);
} else {
console.log("Geolocation is not supported by this browser.");
userLatLng = [34.6937, 135.5023]; // Default to Osaka
userMarker = L.marker(userLatLng, {
icon: L.icon({
iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-red.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
})
}).addTo(map)
.bindPopup("現在地 (位置情報未対応)").openPopup();
}
}
// Call setupGeolocation immediately
setupGeolocation();
// Button to go to user's current location
document.getElementById('gotoUserLocation').addEventListener('click', function() {
if (userLatLng) {
map.setView(userLatLng, 16); // Zoom in on user's location
if (userMarker) userMarker.openPopup();
} else {
alert("位置情報を取得できませんでした。ブラウザの設定を確認してください。");
// Try to get location again if it failed
setupGeolocation();
}
});
/* ======== GraphHopper Routing Function ======== */
async function getRoute(start, dest) {
// Remove previous route if it exists
if (currentRoute) {
map.removeLayer(currentRoute);
currentRoute = null; // Clear the reference
}
// Ensure userLatLng is available before routing
if (!userLatLng) {
alert("現在地がまだ取得できていません。しばらくお待ちいただくか、ブラウザの位置情報設定を確認してください。");
return;
}
const url = `https://graphhopper.com/api/1/route`
+ `?point=${start[0]},${start[1]}`
+ `&point=${dest[0]},${dest[1]}`
+ `&vehicle=foot&locale=ja` // vehicle=foot for walking. Change to 'car' for car.
+ `&points_encoded=false`
+ `&key=${GH_KEY}`; //
console.log("Fetching route from:", url); // Log the URL
try {
const res = await fetch(url);
if (!res.ok) { // Check for HTTP errors
const errorJson = await res.json();
console.error("GraphHopper API Error:", errorJson);
alert(`ルートを取得できませんでした: ${errorJson.message || '不明なエラー'}`);
return;
}
const json = await res.json();
if (json.paths && json.paths.length) { //
// GraphHopper gives [lon,lat] -> reverse to [lat,lon] for Leaflet
const coords = json.paths[0].points.coordinates //
.map(c => [c[1], c[0]]); //
console.log("GraphHopper route coordinates (Leaflet format):", coords); // Check parsed coords
// Use a distinct color for the route to make it stand out
currentRoute = L.polyline(coords, {color: "purple", weight: 5, opacity: 0.8}).addTo(map);
map.fitBounds(currentRoute.getBounds(), {padding: [50, 50]}); // Add padding to fitBounds
} else {
alert("ルートを取得できませんでした。別の地点をお試しください。");
}
} catch (err) {
console.error("Error fetching route:", err);
alert("ルートを取得中にエラーが発生しました。");
}
}
/* ======== Dummy marker at なんば ======== */
const namba = [34.6679, 135.5015];
nambaMarker = L.marker(namba, {
icon: L.icon({
iconUrl: 'https://cdn.rawgit.com/pointhi/leaflet-color-markers/master/img/marker-icon-2x-blue.png',
shadowUrl: 'https://cdnjs.cloudflare.com/ajax/libs/leaflet/0.7.7/images/marker-shadow.png',
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41]
})
}).addTo(map).bindPopup(`
<strong>なんば(ダミー)</strong><br>
<button onclick="getRoute(userLatLng, namba)" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-1 px-2 rounded mt-2">
ここまでルート
</button>
`);
</script>
</body>
</html>