We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
GuidesMap KitJavaScriptDrawing on a MapCustom POI

Custom POI

You can add custom POIs to a map to identify locations such as stores and buildings, and provide location details with information windows. Text labels of custom POIs support collision and directional avoidance.

  1. A custom POI and its text label are treated as a whole to collide with other custom POIs and their text labels. When two custom POIs collide with each other, the POI with a higher priority will be shown and the POI with a lower priority will be hidden.
  2. The icon and text label of a custom POI can collide with icons and texts on the base map. When colliding with icons and texts on the base map, the icon and text label of a custom POI will be shown while those on the base map will be hidden.
  3. The text label of a custom POI supports directional avoidance. The avoidance directions include up, down, left, and right. You can set priorities for these directions, and select specific directions for displaying the text label (for example, select only up and down for displaying the text label). If the text label of a custom POI collides with another custom POI, the text label will be placed in the specified directions based on their priorities to avoid that POI. If the text label cannot be properly placed in any specified direction, the text label will be hidden.

Adding a Custom POI

Call HWMapJsSDK.HWCustomPoi(customPoiOptions) to add a custom POI.

Collapse
Word wrap
Dark theme
Copy code
  1. function initMap() {
  2. var mapOptions = {};
  3. mapOptions.center = {lng: 2.3506770476074217, lat: 48.93245374505838};
  4. mapOptions.zoom = 12;
  5. mapOptions.language = 'en';
  6. mapOptions.sourceType = 'vector';
  7. mapOptions.navigationControl = true;
  8. mapOptions.locationControl = true;
  9. mapOptions.rotateControl = true;
  10. mapOptions.zoomControl = true;
  11. mapOptions.zoomSlider = true;
  12. mapOptions.scaleControl = true;
  13. mapOptions.copyrightControl = true;
  14. map = new HWMapJsSDK.HWMap(document.getElementById('map'), mapOptions);
  15. // Add a custom POI (point 1).
  16. customPoi1 = new HWMapJsSDK.HWCustomPoi({
  17. map,
  18. icon: {
  19. anchor: 'center',
  20. scale: 1,
  21. opacity: 1,
  22. },
  23. label: {
  24. color: '#333',
  25. fontSize: '36px',
  26. text: 'point 1',
  27. offsetX: 0,
  28. offsetY: 0,
  29. },
  30. position: {lat: 49, lng: 2.35},
  31. zIndex: 1,
  32. collisionEnabled: true,
  33. variableLabelAnchor: ['top','bottom','left', 'right'],
  34. });
  35. // Add a custom POI (point 2).
  36. customPoi2 = new HWMapJsSDK.HWCustomPoi({
  37. map,
  38. icon: {
  39. anchor: 'bottom',
  40. scale: 1,
  41. opacity: 1,
  42. },
  43. label: {
  44. color: '#333',
  45. fontSize: '36px',
  46. text: 'point 2',
  47. offsetX: 0,
  48. offsetY: 0,
  49. },
  50. position: {lat: 48.5, lng: 2.35},
  51. zIndex: 1,
  52. collisionEnabled: true,
  53. variableLabelAnchor: ['top','bottom','left', 'right'],
  54. });
  55. }

The figure below shows the custom POI text label collision effect.

Deleting a Custom POI

To delete a custom POI from a map, call the setMap() method and pass null as a parameter of the method.

Collapse
Word wrap
Dark theme
Copy code
  1. customPoi.setMap(null);

Configuring a Listener for Custom POI Events

Call the addListener(type, callback) or removeListener(type, callback) methods of HWCustomPoi to add or delete the listener for the click event.

Collapse
Word wrap
Dark theme
Copy code
  1. function handleListener(e) {
  2. console.log(e);
  3. }
  4. // Add a listener for the client event.
  5. customPoi.addListener('click', handleListener);
  6. // Delete the listener for the click event.
  7. customPoi.removeListener('click', handleListener);
Search in Guides
Enter a keyword.