Javascript 样式 MarkerClusterer 图标?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7834284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 03:46:29  来源:igfitidea点击:

Styling MarkerClusterer Icons?

javascriptgoogle-maps-api-3markerclusterer

提问by Louise McComiskey

I am using the MarkerCluster.js to create clustering in my google maps api. The clusters work how I want them however I want to style differently than yellow, blue and red circles. I was trying to use the MarkerStyleOptions and it says you have an array of styles with the smallest cluster icon first and the biggest last. I tried to create this below but I am getting really confused about what syntax to use and can't find any good examples.

我正在使用 MarkerCluster.js 在我的 google maps api 中创建聚类。集群按照我想要的方式工作,但是我想要与黄色、蓝色和红色圆圈不同的样式。我试图使用 MarkerStyleOptions ,它说你有一个样式数组,首先是最小的集群图标,最后是最大的。我试图在下面创建它,但我对使用什么语法感到非常困惑,并且找不到任何好的例子。

var clusterStyles = [
    [opt_textColor: 'white'],
    [opt_textColor: 'white'],
    [opt_textColor: 'white']
];

var mcOptions = {
    gridSize: 50,
    styles: clusterStyles,
    maxZoom: 15
};
var markerclusterer = new MarkerClusterer(map, cluster, mcOptions);

回答by duncan

What you need to do is use the url to specify which images to use instead of the blue/yellow/red images currently being used. And probably a good idea to include the height and width options too.

您需要做的是使用 url 来指定要使用的图像,而不是当前使用的蓝色/黄色/红色图像。也可能包含高度和宽度选项是个好主意。

var clusterStyles = [
  {
    textColor: 'white',
    url: 'path/to/smallclusterimage.png',
    height: 50,
    width: 50
  },
 {
    textColor: 'white',
    url: 'path/to/mediumclusterimage.png',
    height: 50,
    width: 50
  },
 {
    textColor: 'white',
    url: 'path/to/largeclusterimage.png',
    height: 50,
    width: 50
  }
];

回答by Yazan Rawashdeh

It's never too late to post a rather helpful answer, so additionally you can look through the whole MarkerClusterer Documentation for IconStyle

发布一个相当有用的答案永远不会太晚,因此您还可以查看IconStyle的整个MarkerClusterer 文档

UPDATE

更新

There's also google maps v3 utility on githubas stated by ehcanadian

如ehcanadian所述,github上还有谷歌地图v3实用程序