Jean Carlo Codogno
Jean Carlo Codogno

Reputation: 78

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')

Upvotes: 0

Views: 1115

Answers (1)

Jean Carlo Codogno
Jean Carlo Codogno

Reputation: 78

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;
}

Upvotes: 2

Related Questions