Multi-colored Google Map SVG Symbols

荒凉一梦 提交于 2019-11-29 13:21:00

I just did the same thing and I think you have to draw two markers with essentially identical data, but with the path and in this case fillColor properties changed:

var baseSvg = {
        x1 : "m 0,0 l45,0 l 190,225 l -45,0 l -190,-225 z",
        x2 : "m 225,0 l -45,0 l -190,225 l 45,0 l 190,-225 z"                
    },
    baseIcon = {
        fillOpacity: 1,
        scale: .2,
        strokeColor: "black",
        strokeWeight: 0,
        rotation: 15
    },
    markerPos = new google.maps.LatLng(somelat, somelng),
    // psuedo code for cloning an object since that 
    // is out of scope for this question
    greenIcon = Object.clone(baseIcon),
    redIcon = Object.clone(baseIcon);

greenIcon.path = baseSvg.x1;
greenIcon.fillColor = "#0f0";
redIcon.path = baseSvg.x2;
redIcon.fillColor = "#f00";

var marker1 = new google.maps.Marker({
    position: markerPos,
    map: map,
    icon: greenIcon
});
var marker2 = new google.maps.Marker({
    position: markerPos, 
    map: map,
    icon: redIcon
});

obviously not optimized js, but you get the idea.

When it comes to opacity, strokeOpacity is your guy. Check the maps.Symbol class for more information on symbol properties.

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