1- // Define a valid apikey for Interactive Map Layer
2- const apikey = "wuhhFoo3HHQ8Bxw68fCZe8iA_J9v4dBnRhSbkAlMup4" ;
3- // HERE platform stores data in catalogs, define Here Resource Name (HRN) of the catalog
4- const catalogHrn = "hrn:here:data::olp-here:dh-showcase-dc-transit" ;
5- // A catalog is a collection of layers that managed as a single set, define the layer that stores data
6- const layerId = "dc-transit" ;
7-
8- function overlay ( map ) {
9- // Get access to Interactive Map Layer
10- const service = platform . getXYZService ( {
11- // authenticate with apiKey instead of token
12- toBypassToken : true ,
13- // host of Interactive Map Layer
14- host : 'interactive.data.api.platform.here.com' ,
15- // path to endpoint of getting features in tile
16- path : 'interactive/v1/catalogs/' + catalogHrn + '/layers'
17- } ) ;
18-
19- // create a provider for the custom user defined data
20- const imlProvider = new H . service . xyz . Provider ( service , layerId ) ;
21-
22- // get the style object for interactive map layer
23- var style = imlProvider . getStyle ( ) ;
24- // query the sub-section of the style configuration
25- var styleConfig = style . extractConfig ( [ 'xyz' ] ) ;
26-
27- // set layer with Here Resource Name (HRN)
28- styleConfig . layers . xyz . data . layer = catalogHrn + ':' + layerId ;
29- // change the color, for the description of the style section
30- // see the Developer's guide
31- styleConfig . layers . xyz . lines . draw . lines . color = '#0258AE' ;
32- styleConfig . layers . xyz . lines . draw . lines . dash = [ 1 , 1 ] ;
33- styleConfig . layers . xyz . lines . draw . lines . width = [ [ 5 , 5000 ] , [ 8 , 800 ] , [ 10 , 200 ] , [ 12 , 160 ] , [ 14 , 60 ] , [ 18 , 20 ] ]
34-
35- // merge the configuration back to the base layer configuration
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
3622 style . mergeConfig ( styleConfig ) ;
3723
38- const imlLayer = new H . map . layer . TileLayer ( imlProvider ) ;
39- // add a layer to the map
40- map . addLayer ( imlLayer ) ;
24+ // Add a tile layer to the map
25+ map . addLayer ( new H . map . layer . TileLayer ( imlProvider ) ) ;
4126}
4227
4328/**
4429 * Boilerplate map initialization code starts below:
4530 */
4631
4732// Step 1: initialize communication with the platform
48- // In your own code, replace variable apikey with your own apikey
49- var platform = new H . service . Platform ( {
50- " apikey" : apikey
33+ // In your own code, replace apikey value with your own apikey
34+ const platform = new H . service . Platform ( {
35+ apikey : 'wuhhFoo3HHQ8Bxw68fCZe8iA_J9v4dBnRhSbkAlMup4'
5136} ) ;
52- var defaultLayers = platform . createDefaultLayers ( ) ;
37+ const defaultLayers = platform . createDefaultLayers ( ) ;
5338
5439// Step 2: initialize a map
55- var map = new H . Map (
56- document . getElementById ( 'map' ) ,
57- defaultLayers . vector . normal . map ,
40+ const map = new H . Map (
41+ document . getElementById ( 'map' ) ,
42+ defaultLayers . vector . normal . map ,
5843 {
5944 center : new H . geo . Point ( 38.90192 , - 76.97605 ) ,
6045 zoom : 12
6146 }
6247) ;
63- // add a resize listener to make sure that the map occupies the whole container
48+ // Add a resize listener to make sure that the map occupies the whole container
6449window . addEventListener ( 'resize' , ( ) => map . getViewPort ( ) . resize ( ) ) ;
6550
6651// Step 3: make the map interactive
6752// MapEvents enables the event system
6853// Behavior implements default interactions for pan/zoom (also on mobile touch environments)
69- var behavior = new H . mapevents . Behavior ( new H . mapevents . MapEvents ( map ) ) ;
54+ const behavior = new H . mapevents . Behavior ( new H . mapevents . MapEvents ( map ) ) ;
7055
7156// Step 4: create the default UI component, for displaying bubbles
72- var ui = H . ui . UI . createDefault ( map , defaultLayers ) ;
57+ const ui = H . ui . UI . createDefault ( map , defaultLayers ) ;
7358
7459// Step 5: Main logic goes here
75- overlay ( map ) ;
60+ addIml ( map ) ;
0 commit comments