Google在icon-fillColor和strokeColor之间映射Marker图标填充 [英] Google maps Marker icon padding between icon-fillColor and strokeColor

查看:129
本文介绍了Google在icon-fillColor和strokeColor之间映射Marker图标填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个Google地图标记图标,并在icon-fillColor和外部StrokeColor之间填充空白.

I am trying to create a Google map marker icon with padding between the icon-fillColor and the outer StrokeColor.

我的标记代码:

marker = new google.maps.Marker({
id: i,
position: position,
label: {
    text: 'id',
    color: "white",
    fontWeight: 'bold',
    fontSize: '16px',
},
map: map,
title: "My Title",
icon: {
    path: google.maps.SymbolPath.CIRCLE,
    scale: 15,
    fillColor: "#4A86FE",
    fillOpacity: 1.0,
    strokeWeight: 6,
    strokeOpacity: 0.8,
    strokeColor:"red",
    rotation: 30
},
animation: google.maps.Animation.DROP,});

我当前的输出:如果您可以看到内部蓝色圆圈和外部红色彼此接触.我正在尝试在内部和外部之间编码白色.检查我的预期输出.

My Current OutPut: If you can see the Inner Blue circle and The Outer red are touching each other. I'm trying to code a white color between inner and outer. Check my expected output.

我要实现的目标如下:

推荐答案

类似的事情(使用两个重叠的标记)应该可以工作,您可以添加其他参数(或创建"options"对象)来定义各种颜色件:

Something like this (using two overlapping markers) should work, you can add additional parameters (or create an "options" object) to define the colors of the various pieces:

function makeComplexIcon(map, latLng, fillColor, stripeColor, outsideColor, title, id, label) {
  var bottom = new google.maps.Marker({
    zIndex: 10, // bottom
    id: id,
    position: latLng,
    map: map,
    title: title,
    icon: {
      path: google.maps.SymbolPath.CIRCLE,
      scale: 15,
      fillColor: fillColor,
      fillOpacity: 1.0,
      strokeWeight: 6,
      strokeOpacity: 0.8,
      strokeColor: outsideColor,
      rotation: 30
    },
  });
  var top = new google.maps.Marker({
    zIndex: 15, // top
    id: id,
    position: latLng,
    label: label,
    map: map,
    title: title,
    icon: {
      path: google.maps.SymbolPath.CIRCLE,
      scale: 15,
      fillColor: fillColor,
      fillOpacity: 1.0,
      strokeWeight: 2,
      strokeOpacity: 0.8,
      strokeColor: stripeColor,
      rotation: 30
    },
  });

概念提琴证明

代码段:

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 4,
    center: {
      lat: -25.363882,
      lng: 131.044922
    }
  });

  var position = map.getCenter(),
    i = 10;
  makeComplexIcon(map, position, "#4A86FE", "white", "red", "My Title", i, {
    text: 'id',
    color: "white",
    fontWeight: 'bold',
    fontSize: '16px',
  });
  makeComplexIcon(map, {
    lat: -27.6728168,
    lng: 121.6283098
  }, "green", "yellow", "orange", "W. Australia", 12, {
    text: 'id1',
    color: "blue",
    fontWeight: 'bold',
    fontSize: '16px',
  })
  makeComplexIcon(map, {
    lat: -30.0,
    lng: 136.2
  }, "black", "white", "black", "S. Australia", 14, {
    text: 'id2',
    color: "red",
    fontWeight: 'bold',
    fontSize: '16px',
  })
}

function makeComplexIcon(map, latLng, fillColor, stripeColor, outsideColor, title, id, label) {
  var marker = new google.maps.Marker({
    zIndex: 10, // bottom
    id: id,
    position: latLng,
    map: map,
    title: title,
    icon: {
      path: google.maps.SymbolPath.CIRCLE,
      scale: 15,
      fillColor: fillColor,
      fillOpacity: 1.0,
      strokeWeight: 6,
      strokeOpacity: 0.8,
      strokeColor: outsideColor,
      rotation: 30
    },
  });
  var marker = new google.maps.Marker({
    zIndex: 15, // top
    id: id,
    position: latLng,
    label: label,
    map: map,
    title: title,
    icon: {
      path: google.maps.SymbolPath.CIRCLE,
      scale: 15,
      fillColor: fillColor,
      fillOpacity: 1.0,
      strokeWeight: 2,
      strokeOpacity: 0.8,
      strokeColor: stripeColor,
      rotation: 30
    },
  });
}

html,
body,
#map {
  height: 100%;
  margin: 0;
  padding: 0;
}

<div id="map"></div>
<!-- Replace the value of the key parameter with your own API key. -->
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk&callback=initMap"></script>

这篇关于Google在icon-fillColor和strokeColor之间映射Marker图标填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆