【问题标题】:MarkerCluster V3 stopped working properlyMarkerCluster V3 停止正常工作
【发布时间】:2016-09-07 21:05:06
【问题描述】:

我正在使用来自 github 的 MarkerCluster_compiled.js。但是,虽然逻辑有效,但它的图形从昨天开始就失败了。

问题似乎是由“https://google-maps-utility-library-v3.googlecode.com/svn”返回404引起的,并且所有集群标记图像都依赖于这个url。 (这个 google map v3 svn url 还在 google 的公共域中)

在我看来,这个特殊的“404”的影响并非微不足道,因为我看到人们的直播网站受到了影响。我很惊讶这个问题可能发生在谷歌身上。

例如: github.io 上的marker-clusterer 的advanced_example 不再起作用(由于我的声誉低,我无法发布链接)。

期待看到 Google 解决此问题或提供任何其他建议。

【问题讨论】:

标签: google-maps markerclusterer


【解决方案1】:

就像不久前的Google moved the source over to GitHub,新的GitHub version 可以通过使用以下脚本url 从RawGit 访问:

https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/src/markerclusterer.js

您还需要在实例化 MarkerClusterer 以从 GitHub 访问图像时指定 imagePath 选项:

var mc = new MarkerClusterer(map, markers, { 
    imagePath: 'https://cdn.rawgit.com/googlemaps/js-marker-clusterer/gh-pages/images/m' 
});

以下较早的 SO 帖子包含有关集群图像的 imagePath 引用的更多详细信息:

Google maps not working in https://

虽然上述网址(带有 cdn 前缀)有 no traffic limits or throttling and the files are served via a super fast global CDN,但请记住 RawGit is a free hosting service and offers no uptime or support guarantees

以下 SO 答案中对此进行了更详细的介绍:

Link and execute external JavaScript file hosted on GitHub

这篇文章还介绍了,如果您要链接到 GitHub 上的文件,在生产中您应该考虑定位特定的发布标签,以确保您获得脚本的特定发布版本。

但是,由于 js-marker-clusterer 存储库的保管人尚未创建任何版本,因此目前不可能。

因此,您应该认真考虑下载库及其资源并将其直接包含在您的项目中以用于生产目的。

【讨论】:

  • 这个答案会起作用,但它不是正确的解决方案,因为链接到 github(或 github 的镜像)是有风险的,因为链接可能随时更改(再次!)。
【解决方案2】:

从 Github https://github.com/googlemaps/js-marker-clusterer/tree/gh-pages/images 下载 markerclusterer.js 和图片 m1.pngm5.png 并保存在本地,如下所示:

index.html
markerclusterer.js
images/
- m1.png
- m2.png
- m3.png
- m4.png
- m5.png

然后在使用markerclusterer.js时,将imagePath设置为ìmages/m,如下所示:

var mc = new MarkerClusterer(map, makers, {imagePath: 'images/m'});

为什么你应该像上面描述的那样使用它:

  • GitHub 不是 CDN。
  • 路径可能会发生变化,就像以前一样。
  • 它适用于 http 和 https!
  • 您不必依赖外部资源来维持服务。

【讨论】:

    【解决方案3】:
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多