2
2
* Example for Indoor Map for JSMapsApi.
3
3
*/
4
4
5
- // Replace with your HERE platform app api key
5
+ // Replace with your HERE platform app api key
6
6
const yourApikey = 'ZKBUeAgkzH4JWhg93AA7cIE_kZotbMGhVI0_UYC0COY' ;
7
7
8
8
// Replace with your indoor map platform collection hrn
@@ -91,10 +91,10 @@ addVenueToMap(map);
91
91
92
92
/**
93
93
* Function to search and highlight geometries
94
- *
95
- * @param {H.venues.Venue } venue
96
- * @param {H.venues.Provider } venuesProvider
97
- * @param {string } geometryForSearch - geometry name to be searched
94
+ *
95
+ * @param {H.venues.Venue } venue
96
+ * @param {H.venues.Provider } venuesProvider
97
+ * @param {string } geometryForSearch The identifier of the geometry to be searched
98
98
*/
99
99
function highlightGeometries ( venue , geometryForSearch ) {
100
100
const searchGeometries = venue . search ( geometryForSearch ) ;
@@ -103,54 +103,52 @@ addVenueToMap(map);
103
103
outlineColor : '#99cc00' ,
104
104
outlineWidth : 0.2 ,
105
105
} ;
106
-
106
+
107
107
if ( searchGeometries . length > 0 ) {
108
108
venuesProvider . activeVenue . setHighlightedGeometries ( true , searchGeometries , highlightStyle ) ;
109
- // venuesProvider.activeVenue.setHighlightedGeometries(false, searchGeometries, highlightStyle); // If you need to remove the highlighting
110
109
}
111
110
}
112
111
113
112
/**
114
- * For a given location open an information popup and highlight geometry.
115
- * @param {mapsjs.geo.Point } position tapped on map
116
- * @param {H.venues.Geometry } geometry which was tapped
117
- * @param {boolean } highlight geometry or not
113
+ * For a given location open an information popup and highlight the geometry
114
+ * @param {mapsjs.geo.Point } position The position where to show the InfoBubble
115
+ * @param {H.venues.Geometry } geometry The instance of Geometry to be highlighted
118
116
*/
119
- const onGeometryTap = ( position , geometry , highlight = true ) => {
120
- // Hide existing infoBubble and remove existing highlight
121
- if ( infoBubble ) {
122
- const currentGeometry = infoBubble . getData ( ) ;
123
- if ( currentGeometry ) venuesProvider . getActiveVenue ( ) . setHighlightedGeometries ( false , [ currentGeometry ] ) ;
124
- ui . removeBubble ( infoBubble ) ;
117
+ const onGeometryTap = ( position , geometry ) => {
118
+ const popUpContent = ( geometry ) => `${ geometry . getIdentifier ( ) } : ${ geometry . getName ( ) } <br>` ;
119
+
120
+ if ( ! infoBubble ) {
121
+ infoBubble = new H . ui . InfoBubble ( position , {
122
+ onStateChange : ( evt ) => {
123
+ if ( evt . target . getState ( ) === 'closed' ) {
124
+ // On closing the popup, remove highlight from the geometry
125
+ venuesProvider . getActiveVenue ( ) . setHighlightedGeometries ( false , [ evt . target . getData ( ) ] ) ;
126
+ }
127
+ }
128
+ } ) ;
129
+
130
+ // Prepare the content of the InfoBubble
131
+ const domElement = document . createElement ( 'div' ) ;
132
+ domElement . innerHTML = popUpContent ( geometry ) ;
133
+ domElement . setAttribute ( 'style' , 'width: max-content;' ) ;
134
+
135
+ ui . addBubble ( infoBubble ) ;
125
136
}
126
137
127
- infoBubble = new H . ui . InfoBubble ( position , {
128
- onStateChange : ( ) => {
129
- // On closing the popup, removing highlight from the geometry
130
- venuesProvider . getActiveVenue ( ) . setHighlightedGeometries ( false , [ infoBubble . getData ( ) ] ) ;
131
- } ,
132
- } ) ;
138
+ // Set the new position of the InfoBubble
139
+ infoBubble . setPosition ( position ) ;
133
140
134
- ui . addBubble ( infoBubble ) ;
141
+ // Update its content
142
+ infoBubble . getContentElement ( ) . innerHTML = popUpContent ( geometry )
135
143
136
- // Then set a new geometry at info bubble
144
+ // Set a new geometry in the data payload of the InfoBubble
137
145
infoBubble . setData ( geometry ) ;
138
146
139
- if ( highlight ) {
140
- venuesProvider . getActiveVenue ( ) . setHighlightedGeometries ( true , [ infoBubble . getData ( ) ] ) ;
141
- }
142
-
143
- const popUpContent = `${ geometry . getId ( ) } : ${ geometry . getName ( ) } <br>` ;
144
-
145
- const domElement = document . createElement ( 'div' ) ;
146
- domElement . innerHTML = popUpContent ;
147
- domElement . setAttribute ( 'style' , 'width: max-content;' ) ;
148
-
149
- infoBubble . setPosition ( position ) ;
150
- infoBubble . setContent ( domElement ) ;
147
+ // Highlight the geometry
148
+ venuesProvider . getActiveVenue ( ) . setHighlightedGeometries ( true , [ geometry ] , undefined , true ) ;
151
149
152
- // if content is available, open the infoBubble
153
- return popUpContent . length > 0 ? infoBubble . open ( ) : infoBubble . close ( ) ;
150
+ // Open the InfoBubble if geometry is not undefined
151
+ return geometry ? infoBubble . open ( ) : infoBubble . close ( ) ;
154
152
} ;
155
153
156
154
/**
0 commit comments