Search code examples
javascripthere-api

How to do labeled markers in here maps with JavaScript API?


I'm trying to create labeled markers in the here maps, some like google maps, but I didn't find how. Something like code bellow.

marker.setLabel('label')


Solution

  • I didn't find in the documentation a easy way to do this. I solved this problem using the DomMarker. The solution is below.

    function createMarker(point, ico, label = ''){
    
        var html = document.createElement('div'), 
        divIcon = document.createElement('div'), 
        divText = document.createElement('div'),
        imgIco = document.createElement('img');
        imgIco.setAttribute('src', ico);
    
        divIcon.appendChild(imgIco);
        divText.innerHTML = label;
        html.appendChild(divIcon);
        html.appendChild(divText);
    
        var domIcon = new H.map.DomIcon(html);
        var marker = new H.map.DomMarker(point, {
            icon: domIcon
        });
        return marker;
    }