Skip to content

Commit cfc4241

Browse files
authored
Merge pull request #103 from heremaps/example-iml
Added, example Interactive Map Layer.
2 parents 431d43e + 1c5e3df commit cfc4241

File tree

6 files changed

+118
-0
lines changed

6 files changed

+118
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ All of the following examples use **version 3.1** of the API
2727
* [Extruded geo shapes](https://heremaps.github.io/maps-api-for-javascript-examples/extruded-objects/demo.html) - 3D extrusion of the geometric shapes
2828
* [Finding the Nearest Marker](https://heremaps.github.io/maps-api-for-javascript-examples/finding-the-nearest-marker/demo.html) - Find a marker nearest to the click location
2929
* [Image overlay](https://heremaps.github.io/maps-api-for-javascript-examples/image-overlay/demo.html) - Display an animated weather radar
30+
* [Interactive Map Layer](https://heremaps.github.io/maps-api-for-javascript-examples/transit-mapsjs-iml/demo.html) - Visualize Data from Interactive Map Layer on Map
3031
* [Interleave vector and object layers](https://heremaps.github.io/maps-api-for-javascript-examples/interleave-layers/demo.html) - Display an object under the buildings
3132
* [Map Objects Event Delegation](https://heremaps.github.io/maps-api-for-javascript-examples/map-objects-event-delegation/demo.html) - Use event delegation on map objects
3233
* [Map Objects Events](https://heremaps.github.io/maps-api-for-javascript-examples/map-object-events-displayed/demo.html) - Handle events on various map objects

meta.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@
112112
"title": "Display Venue data",
113113
"shortDescription": "Use Here Venues services to load and visualize an indoor data",
114114
"published": true
115+
},
116+
{
117+
"uid": "transit-mapsjs-iml",
118+
"title": "Interactive Map Layer",
119+
"shortDescription": "Visualize Data from Interactive Map Layer on Map.",
120+
"published": true
115121
}
116122
]
117123
},

transit-mapsjs-iml/demo.css

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
#map {
3+
width: 95%;
4+
height: 450px;
5+
background: grey;
6+
}
7+
8+
#panel {
9+
width: 100%;
10+
height: 400px;
11+
}

transit-mapsjs-iml/demo.details

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
name: Interactive Map Layer
3+
description: Visualize Data from Interactive Map Layer on Map.
4+
resources:
5+
- https://heremaps.github.io/maps-api-for-javascript-examples/test-credentials.js
6+
normalize_css: no
7+
dtd: html 5
8+
wrap: d
9+
panel_html: 0
10+
panel_js: 0
11+
panel_css: 0
12+
...

transit-mapsjs-iml/demo.html

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<html>
2+
<head>
3+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=yes">
4+
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
5+
<meta name="description" content="Visualize Data from Interactive Map Layer on Map">
6+
<title>Interactive Map Layer</title>
7+
<link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.1/mapsjs-ui.css" />
8+
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-core.js"></script>
9+
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-mapevents.js"></script>
10+
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-service.js"></script>
11+
<script type="text/javascript" src="https://js.api.here.com/v3/3.1/mapsjs-ui.js"></script>
12+
<link rel="stylesheet" type="text/css" href="../template.css" />
13+
<link rel="stylesheet" type="text/css" href="demo.css" />
14+
</head>
15+
<body>
16+
<div class="page-header">
17+
<h1>Interactive Map Layer</h1>
18+
<p>Visualize Data from Interactive Map Layer on Map</p>
19+
</div>
20+
<p>This examples adds dashed lines showing the 2030 <b>Washington D.C.</b> Proposed Transit.</p>
21+
<div id="map"></div>
22+
<h3>Code</h3>
23+
<p>
24+
The example uses <code>H.service.iml.Service</code>
25+
class to fetch data from Interactive Map Layer, and visualizes the data with customized style.</p>
26+
<script type="text/javascript" src='demo.js'></script>
27+
</body>
28+
</html>

transit-mapsjs-iml/demo.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
function addIml(map) {
2+
// HERE platform stores data in catalogs. Define Here Resource Name (HRN) of the catalog
3+
const catalogHrn = 'hrn:here:data::olp-here:dh-showcase-dc-transit';
4+
// A catalog is a collection of layers that are managed as a single set. Define the layer that stores data
5+
const layerId = 'dc-transit';
6+
// Instantiate the IML service
7+
const service = platform.getIMLService();
8+
// Create a provider for the custom user defined data
9+
const imlProvider = new H.service.iml.Provider(service, catalogHrn, layerId);
10+
11+
// Get the style object
12+
const style = imlProvider.getStyle();
13+
// Query the sub-section of the style configuration
14+
const styleConfig = style.extractConfig(['iml']);
15+
16+
// Add dashes
17+
styleConfig.layers.iml.lines.draw.lines.dash = [1, 1];
18+
// Set line width per zoom level
19+
styleConfig.layers.iml.lines.draw.lines.width = [[5, 5000], [8, 800], [10, 200], [12, 160], [14, 60], [18, 20]];
20+
21+
// Merge the style configuration back
22+
style.mergeConfig(styleConfig);
23+
24+
// Add a tile layer to the map
25+
map.addLayer(new H.map.layer.TileLayer(imlProvider));
26+
}
27+
28+
/**
29+
* Boilerplate map initialization code starts below:
30+
*/
31+
32+
// Step 1: initialize communication with the platform
33+
// In your own code, replace apikey value with your own apikey
34+
const platform = new H.service.Platform({
35+
apikey: 'wuhhFoo3HHQ8Bxw68fCZe8iA_J9v4dBnRhSbkAlMup4'
36+
});
37+
const defaultLayers = platform.createDefaultLayers();
38+
39+
// Step 2: initialize a map
40+
const map = new H.Map(
41+
document.getElementById('map'),
42+
defaultLayers.vector.normal.map,
43+
{
44+
center: new H.geo.Point(38.90192, -76.97605),
45+
zoom: 12
46+
}
47+
);
48+
// Add a resize listener to make sure that the map occupies the whole container
49+
window.addEventListener('resize', () => map.getViewPort().resize());
50+
51+
// Step 3: make the map interactive
52+
// MapEvents enables the event system
53+
// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
54+
const behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
55+
56+
// Step 4: create the default UI component, for displaying bubbles
57+
const ui = H.ui.UI.createDefault(map, defaultLayers);
58+
59+
// Step 5: Main logic goes here
60+
addIml(map);

0 commit comments

Comments
 (0)