Skip to content

Commit f054385

Browse files
author
Jason Fox
committed
Created initial example set
1 parent 22caf15 commit f054385

File tree

267 files changed

+8855
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

267 files changed

+8855
-0
lines changed

README.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# jsFiddle Examples
2+
3+
This repository holds a series of JavaScript based examples demonstrating the use the HERE Maps API for JavaScript. It is designed to be consumed by the jsfiddle github API.
4+
5+
You do not need to clone this repository, just use the links below to navigate to [jsfiddle](http://jsfiddle.net).
6+
7+
## Maps API for JavaScript 3.x
8+
9+
* [Adding Meta Information layer to the Map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/meta-info-layer) - Retrieve meta information of city labels, transit stations, etc.
10+
* [Adding Venues layer to the Map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/venues-layer) - Display venue objects (e.g. shops, airports etc) on the map
11+
* [Adding a Ground Overlay to the Map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/ground-overlay) - Display an image over a specified geographical area.
12+
* [Adding an Overlay to the Map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/custom-tile-overlay) - Display custom map tiles as an overlay
13+
* [Calculating a Location from a Mouse Click](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/position-on-mouse-click) - Obtain the latitude and longitude of a location within the map
14+
* [Changing from the Metric System](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-scale-bar-changing-from-the-metric-system) - Display a map including a scale bar in miles or yards
15+
* [Circle on the Map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/circle-on-the-map) - Display a map highlighting a circular region
16+
* [DOM Marker](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-with-dom-marker) - Display a marker that is capable of receiving DOM events
17+
* [Detailed Place Information](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/get-place-details) - Request detailed information about a place marked on the map selected using a mouse click
18+
* [Display Interactive KML Objects](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-with-interactive-kml-objects) - Parse a KML file and display and interact with the data on a map
19+
* [Display KML Data](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/display-kml-on-map) - Parse a KML file and display the data on a map
20+
* [Draggable Marker](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/draggable-marker) - Display a moveable marker on a map
21+
* [Explore Nearby Places](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/identify-places-at-location) - Request a list of places close to a location and display them on a map
22+
* [Explore Popular Places by Category](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/explore-places) - Request a list of places within a category around a location and display them on a map.
23+
* [Finding the Nearest Marker](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/finding-the-nearest-marker) - Find a marker nearest to the click location
24+
* [Map Objects Event Delegation](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-objects-event-delegation) - Use event delegation on map objects
25+
* [Map Objects Events](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-object-events-displayed) - Handle events on various map objects
26+
* [Map UI Components](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/moved-map-components) - Display a map with the standard UI components in an altered location
27+
* [Map at a specified location](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-at-specified-location) - Display a map at a specified location and zoom level
28+
* [Map using View Bounds](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-using-view-bounds) - Display a map of a given area
29+
* [Map with Driving Route from A to B](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-with-route-from-a-to-b) - Request a driving route from A to B and display it on the map.
30+
* [Map with Pedestrian Route from A to B](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-with-pedestrian-route-from-a-to-b) - Request a walking route from A to B and display it on the map.
31+
* [Map with Route from A to B using Public Transport](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-with-route-from-a-to-b-using-public-transport) - Request a route from A to B using public transport and display it on the map.
32+
* [Map with Truck Route from A to B](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-with-truck-route-from-a-to-b) - Request a truck route from A to B and display it on the map.
33+
* [Marker on the Map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/markers-on-the-map) - Display a map highlighting points of interest
34+
* [Multi-language support](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-multi-language-support) - Display a map with labels in a foreign language
35+
* [One-Box Search](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/search-for-places) - Request a list of nearby places based on a query string and display them on a map
36+
* [Opening an Infobubble on a Mouse Click](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/open-infobubble) - Open an infobubble when a marker is clicked
37+
* [Ordering Overlapping Markers](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/ordering-overlapping-markers) - Arrange the order in which a series of map objects are displayed
38+
* [Panning the Map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/panning-the-map) - Programmatically pan the map so that it is continually in motion
39+
* [Polygon on the Map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/polygon-on-the-map) - Display a map highlighting a region or area
40+
* [Polyline on the Map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/polyline-on-the-map) - Display a map with a line showing a known route
41+
* [Rectangle on the map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/rectangle-on-the-map) - Display a map highlighting a retangular region or area
42+
* [Restrict Map Movement](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/restrict-map) - Restrict a moveable map to a given rectangular area
43+
* [SVG Graphic Markers](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/map-with-svg-graphic-markers) - Display a map with custom SVG markers
44+
* [Search for a Landmark](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/search-for-landmark) - Request the location of a landmark and display it on the map.
45+
* [Search for a Location based on an Address](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/geocode-a-location-from-address) - Request a location using a free-form text input and display it on the map.
46+
* [Search for a Location given a Structured Address](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/geocode-a-location-from-structured-address) - Request a location from a structured address and display it on the map.
47+
* [Search for the Address of a Known Location](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/reverse-geocode-an-address-from-location) - Request address details for a given location and display it on the map.
48+
* [Store map tiles for offline usage](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/offline-map) - Store map tiles for offline usage
49+
* [Synchronising Two Maps](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/synchronising-two-maps) - Synchronise a static map with an interactive map
50+
* [Take a Snapshot of the Map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/capture-map-area) - Capture an area on the map
51+
* [Terrain Map](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/terrain-map) - Display a topographical map
52+
* [Traffic Information](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/showing-traffic-information) - Display traffic information on the map
53+
* [Zoom into Bounds](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/custom-zooming-into-bounds) - Zoom into bounds limiting maximum level
54+
* [Zooming to a Set of Markers](http://jsfiddle.net/gh/get/jquery/2.1.0/heremaps/jsfiddle-github/tree/master/zoom-to-set-of-markers) - Alter the viewport to ensure a group of objects are visible

capture-map-area/demo.css

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
code, h1, h2, h3{
3+
color: #124191;
4+
letter-spacing: -0.03em;
5+
}
6+
body {
7+
font-family:"Lucida Grande",Tahoma,sans-serif;
8+
color: rgb(102, 102, 102);
9+
font-size: 80%;
10+
}
11+
b, strong {
12+
color: black;
13+
}
14+
code {
15+
font-weight: 700;
16+
font-size: 120%;
17+
}

capture-map-area/demo.details

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: Take a Snapshot of the Map
3+
description: Capture an area on the map
4+
resources:
5+
- https://js.api.here.com/v3/3.0/mapsjs-ui.css
6+
normalize_css: no
7+
dtd: html 5
8+
wrap: d
9+
panel_html: 0
10+
panel_js: 0
11+
panel_css: 0
12+
...

capture-map-area/demo.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- SCRIPTS -->
2+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
3+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
4+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
5+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
6+
7+
<!-- BODY -->
8+
<h1>Take a Snapshot of the Map</h1>
9+
<p><span>This example demonstrates how to take a snapshot of&nbsp;the map.&nbsp;It specifies area to be captured with&nbsp;top/left and bottom/right view port&nbsp;coordinates<br></span></p>
10+
<hr/>
11+
<div id="map" style="width: 600px; height: 300px; background: grey;" ></div>
12+
<hr/>
13+
<div id="panel" style="width: 600px; "></div>

capture-map-area/demo.js

+81
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Takes a snapshot of the map.
3+
*
4+
* @param {Element} resultContainer Reference to DOM Element to show the captured map area
5+
* @param {H.Map} map Reference to initialized map object
6+
* @param {H.ui.UI} ui Reference to UI component
7+
*/
8+
function capture(resultContainer, map, ui) {
9+
// Capturing area of the map is asynchronous, callback function receives HTML5 canvas
10+
// element with desired map area rendered on it.
11+
// We also pass an H.ui.UI reference in order to see the ScaleBar in the output.
12+
// If dimensions are omitted, whole veiw port will be captured
13+
map.capture(function(canvas) {
14+
if (canvas) {
15+
resultContainer.innerHTML = '';
16+
resultContainer.appendChild(canvas);
17+
} else {
18+
// For example when map is in Panorama mode
19+
resultContainer.innerHTML = 'Capturing is not supported';
20+
}
21+
}, [ui], 50, 50, 500, 200);
22+
}
23+
24+
25+
26+
/**
27+
* Boilerplate map initialization code starts below:
28+
*/
29+
// Step 1: initialize communication with the platform
30+
var platform = new H.service.Platform({
31+
app_id: 'DemoAppId01082013GAL',
32+
app_code: 'AJKnXv84fjrb0KIHawS0Tg',
33+
useHTTPS: true,
34+
useCIT: true
35+
});
36+
var defaultLayers = platform.createDefaultLayers();
37+
38+
var mapContainer = document.getElementById('map');
39+
40+
// Step 2: initialize a map
41+
var map = new H.Map(mapContainer, defaultLayers.normal.map, {
42+
// initial center and zoom level of the map
43+
zoom: 16,
44+
// Champs-Elysees
45+
center: {lat: 48.869145, lng: 2.314298}
46+
});
47+
48+
// Step 3: make the map interactive
49+
// MapEvents enables the event system
50+
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
51+
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
52+
53+
// Step 4: Create the default UI
54+
var ui = H.ui.UI.createDefault(map, defaultLayers, 'en-US');
55+
56+
57+
// Step 6: Create "Capture" button and place for showing the captured area
58+
var resultContainer = document.getElementById('panel');
59+
60+
// Create container for the "Capture" button
61+
var containerNode = document.createElement('div');
62+
containerNode.setAttribute('style',
63+
'position:absolute;top:0;left:0;background-color:#fff; padding:10px;');
64+
containerNode.className = 'btn-group';
65+
66+
// Create the "Capture" button
67+
var captureBtn = document.createElement('input');
68+
captureBtn.value = 'Capture';
69+
captureBtn.type = 'button';
70+
captureBtn.className = 'btn btn-sm btn-default';
71+
72+
// Add both button and container to the DOM
73+
containerNode.appendChild(captureBtn);
74+
mapContainer.appendChild(containerNode);
75+
76+
// Step 7: Handle capture button click event
77+
captureBtn.onclick = function() {
78+
capture(resultContainer, map, ui);
79+
};
80+
81+
$('head').append('<link rel="stylesheet" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css" type="text/css" />');

circle-on-the-map/demo.css

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
code, h1, h2, h3{
3+
color: #124191;
4+
letter-spacing: -0.03em;
5+
}
6+
body {
7+
font-family:"Lucida Grande",Tahoma,sans-serif;
8+
color: rgb(102, 102, 102);
9+
font-size: 80%;
10+
}
11+
b, strong {
12+
color: black;
13+
}
14+
code {
15+
font-weight: 700;
16+
font-size: 120%;
17+
}

circle-on-the-map/demo.details

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: Circle on the Map
3+
description: Display a map highlighting a circular region
4+
resources:
5+
- https://js.api.here.com/v3/3.0/mapsjs-ui.css
6+
normalize_css: no
7+
dtd: html 5
8+
wrap: d
9+
panel_html: 0
10+
panel_js: 0
11+
panel_css: 0
12+
...

circle-on-the-map/demo.html

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!-- SCRIPTS -->
2+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
3+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
4+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
5+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
6+
7+
<!-- BODY -->
8+
<h1>Circle on the Map</h1>
9+
<p>This example shows a circle with a radius of 1000 meters centered over a location in <b>New Delhi</b> (<i>28.6071°N, 77.2127°E</i>) and displayed on a moveable map.</p>
10+
<hr/>
11+
<div id="map" style="width: 600px; height: 400px; background: grey"></div>
12+

circle-on-the-map/demo.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
/**
3+
* Adds a circle over New Delhi with a radius of 1000 metres onto the map
4+
*
5+
* @param {H.Map} map A HERE Map instance within the application
6+
*/
7+
function addCircleToMap(map){
8+
map.addObject(new H.map.Circle(
9+
// The central point of the circle
10+
{lat:28.6071, lng:77.2127},
11+
// The radius of the circle in meters
12+
1000,
13+
{
14+
style: {
15+
strokeColor: 'rgba(55, 85, 170, 0.6)', // Color of the perimeter
16+
lineWidth: 2,
17+
fillColor: 'rgba(0, 128, 0, 0.7)' // Color of the circle
18+
}
19+
}
20+
));
21+
}
22+
23+
24+
25+
26+
27+
/**
28+
* Boilerplate map initialization code starts below:
29+
*/
30+
31+
//Step 1: initialize communication with the platform
32+
var platform = new H.service.Platform({
33+
app_id: 'DemoAppId01082013GAL',
34+
app_code: 'AJKnXv84fjrb0KIHawS0Tg',
35+
useCIT: true,
36+
useHTTPS: true
37+
});
38+
var defaultLayers = platform.createDefaultLayers();
39+
40+
//Step 2: initialize a map - this map is centered over New Delhi
41+
var map = new H.Map(document.getElementById('map'),
42+
defaultLayers.normal.map,{
43+
center: {lat:28.6071, lng:77.2127},
44+
zoom: 13
45+
});
46+
47+
//Step 3: make the map interactive
48+
// MapEvents enables the event system
49+
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
50+
var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
51+
52+
// Create the default UI components
53+
var ui = H.ui.UI.createDefault(map, defaultLayers);
54+
55+
// Now use the map as required...
56+
addCircleToMap(map);
57+
58+
$('head').append('<link rel="stylesheet" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css" type="text/css" />');

custom-tile-overlay/demo.css

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
code, h1, h2, h3{
3+
color: #124191;
4+
letter-spacing: -0.03em;
5+
}
6+
body {
7+
font-family:"Lucida Grande",Tahoma,sans-serif;
8+
color: rgb(102, 102, 102);
9+
font-size: 80%;
10+
}
11+
b, strong {
12+
color: black;
13+
}
14+
code {
15+
font-weight: 700;
16+
font-size: 120%;
17+
}

custom-tile-overlay/demo.details

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: Adding an Overlay to the Map
3+
description: Display custom map tiles as an overlay
4+
resources:
5+
- https://js.api.here.com/v3/3.0/mapsjs-ui.css
6+
normalize_css: no
7+
dtd: html 5
8+
wrap: d
9+
panel_html: 0
10+
panel_js: 0
11+
panel_css: 0
12+
...

custom-tile-overlay/demo.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!-- BASE - this example uses relative URLs -->
2+
<base href="https://raw.githubusercontent.com/heremaps/jsfiddle-github/master/custom-tile-overlay/" />
3+
4+
<!-- SCRIPTS -->
5+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
6+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
7+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
8+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
9+
10+
<!-- BODY -->
11+
<h1>Adding an Overlay to the Map</h1>
12+
<p>This example displays a movable map initially centered on the historical centre of <b>Berlin</b> (<i>52.515, °N, 13.405°E</i>) with an overlay of a historical map from 1789 on top of the base map. A public domain&nbsp;<a target="_blank" rel="nofollow" href="http://commons.wikimedia.org/wiki/File:Map_de_berlin_1789_%28georeferenced%29.jpg">image</a> was used as a source, and split it into individual map tiles. Additional tiles are only downloaded when the zoom level or location changes.</p>
13+
<hr/>
14+
<div id="map" style="width: 600px; height: 400px; background: grey"></div>
15+

0 commit comments

Comments
 (0)