How to create a custom bookmark with two icons in gmap v3

0

I need to be able to have a marker with at least two different icons, one of which has to have a float indicator number inside it, it occurs to me to create two markers in the same position but one with an icon in .png with a margin, clearly this option is not the most optimal and would still have the question of how to enter the numerical value, any idea?

    
asked by Felipe Parra Soto 20.12.2016 в 14:32
source

1 answer

2

You can load the marker icon in a canvas, modify it and then export it as a URL to create your icon

var canvas = document.createElement('canvas');
var img = new Image();
var markerUrl;
var marker;
img.addEventListener("load", function() {
    if (canvas.getContext) {
        var ctx = canvas.getContext('2d');
        ctx.drawImage(img, 0, 0);
        ctx.fillText('1.5', 50, 50); // Esto añade el texto '1.5' en la
                                     // posición x: 50, y: 50 de la imagen.
    }
    markerUrl = canvas.toDataURL();  // Exportamos el canvas modificado como
                                     // una URL

    // Creamos el marker con la URL que acabamos de obtener
    marker = new google.maps.MarkerImage(markerUrl, 
                 new google.maps.Size(size.width, size.height));
}, false);

// En esta imagen cargamos la imagen original, esto hará que se dispare el
// evento load de
img.src='marker.png';   
    
answered by 20.12.2016 в 15:46