gpt4 book ai didi

svg - 多色 Google map SVG 符号

转载 作者:行者123 更新时间:2023-12-03 03:36:02 26 4
gpt4 key购买 nike

Google map 标记可以采用复杂的 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?而且效果很好。

最佳答案

我刚刚做了同样的事情,我认为你必须绘制两个具有基本相同数据的标记,但 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,但你明白了。

关于svg - 多色 Google map SVG 符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14514274/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com