如何在带有视网膜图像的谷歌地图上使用Marker Clusterer Plus

 惯性hold不住 发布于 2023-02-04 16:27

我正在使用Marker Clusterer Plus在谷歌地图上分组标记,但enableRetinaIcons选项似乎不起作用.

// Custom style to alter the default font color (style is always the same).
var styles = [
    {
        url: 'PATH_TO_MY_66x66px_IMAGE',
        textColor: '#ddddd',
        textSize: 18,
        width: 33,
        height: 33,
    }
];

// Calculator function to determine which style to use (I only have one)
var calculator = function (markers, iconstyles){
    return{ text: markers.length.toString(), index:1};
};

// Set Options
var clusterOptions = {
    title: 'Cluster Title',
    enableRetinaIcons: true,
    styles: styles,
    calculator: calculator
}

// Add to map
new MarkerClusterer(this.map, this.markers, clusterOptions);

enableRetinaIcons选项似乎不起作用,图像显示两倍大小.

将宽度设置为66x66px也无济于事.

有人知道如何正确配置吗?

1 个回答
  • 这显然是Marker Clusterer Plus中的错误.代码中他们实际使用此选项的唯一位置是:

    img = "<img src='" + this.url_ + "'  + spriteV + "px; left: " + spriteH + "px; ";
    if (!this.cluster_.getMarkerClusterer().enableRetinaIcons_) {
      img += "clip: rect(" + (-1 * spriteV) + "px, " + ((-1 * spriteH) + this.width_) + "px, " +
          ((-1 * spriteV) + this.height_) + "px, " + (-1 * spriteH) + "px);";
    }
    img += "'>";
    

    所以他们实际上只禁用精灵图标的剪辑,但它们实际上并没有运行所需的视网膜动作.图标的HTML树实际上如下所示:

    在此输入图像描述

    所以你可以看到图标周围的div有适当的尺寸设置(33x33),但是图像(蓝色代码)没有设置任何尺寸.

    我试图通过修补标记聚类器库来解决问题,只需添加一个else分支:

    img = "<img src='" + this.url_ + "'  + spriteV + "px; left: " + spriteH + "px; ";
    if (!this.cluster_.getMarkerClusterer().enableRetinaIcons_) {
      img += "clip: rect(" + (-1 * spriteV) + "px, " + ((-1 * spriteH) + this.width_) + "px, " +
          ((-1 * spriteV) + this.height_) + "px, " + (-1 * spriteH) + "px);";
    }
    else {
        img += "width: " + this.width_ + "px;" + "height: " + this.height_ + "px;";
    }
    img += "'>";
    

    它似乎工作:

    完成修补的库@pastebin

    测试示例 - http://jsfiddle.net/Rt28T/2/

    您可以报告错误并将其添加为建议的补丁:-)

    2023-02-04 16:29 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有