Google地图标记可以将复杂的svg路径作为其图标,如:
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"
};
var baseIcon = {
path: "M0,0 " + baseSvg["x1"] + baseSvg["x2"],
fillColor: "#000000",
fillOpacity: 1,
scale: .2,
strokeColor: "black",
strokeWeight: 0,
rotation: 15
};
然后送入标记:
var marker = new google.maps.Marker({
position: new google.maps.LatLng(somelat, somelng),
icon: baseIcon
});
一切都好。但它只绘制一种颜色(本例中为黑色)。 那么,它们只能使用单一颜色还是有多种颜色的符号?使用示例代码,x1为红色,x2为绿色。
请注意,这个构造是从这里借来的:How do I indicate transparency in an SVG path in Google Maps API v3?并且它运行良好。
答案 0 :(得分:1)
我刚刚做了同样的事情,我认为你必须绘制两个基本相同数据的标记,但是path
并且在这种情况下fillColor
属性已更改:
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
});
显然没有优化js,但你明白了。
答案 1 :(得分:0)
说到不透明度,strokeOpacity
就是你的家伙。有关符号属性的详细信息,请查看maps.Symbol class。