how to change polyline color by clicking on it?

女生的网名这么多〃 提交于 2019-12-25 02:22:10

问题


i am using drawnig tools provided by google maps api, and i want after drawnig the polyline, to change its color by clicking on it this is my code

function initialize() {
    var mapOptions = {
        center: new google.maps.LatLng(-34.397, 150.644),
        zoom: 8
    };

    var map = new google.maps.Map(document.getElementById('map-canvas'),mapOptions);

    var drawingManager = new google.maps.drawing.DrawingManager({
        drawingMode: google.maps.drawing.OverlayType.MARKER,
        drawingControl: true,
        drawingControlOptions: {
            position: google.maps.ControlPosition.TOP_CENTER,
            drawingModes: [
                google.maps.drawing.OverlayType.MARKER,
                google.maps.drawing.OverlayType.POLYLINE
            ]
        },
        markerOptions: {
            icon: 'images/beachflag.png'
        },
        circleOptions: {
            fillColor: '#ffff00',
            fillOpacity: 1,
            strokeWeight: 5,
            clickable: true,
            zIndex: 1
        }
    });

    drawingManager.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);

回答1:


You have to add listener for event polylinecomplete inside initialize() function and define click event listener, for example:

google.maps.event.addListener(drawingManager, 'polylinecomplete', function(polyline) {
    google.maps.event.addListener(polyline, 'click', function() {
        polyline.setOptions({strokeColor: '#FF0000'});
    });
});


来源:https://stackoverflow.com/questions/23581669/how-to-change-polyline-color-by-clicking-on-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!