Skip to content

Commit 558f7ed

Browse files
author
Jason Fox
committed
Created initial example set and updated the README.md
1 parent ba4ef80 commit 558f7ed

File tree

236 files changed

+8092
-2
lines changed

Some content is hidden

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

236 files changed

+8092
-2
lines changed

README.md

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,63 @@
1-
# maps-api-for-javascript-examples
2-
Self-contained examples for Maps API for JavaScript
1+
# Maps API for JavaScript
2+
3+
This repository holds a series of JavaScript based examples using the **HERE Maps API for JavaScript**. More information about the API can be found on [developer.here.com](https://developer.here.com/).
4+
5+
This set of self-contained, use-case based examples is designed to be cloned by developers for their own use.
6+
7+
8+
**Note:** In order to get the sample code to work, you **must** replace all instances of `{YOUR_APP_ID}` and `{YOUR_APP_CODE}` within the code and use your own HERE credentials.
9+
10+
You can obtain a set of credentials from the [Plans Page](https://developer.here.com/plans/api/consumer-mapping) on developer.here.com.
11+
12+
## Maps API for JavaScript
13+
14+
All of the following examples use **version 3.0** of the API
15+
16+
* [Adding Meta Information layer to the Map](tree/master/meta-info-layer) - Retrieve meta information of city labels, transit stations, etc.
17+
* [Adding Venues layer to the Map](tree/master/venues-layer) - Display venue objects (e.g. shops, airports etc) on the map
18+
* [Adding a Ground Overlay to the Map](tree/master/ground-overlay) - Display an image over a specified geographical area.
19+
* [Adding an Overlay to the Map](tree/master/custom-tile-overlay) - Display custom map tiles as an overlay
20+
* [Calculating a Location from a Mouse Click](tree/master/position-on-mouse-click) - Obtain the latitude and longitude of a location within the map
21+
* [Changing from the Metric System](tree/master/map-scale-bar-changing-from-the-metric-system) - Display a map including a scale bar in miles or yards
22+
* [Circle on the Map](tree/master/circle-on-the-map) - Display a map highlighting a circular region
23+
* [DOM Marker](tree/master/map-with-dom-marker) - Display a marker that is capable of receiving DOM events
24+
* [Detailed Place Information](tree/master/get-place-details) - Request detailed information about a place marked on the map selected using a mouse click
25+
* [Display Interactive KML Objects](tree/master/map-with-interactive-kml-objects) - Parse a KML file and display and interact with the data on a map
26+
* [Display KML Data](tree/master/display-kml-on-map) - Parse a KML file and display the data on a map
27+
* [Draggable Marker](tree/master/draggable-marker) - Display a moveable marker on a map
28+
* [Explore Nearby Places](tree/master/identify-places-at-location) - Request a list of places close to a location and display them on a map
29+
* [Explore Popular Places by Category](tree/master/explore-places) - Request a list of places within a category around a location and display them on a map.
30+
* [Finding the Nearest Marker](tree/master/finding-the-nearest-marker) - Find a marker nearest to the click location
31+
* [Map Objects Event Delegation](tree/master/map-objects-event-delegation) - Use event delegation on map objects
32+
* [Map Objects Events](tree/master/map-object-events-displayed) - Handle events on various map objects
33+
* [Map UI Components](tree/master/moved-map-components) - Display a map with the standard UI components in an altered location
34+
* [Map at a specified location](tree/master/map-at-specified-location) - Display a map at a specified location and zoom level
35+
* [Map using View Bounds](tree/master/map-using-view-bounds) - Display a map of a given area
36+
* [Map with Driving Route from A to B](tree/master/map-with-route-from-a-to-b) - Request a driving route from A to B and display it on the map.
37+
* [Map with Pedestrian Route from A to B](tree/master/map-with-pedestrian-route-from-a-to-b) - Request a walking route from A to B and display it on the map.
38+
* [Map with Route from A to B using Public Transport](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.
39+
* [Map with Truck Route from A to B](tree/master/map-with-truck-route-from-a-to-b) - Request a truck route from A to B and display it on the map.
40+
* [Marker Clustering](tree/master/marker-clustering) - Cluster multiple markers together to better visualize the data
41+
* [Marker Clustering with Custom Theme](tree/master/custom-cluster-theme) - Cluster multiple markers and customize the theme
42+
* [Marker on the Map](tree/master/markers-on-the-map) - Display a map highlighting points of interest
43+
* [Multi-language support](tree/master/map-multi-language-support) - Display a map with labels in a foreign language
44+
* [One-Box Search](tree/master/search-for-places) - Request a list of nearby places based on a query string and display them on a map
45+
* [Opening an Infobubble on a Mouse Click](tree/master/open-infobubble) - Open an infobubble when a marker is clicked
46+
* [Ordering Overlapping Markers](tree/master/ordering-overlapping-markers) - Arrange the order in which a series of map objects are displayed
47+
* [Panning the Map](tree/master/panning-the-map) - Programmatically pan the map so that it is continually in motion
48+
* [Polygon on the Map](tree/master/polygon-on-the-map) - Display a map highlighting a region or area
49+
* [Polyline on the Map](tree/master/polyline-on-the-map) - Display a map with a line showing a known route
50+
* [Rectangle on the map](tree/master/rectangle-on-the-map) - Display a map highlighting a retangular region or area
51+
* [Restrict Map Movement](tree/master/restrict-map) - Restrict a moveable map to a given rectangular area
52+
* [SVG Graphic Markers](tree/master/map-with-svg-graphic-markers) - Display a map with custom SVG markers
53+
* [Search for a Landmark](tree/master/search-for-landmark) - Request the location of a landmark and display it on the map.
54+
* [Search for a Location based on an Address](tree/master/geocode-a-location-from-address) - Request a location using a free-form text input and display it on the map.
55+
* [Search for a Location given a Structured Address](tree/master/geocode-a-location-from-structured-address) - Request a location from a structured address and display it on the map.
56+
* [Search for the Address of a Known Location](tree/master/reverse-geocode-an-address-from-location) - Request address details for a given location and display it on the map.
57+
* [Store map tiles for offline usage](tree/master/offline-map) - Store map tiles for offline usage
58+
* [Synchronising Two Maps](tree/master/synchronising-two-maps) - Synchronise a static map with an interactive map
59+
* [Take a Snapshot of the Map](tree/master/capture-map-area) - Capture an area on the map
60+
* [Terrain Map](tree/master/terrain-map) - Display a topographical map
61+
* [Traffic Information](tree/master/showing-traffic-information) - Display traffic information on the map
62+
* [Zoom into Bounds](tree/master/custom-zooming-into-bounds) - Zoom into bounds limiting maximum level
63+
* [Zooming to a Set of Markers](tree/master/zoom-to-set-of-markers) - Alter the viewport to ensure a group of objects are visible

capture-map-area/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
5+
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
6+
<meta name="description" content="Capture an area on the map">
7+
<title>Take a Snapshot of the Map</title>
8+
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css" />
9+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
10+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
11+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
12+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
13+
</head>
14+
<body>
15+
<h1>Take a Snapshot of the Map</h1>
16+
<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>
17+
<div id="map" style="width: 600px; height: 400px; background: grey"></div>
18+
<div id="panel" style="width: 600px;"></div>
19+
<script type="text/javascript" src='js/app.js'></script>
20+
</body>
21+
</html>

capture-map-area/js/app.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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: '{YOUR_APP_ID}',
32+
app_code: '{YOUR_APP_CODE}',
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+
};

capture-map-area/thumb.jpg

7.68 KB
Loading

circle-on-the-map/circle-on-map.png

15.2 KB
Loading

circle-on-the-map/index.html

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
5+
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
6+
<meta name="description" content="Display a map highlighting a circular region">
7+
<title>Circle on the Map</title>
8+
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css" />
9+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
10+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
11+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
12+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
13+
</head>
14+
<body>
15+
<h1>Circle on the Map</h1>
16+
<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>
17+
<div id="map" style="width: 600px; height: 400px; background: grey"></div>
18+
<script type="text/javascript" src='js/app.js'></script>
19+
</body>
20+
</html>

circle-on-the-map/js/app.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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: '{YOUR_APP_ID}',
34+
app_code: '{YOUR_APP_CODE}',
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);
3.9 KB
Loading

custom-cluster-theme/data/photos.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
1.88 KB
Loading

custom-cluster-theme/index.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
5+
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
6+
<meta name="description" content="Cluster multiple markers and customize the theme">
7+
<title>Marker Clustering with Custom Theme</title>
8+
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css" />
9+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-core.js"></script>
10+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-service.js"></script>
11+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
12+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
13+
<script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-clustering.js"></script>
14+
</head>
15+
<body>
16+
<h1>Marker Clustering with Custom Theme</h1>
17+
<p>This example displays a map&nbsp;showing geo-tagged clusters of photographs taken from locations&nbsp;around the world. The <a target="_blank" rel="nofollow" href="http://commons.wikimedia.org/wiki/Main_Page">Wikimedia Commons</a> website was used to provide&nbsp;a source of data of geo-tagged images.</p>
18+
<div id="map" style="width: 600px; height: 400px; background: grey"></div>
19+
<script type="text/javascript" src='js/app.js'></script>
20+
</body>
21+
</html>

0 commit comments

Comments
 (0)