Text Within Polyline Google Maps V3

前端 未结 3 948
温柔的废话
温柔的废话 2021-01-07 00:26

I need to be able to put text within my polyline like the embedded Google Maps does as you can see from the below screenshot...

3条回答
  •  情深已故
    2021-01-07 01:07

    I commented yesterday asking if there might be any current way to add text within polylines. I know this question has been resolved, but the last activity I can see was in 2014. I came across this library in github https://github.com/googlemaps/js-map-label

    It allows a user to overlay text on the map with (see also examples folder):

        var mapLabel = new MapLabel({
            text: 'Route name',
            position: pointCoordinate,
            map: map,
            fontSize: 12,
            align: 'left',
        });
    

    Note, their source code within the "onAdd" method applies the pane to the map level, meaning the text would be underneath polylines. So, instead, I added it to the floatShadow pane by:

    panes.floatShadow.appendChild(canvas);
    

    Instead of:

    panes.mapPane.appendChild(canvas);
    

    I was able to make my map look like:

提交回复
热议问题