【问题标题】:Circle marker with three different border colors in Google Maps APIGoogle Maps API 中具有三种不同边框颜色的圆形标记
【发布时间】:2016-06-10 19:13:46
【问题描述】:

我有一个带有一种边框颜色的圆圈的 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>

看起来像这样:

我应该如何将 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>

必填

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

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

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

【问题讨论】:

  • 给它一个GO

标签: javascript css google-maps-markers


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    你可以使用画布,像这样可以做到:

    <canvas id="myCanvas" width="578" height="250"></canvas>
    <script>
      var canvas = document.getElementById('myCanvas');
      var context = canvas.getContext('2d');
      var context2 = canvas.getContext('2d');
      var context3 = canvas.getContext('2d');
      var x = canvas.width / 2;
      var y = canvas.height / 2;
      var radius = 75;
      var startAngle = 1.5 * Math.PI;
      var endAngle = 0.15 * Math.PI;
      var counterClockwise = false;
    
      //1st arc
      context.beginPath();
      context.arc(x, y, radius, startAngle, endAngle, counterClockwise);
      context.lineWidth = 10;
    
      // line color
      context.strokeStyle = '#FFA325';
      context.stroke();
    
      //second arc
      startAngle=endAngle;
      endAngle=0.85 * Math.PI;
      context.beginPath();
      context.arc(x, y, radius, startAngle, endAngle, counterClockwise);
    
    
      // line color
      context.strokeStyle = '#FFBEC9';
      context.stroke();
    
      //third arc
      startAngle=endAngle;
      endAngle=1.5 * Math.PI;
      context.beginPath();
      context.arc(x, y, radius, startAngle, endAngle, counterClockwise);
    
    
      // line color
      context.strokeStyle = '#007F1B';
      context.stroke();
    </script>
    

    希望对您有所帮助,HERE 您可以找到指向代码笔的链接,谢谢

    【讨论】:

      猜你喜欢
      • 2016-09-09
      • 2019-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-26
      • 2018-11-14
      相关资源
      最近更新 更多