【问题标题】:Google maps custom overlay with wrong width谷歌地图自定义覆盖宽度错误
【发布时间】:2014-11-14 07:08:56
【问题描述】:

我正在尝试为谷歌地图制作自定义叠加层。我使用这个this 示例。而且我对覆盖宽度定义有疑问。

var sw = overlayProjection.fromLatLngToDivPixel(this.bounds_.getSouthWest());
var ne = overlayProjection.fromLatLngToDivPixel(this.bounds_.getNorthEast());

// Resize the image's div to fit the indicated dimensions.
var div = this.div_;
div.style.left = sw.x + 'px';
div.style.top = ne.y + 'px';
div.style.width = (ne.x - sw.x) + 'px';
div.style.height = (sw.y - ne.y) + 'px';

此代码返回小于一个像素的宽度,用于与此 latlonbox 叠加:

<LatLonBox>
<north>90.0</north>
<south>-90.0</south>
<east>180.0</east>
<west>-180.0</west>
</LatLonBox>

有人遇到过这个问题吗?也许有人知道解决方案。如果有任何帮助,我将不胜感激。

【问题讨论】:

    标签: google-maps google-maps-api-3 overlay custom-overlay


    【解决方案1】:

    这似乎发生在边界与本初子午线相交时。

    试试这个来计算宽度:

             ((ne.x - sw.x)
              +
              (((ne.x - sw.x)<0
                ||
              this.bounds_.getNorthEast().lng()
              -
              this.bounds_.getSouthWest().lng()>=360)
                ? overlayProjection.getWorldWidth()
                : 0))
    

    演示:http://jsfiddle.net/doktormolle/4vj37ecy/

    【讨论】:

    • 哦,谢谢它的工作!但现在我也看到了身高的问题。据我了解,在谷歌地图中,​​经度可以取值 [-85, 85]。但谷歌地球 kml 包含值 -90 和 90。所以高度和顶部 walues 也是错误的。我该如何解决?演示:iwep.wc.lt(以最小缩放级别看到的叠加)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多