Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google maps Google Maps V3工具提示弹出窗口,具有动态自动定位功能_Google Maps_Popup_Tooltip_Positioning - Fatal编程技术网

Google maps Google Maps V3工具提示弹出窗口,具有动态自动定位功能

Google maps Google Maps V3工具提示弹出窗口,具有动态自动定位功能,google-maps,popup,tooltip,positioning,Google Maps,Popup,Tooltip,Positioning,我正在寻找一个弹出窗口,它将与Google Maps V3一起使用,支持根据标记自动定位弹出窗口,以便整个弹出窗口在地图视口中始终可见。我正试图破解InfoBox库来实现这一点,但事实证明这是一个很大的麻烦。我还研究了QTip2,它显示了一些希望,但也有一些缺点,比如定位,但必须手动设置 编辑:解决方案需要不平移地图以显示弹出窗口。我在。它似乎正是你想要的。以下是。我能够在SmartInfoWindow的一点帮助下,将其添加到InfoBox中,使其实现我想要的功能。这是一个部分定制的解决方案,因

我正在寻找一个弹出窗口,它将与Google Maps V3一起使用,支持根据标记自动定位弹出窗口,以便整个弹出窗口在地图视口中始终可见。我正试图破解InfoBox库来实现这一点,但事实证明这是一个很大的麻烦。我还研究了QTip2,它显示了一些希望,但也有一些缺点,比如定位,但必须手动设置


编辑:解决方案需要不平移地图以显示弹出窗口。

我在。它似乎正是你想要的。以下是。

我能够在SmartInfoWindow的一点帮助下,将其添加到InfoBox中,使其实现我想要的功能。这是一个部分定制的解决方案,因此您可能需要调整定位。您只需获取信息框每个角点的div位置,将这些角点转换回lat/lng,然后获取地图边界,查看这些角点是否在边界内。如果没有,则根据地图上哪些角不在地图上,相应地调整信息框的位置

InfoBox.prototype.maybePanMap = function() {
  // if we go beyond map, pan map
  var map = this.getMap();
  var projection = this.getProjection();
  var bounds = map.getBounds();
  if (!bounds) return;

  // The dimension of the infowindow
  var iwWidth = this.div_.offsetWidth;
  var iwHeight = this.div_.offsetHeight;

  // The offset position of the infowindow
  var iwOffsetX = this.pixelOffset_.width;
  var iwOffsetY = this.pixelOffset_.height;

  var anchorPixel = projection.fromLatLngToDivPixel(this.getPosition());
  var bl = new google.maps.Point(anchorPixel.x + iwOffsetX,
      anchorPixel.y + iwOffsetY);
  var br = new google.maps.Point(anchorPixel.x + iwOffsetX + iwWidth,
      anchorPixel.y + iwOffsetY);
  var tl = new google.maps.Point(anchorPixel.x + iwOffsetX,
      anchorPixel.y + iwOffsetY - iwHeight + 100);
  var tr = new google.maps.Point(anchorPixel.x + iwOffsetX + iwWidth,
      anchorPixel.y + iwOffsetY - iwHeight + 100);

  var sw = projection.fromDivPixelToLatLng(bl);
  var se = projection.fromDivPixelToLatLng(br);
  var nw = projection.fromDivPixelToLatLng(tl);
  var ne = projection.fromDivPixelToLatLng(tr);


  if (!map.getBounds().contains(nw) && !map.getBounds().contains(sw)) {        
    this.div_.style.left = (anchorPixel.x + 10) + 'px';
    if (!map.getBounds().contains(ne)) {
      this.div_.style.top = (anchorPixel.y - 100) + 'px';
    }
  } else if (!map.getBounds().contains(nw) && !map.getBounds().contains(ne)) {
    this.div_.style.top = (anchorPixel.y - 100) + 'px';
    if (!map.getBounds().contains(se)) {
      this.div_.style.left = (anchorPixel.x - iwWidth - 10) + 'px';
    }
  } else if (!map.getBounds().contains(ne) && !map.getBounds().contains(se)) {
    this.div_.style.left = (anchorPixel.x - iwWidth - 10) + 'px';        
    if (!map.getBounds().contains(sw)) {
      this.div_.style.top = (anchorPixel.y - iwHeight - 100) + 'px';
    }        
  }


};

这是一个接近,但我忘了提到,我不能有地图平移显示整个弹出窗口(InfoBox也可以平移来显示弹出窗口。我想你是对的。当我简单地玩演示时,它以避免平移的方式打开了InfoBox窗口。但是现在我发现它并不是在所有情况下都可以避免平移。糟糕。我也在寻找同样的方法。似乎找不到一种方法来破解InfoBox来选择最佳位置。我是真的我会让它工作。我会在下面发布一个答案。这是如何使用的?我需要在infobox.open()之前调用infobox.maybePanMap()吗?我在infobox.js文件的draw函数末尾调用这个。maybePanMap()。谢谢!这绝对完美!