-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmap.html
More file actions
338 lines (307 loc) · 17.6 KB
/
Copy pathmap.html
File metadata and controls
338 lines (307 loc) · 17.6 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
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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Map Routing</title>
<link rel="stylesheet" href="https://js.api.here.com/v3/3.1/mapsjs-ui.css" />
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<style>
/* Add your custom styles here */
#mapContainer {
width: 100%;
height: 400px;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="max-w-md mx-auto">
<!-- Starting Location Input -->
<div class="relative">
<input id="startingLocation" type="text" placeholder="Starting Location"
class="w-full py-2 px-4 border border-gray-300 rounded-md focus:outline-none focus:border-blue-500">
<div id="startingSuggestions"
class="absolute z-10 bg-white border border-gray-300 w-full mt-1 rounded-b-md shadow-lg hidden"></div>
</div>
<!-- Ending Location Input -->
<div class="relative mt-4">
<input id="endingLocation" type="text" placeholder="Ending Location"
class="w-full py-2 px-4 border border-gray-300 rounded-md focus:outline-none focus:border-blue-500">
<div id="endingSuggestions"
class="absolute z-10 bg-white border border-gray-300 w-full mt-1 rounded-b-md shadow-lg hidden"></div>
</div>
<!-- new code -->
<!-- component -->
<div class="flex h-screen bg-gray-100">
<div class="m-auto">
<div>
<button type="button"
class="relative w-full flex justify-center items-center px-5 py-2.5 font-medium tracking-wide text-white capitalize bg-black rounded-md hover:bg-gray-900 focus:outline-none transition duration-300 transform active:scale-95 ease-in-out">
<svg xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px"
viewBox="0 0 24 24" width="24px" fill="#FFFFFF">
<g>
<rect fill="none" height="24" width="24"></rect>
</g>
<g>
<g>
<path d="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6V13z"></path>
</g>
</g>
</svg>
<span class="pl-2 mx-1">Create new shipping label</span>
</button>
<div class="mt-5 bg-white rounded-lg shadow">
<div class="flex">
<div class="flex-1 py-5 pl-5 overflow-hidden">
<svg class="inline align-text-top" height="24px" viewBox="0 0 24 24" width="24px"
xmlns="http://www.w3.org/2000/svg" fill="#000000">
<g>
<path d="m4.88889,2.07407l14.22222,0l0,20l-14.22222,0l0,-20z" fill="none"
id="svg_1" stroke="null"></path>
<path
d="m7.07935,0.05664c-3.87,0 -7,3.13 -7,7c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zm-5,7c0,-2.76 2.24,-5 5,-5s5,2.24 5,5c0,2.88 -2.88,7.19 -5,9.88c-2.08,-2.67 -5,-7.03 -5,-9.88z"
id="svg_2"></path>
<circle cx="7.04807" cy="6.97256" r="2.5" id="svg_3"></circle>
</g>
</svg>
<h1 class="inline text-2xl font-semibold leading-none">Sender</h1>
</div>
</div>
<div class="relative">
<input id="startingLocation" type="text" placeholder="Starting Location"
class="w-full py-2 px-4 border border-gray-300 rounded-md focus:outline-none focus:border-blue-500">
<div id="startingSuggestions"
class="absolute z-10 bg-white border border-gray-300 w-full mt-1 rounded-b-md shadow-lg hidden"></div>
</div>
<div class="flex">
<div class="flex-1 py-5 pl-5 overflow-hidden">
<svg class="inline align-text-top" width="21" height="20.5"
xmlns="http://www.w3.org/2000/svg" fill="#000000">
<g>
<path d="m4.88889,2.07407l14.22222,0l0,20l-14.22222,0l0,-20z" fill="none"
id="svg_1" stroke="null"></path>
<path
d="m7.07935,0.05664c-3.87,0 -7,3.13 -7,7c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zm-5,7c0,-2.76 2.24,-5 5,-5s5,2.24 5,5c0,2.88 -2.88,7.19 -5,9.88c-2.08,-2.67 -5,-7.03 -5,-9.88z"
id="svg_2"></path>
<circle cx="7.04807" cy="6.97256" r="2.5" id="svg_3"></circle>
</g>
</svg>
<h1 class="inline text-2xl font-semibold leading-none">Receiver</h1>
</div>
<div class="flex-none pt-2.5 pr-2.5 pl-1"></div>
</div>
<div class="relative mt-4">
<input id="endingLocation" type="text" placeholder="Ending Location"
class="w-full py-2 px-4 border border-gray-300 rounded-md focus:outline-none focus:border-blue-500">
<div id="endingSuggestions"
class="absolute z-10 bg-white border border-gray-300 w-full mt-1 rounded-b-md shadow-lg hidden"></div>
</div>
<hr class="mt-4">
<div class="flex flex-row-reverse p-3">
<div class="flex-initial pl-3">
<button type="button"
class="flex items-center px-5 py-2.5 font-medium tracking-wide text-white capitalize bg-black rounded-md hover:bg-gray-800 focus:outline-none focus:bg-gray-900 transition duration-300 transform active:scale-95 ease-in-out">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24"
width="24px" fill="#FFFFFF">
<path d="M0 0h24v24H0V0z" fill="none"></path>
<path
d="M5 5v14h14V7.83L16.17 5H5zm7 13c-1.66 0-3-1.34-3-3s1.34-3 3-3 3 1.34 3 3-1.34 3-3 3zm3-8H6V6h9v4z"
opacity=".3"></path>
<path
d="M17 3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V7l-4-4zm2 16H5V5h11.17L19 7.83V19zm-7-7c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3zM6 6h9v4H6z">
</path>
</svg>
<span class="pl-2 mx-1">Save</span>
</button>
</div>
<div class="flex-initial">
<button type="button"
class="flex items-center px-5 py-2.5 font-medium tracking-wide text-black capitalize rounded-md hover:bg-red-200 hover:fill-current hover:text-red-600 focus:outline-none transition duration-300 transform active:scale-95 ease-in-out">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24"
width="24px">
<path d="M0 0h24v24H0V0z" fill="none"></path>
<path d="M8 9h8v10H8z" opacity=".3"></path>
<path
d="M15.5 4l-1-1h-5l-1 1H5v2h14V4zM6 19c0 1.1.9 2 2 2h8c1.1 0 2-.9 2-2V7H6v12zM8 9h8v10H8V9z">
</path>
</svg>
<span class="pl-2 mx-1">Delete</span>
</button>
</div>
</div>
</div>
<div class="mt-5 bg-white shadow cursor-pointer rounded-xl">
<div class="flex">
<div class="flex-1 py-5 pl-5 overflow-hidden">
<ul>
<li class="text-xs text-gray-600 uppercase ">Receiver</li>
<li>Max Mustermann</li>
<li>Musterstrasse 1</li>
<li>4020 Linz</li>
</ul>
</div>
<div class="flex-1 py-5 pl-1 overflow-hidden">
<ul>
<li class="text-xs text-gray-600 uppercase">Sender</li>
<li>Rick Astley</li>
<li>Rickrolled 11</li>
<li>1000 Vienna</li>
</ul>
</div>
<div class="flex-none pt-2.5 pr-2.5 pl-1">
<button type="button"
class="px-2 py-2 font-medium tracking-wide text-black capitalize transition duration-300 ease-in-out transform rounded-xl hover:bg-gray-300 focus:outline-none active:scale-95">
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24"
width="24px" fill="#000000">
<path d="M0 0h24v24H0V0z" fill="none"></path>
<path d="M5 18.08V19h.92l9.06-9.06-.92-.92z" opacity=".3"></path>
<path
d="M20.71 7.04c.39-.39.39-1.02 0-1.41l-2.34-2.34c-.2-.2-.45-.29-.71-.29s-.51.1-.7.29l-1.83 1.83 3.75 3.75 1.83-1.83zM3 17.25V21h3.75L17.81 9.94l-3.75-3.75L3 17.25zM5.92 19H5v-.92l9.06-9.06.92.92L5.92 19z">
</path>
</svg>
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div id="mapContainer" class="my-3"></div>
<!-- Include the HERE Maps JavaScript API -->
<script src="https://js.api.here.com/v3/3.1/mapsjs-core.js"></script>
<script src="https://js.api.here.com/v3/3.1/mapsjs-service.js"></script>
<script src="https://js.api.here.com/v3/3.1/mapsjs-ui.js"></script>
<script src="https://js.api.here.com/v3/3.1/mapsjs-mapevents.js"></script>
<!-- JavaScript code -->
<script>
const startingInput = document.getElementById('startingLocation');
const endingInput = document.getElementById('endingLocation');
const startingSuggestionsList = document.getElementById('startingSuggestions');
const endingSuggestionsList = document.getElementById('endingSuggestions');
const apiUrl = 'https://autosuggest.search.hereapi.com/v1/autosuggest';
const apiKey = 'YOUR_AUTOSUGGEST_API_KEY';
const language = 'en';
const limit = 5;
const termsLimit = 3;
// Initialize HERE platform
const platform = new H.service.Platform({
'apikey': 'IWkZZG8yg7_sabfcdfXNKPSM5vnzmShxTHVPipi99XE'
});
// Function to fetch suggestions
function fetchSuggestions(input, suggestionsList) {
const query = input.value.trim();
if (query.length === 0) {
suggestionsList.innerHTML = '';
return;
}
const url = `${apiUrl}?q=${query}&lang=${language}&limit=${limit}&termsLimit=${termsLimit}&apiKey=${apiKey}`;
fetch(url)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
// Clear previous suggestions
suggestionsList.innerHTML = '';
// Extract suggestions from the response and add them to the suggestions list
data.items.forEach(item => {
// Create a div element for each suggestion
const suggestionDiv = document.createElement('div');
suggestionDiv.textContent = item.title;
// Add a class to the suggestion div
suggestionDiv.classList.add('suggestion-item');
// Handle suggestion selection
suggestionDiv.addEventListener('click', () => {
// Log selected data to console
console.log('Selected:', item.position, item.title);
// Display selected data in the input box
input.value = item.title;
// Hide suggestions dropdown
suggestionsList.classList.add('hidden');
});
// Append the suggestion div to the suggestions list container
suggestionsList.appendChild(suggestionDiv);
});
suggestionsList.classList.remove('hidden');
})
.catch(error => {
console.error('There was a problem with your fetch operation:', error);
});
}
// Event listener for starting location input
startingInput.addEventListener('input', function () {
fetchSuggestions(startingInput, startingSuggestionsList);
});
// Event listener for ending location input
endingInput.addEventListener('input', function () {
fetchSuggestions(endingInput, endingSuggestionsList);
});
// Event listener for form submission
document.querySelector('form').addEventListener('submit', function (event) {
event.preventDefault();
calculateRoute(startingInput.value, endingInput.value);
});
function calculateRoute(startingLocation, endingLocation) {
// Initialize the geocoding and routing services
const service = platform.getSearchService();
const router = platform.getRoutingService();
// Geocode starting location
service.geocode({ q: startingLocation }, (result) => {
const startPoint = result.items[0].position;
// Geocode ending location
service.geocode({ q: endingLocation }, (result) => {
const endPoint = result.items[0].position;
// Create routing parameters
const params = {
mode: 'fastest;car',
waypoint0: `${startPoint.lat},${startPoint.lng}`, // starting point
waypoint1: `${endPoint.lat},${endPoint.lng}`, // ending point
representation: 'display'
};
// Calculate the route
router.calculateRoute(params, onSuccess, onError);
}, onError);
}, onError);
}
function onSuccess(result) {
const route = result.routes[0];
const routeShape = route.shape;
// Create a polyline to display the route:
const strip = new H.geo.Strip();
routeShape.forEach(point => {
const parts = point.split(',');
strip.pushLatLngAlt(parts[0], parts[1]);
});
const routeLine = new H.map.Polyline(strip, {
style: { strokeColor: '#4354b3', lineWidth: 5 }
});
// Clear previous route and markers
map.removeObjects(map.getObjects());
// Add route to the map
map.addObject(routeLine);
// Set map view to show entire route
map.getViewModel().setLookAtData({ bounds: routeLine.getBoundingBox() });
}
function onError(error) {
console.error('Error occurred:', error);
}
// Initialize HERE map
const map = new H.Map(
document.getElementById('mapContainer'),
new H.map.Provider.DefaultLayers.vector.normal.map,
{
center: { lat: 0, lng: 0 },
zoom: 2,
pixelRatio: window.devicePixelRatio || 1
}
);
const behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
// Enable map resize
window.addEventListener('resize', () => map.getViewPort().resize());
</script>
</body>
</html>