Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 动态CSS样式在google地图标记中的应用_Javascript_Css_Angularjs_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 动态CSS样式在google地图标记中的应用

Javascript 动态CSS样式在google地图标记中的应用,javascript,css,angularjs,google-maps,google-maps-api-3,Javascript,Css,Angularjs,Google Maps,Google Maps Api 3,我知道我们可以在angularJs中动态地将标签或图标图像或css类应用于google的marker,但我无法找出如何将动态css样式应用于marker。我必须在谷歌地图上动态生成标记,并对它们进行动态着色。我们能做到吗 我试过跟随,但似乎不起作用 var putMarker = function(lat,long,color) { var marker = new google.maps.Marker({ position: new

我知道我们可以在angularJs中动态地将标签图标图像css类应用于google的marker,但我无法找出如何将动态css样式应用于marker。我必须在谷歌地图上动态生成标记,并对它们进行动态着色。我们能做到吗

我试过跟随,但似乎不起作用

  var putMarker = function(lat,long,color) {              
      var marker = new google.maps.Marker({
        position: new google.maps.LatLng(lat,long),
        map: map,
        labelStyle: {backgroundColor:"#ff00ff", height:"5px", width:"5px", borderRadius:"50px"},
        icon: 'img/mapView.png',
        label: (markers.length + 1) + '',
        animation: google.maps.Animation.DROP,
        isDraggable: false
      });

      markers.push(marker);

      //extend the bounds to include each marker's position
      bounds.extend(marker.position);

      //now fit the map to the newly inclusive bounds
      map.fitBounds(bounds);
    }

MarkerImage去润滑,可以使用Icon类

var customSizeImage = {
  url: place.icon,
  size: new google.maps.Size(71, 71),
  origin: new google.maps.Point(0, 0),
  anchor: new google.maps.Point(17, 34),
  scaledSize: new google.maps.Size(25, 25)
};

var marker = new google.maps.Marker({
   position: {lat: lat, lng: lng},
   map: map,
   icon: customSizeImage
});

仅此而已。

如果要在标记上显示单个文本字符,可以使用标记标签。如果需要更大的自定义,可以定义要显示的图标,而不是默认的标记图像。定义图标涉及设置许多属性,这些属性确定标记的视觉行为

是出现在标记内部的单个文本字符。可以将标记标签指定为字符串或包含字符串和其他标签特性的MarkerLabel对象。在这两种情况下,标记上仅显示指定字符串的第一个字符

创建标记时,可以在MarkerOptions对象中指定标签特性。或者,可以在Marker对象上调用setLabel(),以在现有标记上设置标签

下面是一些示例代码:

// This example adds a marker to indicate the position of Bondi Beach in Sydney,
// Australia.
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: {lat: -33, lng: 151}
});

var image = 'https://developers.google.com/maps/documentation/javascript/examples/full/images/beachflag.png';
var beachMarker = new google.maps.Marker({
position: {lat: -33.890, lng: 151.274},
map: map,
icon: image
});
}

有关更多信息,请查看此项。

为什么不尝试为图标添加样式?您还可以使用MarkerImage类调整大小等。我如何为我的图标提供样式?任何解决方案。。什么是markerImage类?