百度地图Api进阶教程-默认控件和自定义控件2.html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>10.1</title>
<script type="text/javascript">
function initialize() {
var map = new BMap.Map("container", { minZoom: 12, maxZoom: 25 });
map.centerAndZoom("成都", 13);
map.enableScrollWheelZoom(true);
//增加缩放控件
map.addControl(new BMap.NavigationControl());
//版权控件 显示在右下角
var cr = new BMap.CopyrightControl({ anchor: BMAP_ANCHOR_BOTTOM_RIGHT }); //var bs=map.getBounds();
cr.addCopyright({ id: 1, content: "<a href='#' style='font-size:20px;background:yellow'>我是自定义版权控件呀</a>" });
map.addControl(cr); //添加版权控件
//自定义控件
// 定义一个控件类,即function
// 定义一个控件类,即function
function ZoomControl() {
// 默认停靠位置和偏移量
this.defaultAnchor = BMAP_ANCHOR_TOP_RIGHT;
this.defaultOffset = new BMap.Size(10, 10);
} // 通过JavaScript的prototype属性继承于BMap.Control
ZoomControl.prototype = new BMap.Control(); // 自定义控件必须实现自己的initialize方法,并且将控件的DOM元素返回
// 在本方法中创建个div元素作为控件的容器,并将其添加到地图容器中
ZoomControl.prototype.initialize = function (map) {
// 创建一个DOM元素
var div = document.createElement("div");
// 添加文字说明
//div.appendChild(document.createTextNode("放大2级"));
div.innerHTML = "<img src=\"http://t2.baidu.com/it/u=351117335,2626617599&fm=0&gp=0.jpg\" />"
// 设置样式
div.style.cursor = "pointer";
div.style.border = "1px solid gray";
div.style.backgroundColor = "white";
//点击事件
div.onclick = function (e) {
map.setZoom(map.getZoom() + 2);
alert("1");
} // 添加DOM元素到地图中
map.getContainer().appendChild(div);
// 将DOM元素返回
return div; } // 创建控件
var myZoomCtrl = new ZoomControl();
// 添加到地图当中
map.addControl(myZoomCtrl); } function loadScript() {
var script = document.createElement("script");
script.src = "http://api.map.baidu.com/api?v=1.4&callback=initialize";
document.body.appendChild(script);
}
window.onload = loadScript;
</script>
</head>
<body>
<div style="float: left; width: 100px;">
1</div>
<div id="container" style="width: 800px; height: 500px">
</div>
<div id="result">
</div>
</body>
</html>
百度地图Api进阶教程-默认控件和自定义控件2.html的更多相关文章
- 百度地图Api进阶教程-点击生成和拖动标注4.html
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 百度地图Api进阶教程-实例高级操作8.html
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 百度地图Api进阶教程-基础地图示例1.html
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 百度地图Api进阶教程-地图鼠标左右键操作实例和鼠标样式6.html
<!DOCTYPE html> <html> <head> <meta name="viewport" content="ini ...
- 百度地图Api进阶教程-用户自定义数据(标记和搜索)7.html
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 百度地图Api进阶教程-弹出信息窗口5.html
<!DOCTYPE html> <html> <head> <meta name="viewport" content="ini ...
- 百度地图Api进阶教程-创建标注和自定义标注3.html
<!DOCTYPE html> <html> <head> <meta name="viewport" content="ini ...
- 百度地图Api进阶教程-点聚合9.html
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- duilib进阶教程 -- Container控件的bug (14)
在<duilib进阶教程 -- TreeView控件的bug (9)>里,Alberl发现了两个bug,并解决了其中一个,现在教程已经接近尾声啦,所以Alberl就解决了另外一个bug. ...
随机推荐
- Logstash+ElasticSearch+Kibana处理nginx访问日志(转)
ELK似乎是当前最为流行的日志收集-存储-分析的全套解决方案. 去年年初, 公司里已经在用, 当时自己还山寨了一个统计系统(postgresql-echarts, 日志无结构化, json形式存储到p ...
- swagger配置和简单使用
说明:本地环境idea + maven3.5 + springboot2.0.0 + springfox-swagger2 2.8.0 + springfox-swagger-ui 2.8.0 + ...
- databus编译: Execution failed for task ':databus-core:databus-core-impl:compileJava'.
在编译databus的过程中,出现了无法找到jdk的错误: 在/etc/.bashrc和/etc/profile中都配置了JAVA_HOME,依然报错,重启后还是报错,原因的是ubuntu中默认的jd ...
- ssh 反向代理和正向代理的文章
搜索原因是,我希望访问家里内网的机器 技术要点: ssh 反向代理,正向代理 隧道 文章摘自: https://my.oschina.net/leejun2005/blog/94401 https:/ ...
- CSS边框闪烁呼吸样式
<html> <body> <head> .arrow_box{animation: glow 800ms ease-out infinite alternate; ...
- activiti主要API对象
ProcessEngine //流程引擎 RuntimeService //与流程实例,执行对象(正在执行) TaskService //正在执行任务 H ...
- JS location.href跳出框架打开新页面
后面在框架中,当判断登录失效后要返回登录页面,但登录页面却在框架内打开,我想让它直接跳出框架打开,这里不是打开新窗口. echo "<script language=\"ja ...
- haproxy rpm制做
[root@c01 tmp]# fpm -s dir -t rpm -v 1.7.7 -n haproxy --before-install /tmp/haproxy_before.sh --afte ...
- 【小白的CFD之旅】26 何为收敛
小白最近对流体计算的收敛产生了困惑.以前在学习高等数学的时候,小白接触过了级数的收敛,由于当时贪玩,并未将其放在心上,因此大学结束了小白也只是记住有这么一个名词罢了.现如今在利用CFD的过程中 ...
- Multi-cloud Kubernetes with Triton
https://www.joyent.com/blog/triton-kubernetes-multicloud While running an experimental Kubernetes cl ...