Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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
Javascript 谷歌地图自定义内容框?_Javascript_Google Maps_Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 谷歌地图自定义内容框?

Javascript 谷歌地图自定义内容框?,javascript,google-maps,maps,google-maps-api-3,Javascript,Google Maps,Maps,Google Maps Api 3,我似乎在谷歌地图V3文档中找不到关于为谷歌地图创建自定义内容框的内容 以下是自定义内容框的示例: 我的问题是。。。如何更改默认的白色气球弹出窗口 干杯 这个例子使用的是谷歌地图的第二个版本。该功能可能在第三个版本中不可用 但您可以在信息窗口中添加任何html代码并对其进行个性化设置。我不确定你是否可以直接改变它们的外观,但你绝对可以改变内容的外观 编辑:我找到了一些示例代码:查看中的,更具体的,以及中的InfoBox工具包。如果你想看的话,我正在使用它们。正如Sudhir指出的,Infobox

我似乎在谷歌地图V3文档中找不到关于为谷歌地图创建自定义内容框的内容

以下是自定义内容框的示例:

我的问题是。。。如何更改默认的白色气球弹出窗口


干杯

这个例子使用的是谷歌地图的第二个版本。该功能可能在第三个版本中不可用

但您可以在信息窗口中添加任何html代码并对其进行个性化设置。我不确定你是否可以直接改变它们的外观,但你绝对可以改变内容的外观


编辑:我找到了一些示例代码:

查看中的,更具体的,以及中的InfoBox工具包。如果你想看的话,我正在使用它们。

正如Sudhir指出的,Infobox插件是实现你想要的功能的一种方法。我最近回答了一个类似的问题,并提供了一个完整的例子。

就我个人而言,我不使用谷歌的任何自定义覆盖脚本等。我制作了一个自定义php页面,其中包含iframe,在这里我可以加载自定义css文件,并且我还创建了自定义div,这些div位于地图的顶部,当打开时,这些div会在拖动时重新定位

您可以使用“Drag,Dragstart,Dragend”事件来帮助您重新定位已创建的图元

如果在页面上设置了自定义标记,则可以使用此功能获取其像素位置:

getPosition: function (marker) {
        var map = this.map /* Your map, in my case is part of my controller object linked to this.map */;
        var scale = Math.pow(2, map.getZoom());
        var nw = new google.maps.LatLng(
            map.getBounds().getNorthEast().lat(),
            map.getBounds().getSouthWest().lng()
        );
        var worldCoordinateNW = map.getProjection().fromLatLngToPoint(nw);
        var worldCoordinate = map.getProjection().fromLatLngToPoint(marker.getPosition());
        var pixelOffset = new google.maps.Point(
            Math.floor((worldCoordinate.x - worldCoordinateNW.x) * scale),
            Math.floor((worldCoordinate.y - worldCoordinateNW.y) * scale)
        );
        return pixelOffset; /* Returns the top left pixel of the specified marker on the specified map */
    }
然后我使用了一个setPosition函数,它在窗口拖动时使用,它将自定义元素的位置设置为标记的位置。 可以通过以下方式设置拖动事件: addEventListener(map,'drag',function(){setPosition(marker,element);})

setPosition函数使用getPosition(marker)函数简单地收集元素的宽度、高度和与标记关联的像素偏移:

setPosition: function (marker,element) {
    var p = this.getPosition(marker),
        s = {width:element.offsetWidth,height:element.offsetHeight},
        markerOffset = {width:58,height:58};
    element.style.left = p.x - (s.width/2) + (markerOffset.width/2) + "px"; /* We set the element's left position to the marker's position + half of our element's width + half of the marker's width's so it is centered */
    element.style.top = p.y - s.height - (markerOffset.height) + 10 + "px"; /* We set the element's top position to the marker's position + our element's height + markers height so it is 10px above our marker vertically */
},
有时候你只需要跳出框框思考