在文章中:
Getting Google Map MarkerClusterer Plus Icons In One Color
第二种解决方案(将嵌入式SVG用于群集标记)具有JavaScript功能:
getGoogleClusterInlineSvg(color)
允许传递颜色参数,例如
url: getGoogleClusterInlineSvg('blue')
为了动态生成带有SVG代码的标记。
是否有一种方法还可以传递特定标记(例如, “ 37”,以便数字变量也可以嵌入到SVG代码中(以允许设置字体系列和其他字体属性)?
例如
url: getGoogleClusterInlineSvg('blue', intNumberOfItemsClustered)
在功能上:
var textlabel = ‘<text x="50%" y="50%" text-anchor="middle" stroke="#51c5cf" stroke-width="2px" dy=".3em">
+ intNumberOfItemsClustered
+ ‘</text>’
var encoded = window.btoa('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="-100 -100 200 200"><defs><g id="a" transf...”
+ textlabel
+ “(rest of svg code ...)”