Skip to content

Commit df0c721

Browse files
author
Alfiya Tarasenko
committed
Add new routing + MapLibre example with elevation profile
1 parent 47d56fc commit df0c721

File tree

24 files changed

+2642
-12
lines changed

24 files changed

+2642
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Uses JavaScript and HTML to call the Geoapify Routing API for route data and the
5353
- [Geoapify Static Maps API](https://www.geoapify.com/static-maps-api/)
5454

5555
**Demo:**
56-
👉 [Printable Route Directions – Live Demo](https://geoapify.github.io/maps-api-code-samples/javascript/printable-route-directions/demo.html)
56+
👉 [Printable Route Directions – Live Demo](https://geoapify.github.io/maps-api-code-samples/javascript/printable-route-directions/demo_combined.html)
5757

5858
---
5959

javascript/.DS_Store

0 Bytes
Binary file not shown.

javascript/isolines-leaflet/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This code sample demonstrates how to calculate and display **isochrones** (time-
44

55
The application allows users to click on the map, configure travel mode and isoline parameters, and visualize the reachable area as a polygon layer. Each isoline is styled with a distinct color and includes a custom marker to indicate its origin.
66

7-
![Isoline Leaflet Screenshot](https://github.com/geoapify/maps-api-code-samples/blob/main/javascript/isolines-leaflet/isoline-leaflet-demo-screenshot.jpg?raw=true)
7+
![Screenshot: Isoline visualization with Leaflet and custom markers](https://github.com/geoapify/maps-api-code-samples/blob/main/javascript/isolines-leaflet/isoline-leaflet-demo-screenshot.jpg?raw=true)
88

99
The code calculates isolines with the [Geoapify Isoline API](https://www.geoapify.com/isoline-api/) and renders it dynamically using Leaflet:
1010

javascript/isolines-leaflet/demo_combined.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ <h3>Configure Isoline</h3>
404404

405405
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
406406
<script type="module">// Configuration
407-
const GEOAPIFY_API_KEY = '93b8e26606dd485183dcdab30f239f81'; // Replace with your actual API key
407+
const GEOAPIFY_API_KEY = '27a3c5f9a6754da28283d1995edb9467'; // Replace with your actual API key
408408
const DEFAULT_CENTER = [40.7128, -74.0060]; // New York coordinates (lat, lng for Leaflet)
409409
const DEFAULT_ZOOM = 13;
410410

javascript/isolines-maplibre/README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This code sample demonstrates how to calculate and visualize **isochrones** (tim
44

55
The application lets users click on the map, select travel mode and isoline type, and view the resulting polygon directly on a dynamic vector map. Each isoline is styled with a distinct color and features a custom marker that reflects the travel mode and value.
66

7-
![Isoline MapLibre Screenshot](https://github.com/geoapify/maps-api-code-samples/blob/main/javascript/isolines-maplibre/isoline-maplibre-demo-screenshot.jpg?raw=true)
7+
![Screenshot: Multiple isochrones with custom markers and colors](https://github.com/geoapify/maps-api-code-samples/blob/main/javascript/isolines-maplibre/isoline-maplibre-demo-screenshot.jpg?raw=true)
88

99
The application combines Geoapify APIs with MapLibre’s vector rendering engine:
1010

@@ -132,9 +132,6 @@ This will create a `demo_combined.html` file in the `isolines-maplibre/` folder,
132132

133133
> The script uses `src/demo.html` as input and outputs a self-contained file with embedded JavaScript and CSS.
134134
135-
136-
Вот следующий раздел — **Code Examples** — с ключевыми фрагментами из `isolines-maplibre`:
137-
138135
## Code Examples
139136

140137
Here are the key code snippets that power the application:

javascript/isolines-maplibre/demo_combined.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ <h3>Configure Isoline</h3>
393393

394394
<script src="https://unpkg.com/maplibre-gl@4.7.1/dist/maplibre-gl.js"></script>
395395
<script type="module">// Configuration
396-
const GEOAPIFY_API_KEY = '93b8e26606dd485183dcdab30f239f81'; // Replace with your actual API key
396+
const GEOAPIFY_API_KEY = '27a3c5f9a6754da28283d1995edb9467'; // Replace with your actual API key
397397
const DEFAULT_CENTER = [-74.0060, 40.7128]; // New York coordinates
398398
const DEFAULT_ZOOM = 13;
399399

javascript/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"inline-source": "^8.0.3"
4+
}
5+
}

javascript/printable-route-directions/README.md

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This combination of dynamic and static content allows users to interact with the
1313

1414
## Demo
1515

16-
You can see the code sample in action here: [Demo Link](https://geoapify.github.io/maps-api-code-samples/javascript/printable-route-directions/demo.html)
16+
You can see the code sample in action here: [Demo Link](https://geoapify.github.io/maps-api-code-samples/javascript/printable-route-directions/demo_combined.html)
1717

1818
## About the Code Sample
1919

@@ -312,7 +312,78 @@ The **`generateImageURL()`** function dynamically generates static map previews
312312
geometries.push(`polygon:${manoeuvreArrow};linewidth:1;linecolor:${encodeURIComponent('#333333')};fillcolor:${encodeURIComponent('#ffffff')};fillopacity:1`);
313313
```
314314

315-
### Summary
315+
## How to Run the Sample
316+
317+
You can run the Route + Elevation demo locally using a static server or directly in your IDE with live preview.
318+
319+
### Option 1: Run with a Local HTTP Server
320+
321+
Serve the contents of the folder using a static server:
322+
323+
1. **Install `http-server`** (if not already installed):
324+
325+
```bash
326+
npm install -g http-server
327+
```
328+
329+
2. **Start the server** from the folder containing your HTML and JS files:
330+
331+
```bash
332+
http-server .
333+
```
334+
335+
3. **Open the demo** in your browser:
336+
337+
```
338+
http://localhost:8080/demo.html
339+
```
340+
341+
Or use `npx` for a one-time server:
342+
343+
```bash
344+
npx http-server .
345+
```
346+
347+
### Option 2: Use IDE Live Preview
348+
349+
Many modern IDEs provide live preview for HTML files:
350+
351+
* **Visual Studio Code** — Install the “Live Server” extension, then right-click `src/demo.html` and choose **“Open with Live Server”**.
352+
* **WebStorm / IntelliJ / PhpStorm** — Right-click `src/demo.html` and choose **“Open in Browser”**.
353+
* **Brackets** — Click the **lightning bolt icon** or use **File → Live Preview**.
354+
355+
> Opening the file directly via `file://` protocol is not recommended, as some browsers block dynamic requests in local mode.
356+
357+
## How to Build `demo_combined.html`
358+
359+
As an alternative to running the project from multiple files, you can generate a standalone HTML file with all scripts and styles inlined. This is useful for GitHub Pages or distributing the demo as a single file.
360+
361+
### Steps
362+
363+
1. **Navigate to the parent folder**, e.g. `javascript/route-elevation-chart`:
364+
365+
```bash
366+
cd javascript/route-elevation-chart
367+
```
368+
369+
2. **Install the required build dependency**:
370+
371+
```bash
372+
npm install inline-source
373+
```
374+
375+
3. **Run the build script** (make sure `combine.js` exists in the folder):
376+
377+
```bash
378+
node combine.js
379+
```
380+
381+
This will generate a `demo_combined.html` file with all JavaScript and CSS embedded inline.
382+
383+
> The `combine.js` script should take `src/` as input and produce a portable version suitable for publishing or offline usage.
384+
385+
386+
## Summary
316387

317388
This code sample showcases how to use the **Geoapify Routing API** and **Geoapify Static Maps API** to generate rich, interactive route instructions and static map visuals. It includes key functionalities like:
318389

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const inlineSource = require('inline-source').inlineSource;
2+
const fs = require('fs').promises;
3+
const path = require('path');
4+
5+
async function inlineResources() {
6+
const htmlPath = path.resolve('route-directions/src/demo.html');
7+
const outputPath = path.resolve('route-directions/demo_combined.html');
8+
9+
try {
10+
const html = await inlineSource(htmlPath, {
11+
compress: false,
12+
rootpath: path.resolve('route-directions/src'),
13+
ignore: []
14+
});
15+
16+
await fs.writeFile(outputPath, html, 'utf-8');
17+
console.log(`✅ Combined HTML saved to ${outputPath}`);
18+
} catch (err) {
19+
console.error(`❌ Error: ${err.message}`);
20+
}
21+
}
22+
23+
inlineResources();
File renamed without changes.

0 commit comments

Comments
 (0)