在Google Maps API中使用三种不同边框颜色的圆圈标记

时间:2016-05-13 10:44:53

标签: javascript css google-maps-markers

我将这个CSS用于带有一种边框颜色的圆圈:

m = new MarkerWithLabel({
  position: pos,
  map: map,
  labelContent: txt,
  labelAnchor: new google.maps.Point(18, 18),
  labelClass: "circle",
  icon: "/i/t.png"
});
.circle {
  border: 6px solid #ffd511;
  border-radius: 30px;
  -moz-border-radius: 30px;
  -webkit-border-radius: 30px;
  -khtml-border-radius: 30px;
  width: 30px;
  height: 18px;
  line-height: 20px;
  padding: 12px 6px;
  text-align: center;
}
<div class="circle">17</div>

看起来像这样:

circle with one border color

如何将CSS更改为三种边框颜色 - 与时钟一样:

  • 从0到4色#1
  • 从4到8色#2
  • 从8到12颜色#3

与上一个问题的answer一样:

svg{width:30%;height:auto;}
<svg viewbox="0 0 10 10">
  <defs>
    <circle id="circle" cx="5" cy="5" r="4" stroke-width="0.5" fill="transparent" />
  </defs>
  <use xlink:href="#circle" stroke="pink" stroke-dasharray="0,2.09,8.38,30" />
  <use xlink:href="#circle" stroke="green" stroke-dasharray="0,10.47,8.38,30" />
  <use xlink:href="#circle" stroke="orange" stroke-dasharray="2.09,16.75,6.3" />
</svg>

必需

enter image description here

圆圈元素是Google Maps API v3中显示的标记,因此我无法使用SVG。

另一种解决方案是使用图像:

.circle {
  background: url('circle.png') no-repeat;
  width: 58px;
  height: 58px;
  line-height: 20px;
  text-align: center;
}

2 个答案:

答案 0 :(得分:0)

你可以使用画布,像这样的东西会这样做:

root,aNode,bNode,newNode

希望有所帮助,HERE你可以找到一个指向codepen的链接,谢谢

答案 1 :(得分:0)

看起来有解决方案可以使用CSS作为Google Maps API的Marker。

所以我设法创建了一个图像,并将其用作标记类.circle的背景:

.circle {
  background: url('circle.png') no-repeat;
  width: 58px;
  height: 58px;
  line-height: 20px;
  text-align: center;
}

three colors border