加入收藏 | 设为首页 | 会员中心 | 我要投稿 河北网 (https://www.hebeiwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 创业 > 正文

操作GControl和GLayer工具在舆图上表现panoramio图片

发布时间:2018-09-02 14:23:33 所属栏目:创业 来源:站长网
导读:本日是Google map api的关于操作GControl和GLayer工具在舆图上表现panoramio图片的教程,昨天我写了一篇Google map api的教程是关于在舆图上添加节制按钮的(Google Map API教程之行使GControl工具在舆图上添加control按钮),本日团结上篇文章,写一下怎

本日是Google map api的关于操作GControl和GLayer工具在舆图上表现panoramio图片的教程,昨天我写了一篇Google map api的教程是关于在舆图上添加节制按钮的(Google Map API教程之行使GControl工具在舆图上添加control按钮),本日团结上篇文章,写一下怎么在舆图上加一个可以表现panoramio的图片,行使的首要工具是GControl和GLayer工具。关于GControl工具的官方文档(请点这里),GLayer工具的官方文档(请点这里)

行使GLayer建设图片层工具

我们可以通过以下代码建设一个panoramio.com的图片层:
photoLayer=new GLayer("com.panoramio.all")
然后通过Gmap.addOverlay(photoLayer)添加这个层

谷歌舆图的API支持的GLayer工具有谷歌webcam、panoramio、维基百科等,更多支持请点击查察:http://spreadsheets.google.com/pub?key=p9pdwsai2hDN-cAocTLhnag

行使GControl工具在舆图上建设一个checkbox

这种要领就不多说了,详细GControl的行使,请看我之前写的关于GControl的教程(Google Map API教程之行使GControl工具在舆图上添加control按钮)。这里就只是贴出来代码:

function photoControl() {};
photoControl.prototype = new GControl();
photoControl.prototype.initialize = function(gmap){
var buttonDiv = document.createElement("div");
buttonDiv.id = "photoLayer";
var inputDiv=document.createElement("input");
inputDiv.type="checkbox";
inputDiv.id="photoCheckBox"
inputDiv.onclick=function(){
addPhotoLayer(this.checked)
}
buttonDiv.appendChild(inputDiv);
var labelFor=document.createElement("label");
labelFor.setAttribute("for","photoCheckBox");
labelFor.appendChild(document.createTextNode("看图"));
buttonDiv.appendChild(labelFor);
gmap.getContainer().appendChild(buttonDiv);
return buttonDiv;
};

photoControl.prototype.getDefaultPosition = function(){
return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(530, 7));
};

最终代码和实例

var gmap=null,photoLayer=new GLayer("com.panoramio.all");

function init(){
if (GBrowserIsCompatible()) {
gmap = new GMap2(document.getElementById("gmap"));
gmap.setCenter(new GLatLng(36.105,120.34), 12);
gmap.setUI(gmap.getDefaultUI());
gmap.enableScrollWheelZoom();

gmap.addControl(new photoControl());
}
}
function photoControl() {};
photoControl.prototype = new GControl();
photoControl.prototype.initialize = function(gmap){
var buttonDiv = document.createElement("div");
buttonDiv.id = "photoLayer";
var inputDiv=document.createElement("input");
inputDiv.type="checkbox";
inputDiv.id="photoCheckBox"
inputDiv.onclick=function(){
addPhotoLayer(this.checked)
}
buttonDiv.appendChild(inputDiv);
var labelFor=document.createElement("label");
labelFor.setAttribute("for","photoCheckBox");
labelFor.appendChild(document.createTextNode("看图"));
buttonDiv.appendChild(labelFor);
gmap.getContainer().appendChild(buttonDiv);
return buttonDiv;
};

photoControl.prototype.getDefaultPosition = function(){
return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(530, 7));
};
function addPhotoLayer(checked){
if (checked) {
gmap.addOverlay(photoLayer);
}
else {
gmap.removeOverlay(photoLayer);
}
} 出处:http://www.js8.in/566.html

(编辑:河北网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读