在GMaps API V3中显示地图版权 [英] Showing map copyright in GMaps API V3

查看:108
本文介绍了在GMaps API V3中显示地图版权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将应用程序从GMaps V2迁移到V3。当我使用OSM和其他非Google地图图层时,我想将版权声明保留在右下角。但参考文档并未提供任何提示。在V2中,版权甚至有它自己的类 GCopyrightCollection ,并被传递给 GTileLayer 。 Google Code操场也没有提供V3的示例。



有谁知道如何在新的API中执行此操作?

邮件列表帮助我解决了这个问题(请参阅 thread )。 Google代码上的示例代码用于版权集合以及如何将它们显示在地图DIV的右下角。



由于在右下角布局自定义DIV时出现问题(只跳转到正确的位置当拖动地图时,GMaps API自身的问题),我现在将其显示在左下角。 更新:问题似乎在API中得到了解决!)



以下代码按预期工作我没有使用全局变量,为了清晰起见,删除了 this。):

  copyrightDiv = document.createElement(div)
copyrightDiv.id =map-copyright
copyrightDiv.style.fontSize =11px
copyrightDiv.style.fontFamily =Arial ,sans-serif
copyrightDiv.style.margin =0 2px 2px 0
copyrightDiv.style.whiteSpace =nowrap
map.controls [google.maps.ControlPosition.BOTTOM_LEFT] .push(copyrightDiv)

版权= {}
版权[OSM] =< a target = \_blank\href = \http:// www.openstreetmap.org/\\">OpenStreetMap</a>
版权[Osmarender] =版权[OSM]
版权[Cloudmade] =< a target = \_blank\href = \http:// cloudmade.com/\\">CloudMade</a> - 地图资料< a target = \_blank\href = \http://creativecommons.org/licenses/by-sa/2.0/ \ > CCBYSA< / A> 中
copyrights [Cloudmade-Fine] = copyrights [Cloudmade]

onMapTypeIdChanged()
{
newMapType = map.getMapTypeId()

copyrightDiv = document.getElementById(map-copyright)
if(newMapType in copyrights)
copyrightDiv.innerHTML = copyrights [newMapType]
else
copyrightDiv。 innerHTML =
}

google.maps.event.addListener(map,maptypeid_changed,onMapTypeIdChanged)

//调用一次以保证正确的版权通知设置为
//最初选择的地图类型
setTimeout(onMapTypeIdChanged,50)


I'm currently migrating an application from GMaps V2 to V3. As I use OSM and other non-Google map layers, I want to keep the copyright notice at the bottom right. But the reference documentation doesn't give any hints on this. In V2, the copyright even had its own class GCopyrightCollection, and was passed to GTileLayer. Google Code playground also doesn't provide an example for V3.

Does anyone know how to do this in the new API?

解决方案

The mailing list helped me on this issue (see thread). There is sample code on Google Code for copyright collections and how to display them in the bottom right corner of the map DIV.

As there is a problem with layouting the custom DIV in the bottom right corner (only jumps to the correct position when the map is dragged, problem of GMaps API itself), I am now displaying it in the bottom left corner instead. (UPDATE: Problem seems to be fixed in API !)

The following code works as expected (of course I'm not using global variables, removed this. for clarity):

copyrightDiv = document.createElement("div")
copyrightDiv.id = "map-copyright"
copyrightDiv.style.fontSize = "11px"
copyrightDiv.style.fontFamily = "Arial, sans-serif"
copyrightDiv.style.margin = "0 2px 2px 0"
copyrightDiv.style.whiteSpace = "nowrap"
map.controls[google.maps.ControlPosition.BOTTOM_LEFT].push(copyrightDiv)

copyrights = {}
copyrights["OSM"] = "<a target=\"_blank\" href=\"http://www.openstreetmap.org/\">OpenStreetMap</a>"
copyrights["Osmarender"] = copyrights["OSM"]
copyrights["Cloudmade"] = "<a target=\"_blank\" href=\"http://cloudmade.com/\">CloudMade</a> - Map data <a target=\"_blank\" href=\"http://creativecommons.org/licenses/by-sa/2.0/\">CCBYSA</a>"
copyrights["Cloudmade-Fine"] = copyrights["Cloudmade"]

function onMapTypeIdChanged()
{
    newMapType = map.getMapTypeId()

    copyrightDiv = document.getElementById("map-copyright")
    if(newMapType in copyrights)
        copyrightDiv.innerHTML = copyrights[newMapType]
    else
        copyrightDiv.innerHTML = ""
}

google.maps.event.addListener(map, "maptypeid_changed", onMapTypeIdChanged)

// Call once so that the correct copyright notice is set for
// the initially selected map type
setTimeout(onMapTypeIdChanged, 50)

这篇关于在GMaps API V3中显示地图版权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆