Skip to content

Commit bd6d4e0

Browse files
committed
Fixed Indoor interaction demo to use the new flag in Venue#setHighlightedGeometries
1 parent 46050ad commit bd6d4e0

File tree

1 file changed

+37
-39
lines changed

1 file changed

+37
-39
lines changed

indoor-map-ui-interaction/demo.js

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Example for Indoor Map for JSMapsApi.
33
*/
44

5-
// Replace with your HERE platform app api key
5+
// Replace with your HERE platform app api key
66
const yourApikey = 'ZKBUeAgkzH4JWhg93AA7cIE_kZotbMGhVI0_UYC0COY';
77

88
// Replace with your indoor map platform collection hrn
@@ -91,10 +91,10 @@ addVenueToMap(map);
9191

9292
/**
9393
* 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
9898
*/
9999
function highlightGeometries (venue, geometryForSearch) {
100100
const searchGeometries = venue.search(geometryForSearch);
@@ -103,54 +103,52 @@ addVenueToMap(map);
103103
outlineColor: '#99cc00',
104104
outlineWidth: 0.2,
105105
};
106-
106+
107107
if (searchGeometries.length > 0) {
108108
venuesProvider.activeVenue.setHighlightedGeometries(true, searchGeometries, highlightStyle);
109-
// venuesProvider.activeVenue.setHighlightedGeometries(false, searchGeometries, highlightStyle); // If you need to remove the highlighting
110109
}
111110
}
112111

113112
/**
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
118116
*/
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);
125136
}
126137

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);
133140

134-
ui.addBubble(infoBubble);
141+
// Update its content
142+
infoBubble.getContentElement().innerHTML = popUpContent(geometry)
135143

136-
// Then set a new geometry at info bubble
144+
// Set a new geometry in the data payload of the InfoBubble
137145
infoBubble.setData(geometry);
138146

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);
151149

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();
154152
};
155153

156154
/**

0 commit comments

Comments
 (0)