百度地图Api进阶教程-创建标注和自定义标注3.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>11.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.addEventListener("click", function (e) {
document.getElementById("r-result").innerHTML = e.point.lng + "," + e.point.lat;
}); var point = new BMap.Point(104.117287, 30.685906);
var marker = new BMap.Marker(point);
map.addOverlay(marker); var point = new BMap.Point(104.057287, 30.685906);
var myicon = new BMap.Icon("http://t3.baidu.com/it/u=1119318591,884730191&fm=0&gp=0.jpg", new BMap.Size(55, 55));
var marker = new BMap.Marker(point, { icon: myicon });
map.addOverlay(marker); //自定义遮盖物
// 定义自定义覆盖物的构造函数
var point = new BMap.Point(104.117287, 30.695906); //自定义遮盖物
function SquareOverlay(point, length, color) {
this._point = point;
this._length = length;
this._color = color;
} // 继承API的BMap.Overlay
SquareOverlay.prototype = new BMap.Overlay(); // 实现初始化方法
SquareOverlay.prototype.initialize = function (map) {
// 保存map对象实例
this._map = map;
// 创建div元素,作为自定义覆盖物的容器
var div = document.createElement("div");
div.style.position = "absolute";
// 可以根据参数设置元素外观
div.style.width = this._length + "px";
div.style.height = this._length + "px";
div.style.background = this._color;
// 将div添加到覆盖物容器中
map.getPanes().markerPane.appendChild(div);
// 保存div实例
this._div = div;
// 需要将div元素作为方法的返回值,当调用该覆盖物的show、
// hide方法,或者对覆盖物进行移除时,API都将操作此元素。
return div;
} // 实现绘制方法 (您需要在draw方法中设置覆盖物的位置,每当地图状态发生变化(比如:位置移动、级别变化)时,API都会调用覆盖物的draw方法,用于重新计算覆盖物的位置)
SquareOverlay.prototype.draw = function () { var position = map.pointToOverlayPixel(this._point);
this._div.style.left = position.x - this._length / 2 + "px";
this._div.style.top = position.y - this._length / 2 + "px";
}
// 实现显示方法
SquareOverlay.prototype.show = function () {
if (this._div) {
this._div.style.display = "";
}
}
// 实现隐藏方法
SquareOverlay.prototype.hide = function () {
if (this._div) {
this._div.style.display = "none";
}
}
// 添加自定义覆盖物
var mySquare = new SquareOverlay(point, 22, "red");
map.addOverlay(mySquare); } 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="r-result" style="float: left; width: 100px;">
打印坐标</div>
<div id="result">
</div>
</body>
</html>
百度地图Api进阶教程-创建标注和自定义标注3.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进阶教程-用户自定义数据(标记和搜索)7.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进阶教程-弹出信息窗口5.html
<!DOCTYPE html> <html> <head> <meta name="viewport" content="ini ...
- 百度地图Api进阶教程-地图鼠标左右键操作实例和鼠标样式6.html
<!DOCTYPE html> <html> <head> <meta name="viewport" content="ini ...
- 百度地图Api进阶教程-默认控件和自定义控件2.html
<!DOCTYPE html> <html> <head> <meta name="viewport" content="ini ...
- 百度地图Api进阶教程-点聚合9.html
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 【百度地图API】情人节求爱大作战——添加标注功能
原文:[百度地图API]情人节求爱大作战--添加标注功能 任务描述: 2月2日是除夕,2月14立马来!即将到来的情人节,你想送TA一份什么礼物呢? 不如,在你们居住的地方,画个大大的桃心,表达你对TA ...
随机推荐
- Linux 下的hiredis的简单安装、测试*(转)
上一章介绍的是如何安装Redis以及在Redis客户端上进行简单测试,但是我们一般安装完Redis之后,都是要结合编程语言对其进行应用的,hiredis是redis开源库对外发布的客户端API包,这一 ...
- Package CJK Error: Invalid character code. 问题解决方法--xelatex和pdflatex编译的转换
Package CJK Error: Invalid character code. 问题解决方法--xelatex和pdflatex编译的转换 解决方法:添加格式说明信息 将下面语句: \docum ...
- 谈谈MySQL的黑暗语法
[MySQL在SQL标准下实现了自己的一套SQL语句] 每种数据库都会在继承标准SQL的基础上有所发展,比如SQL-SERVER在这个基础之上发展出来的SQL“方言”就叫“T-SQL”,MySQL 发 ...
- css遮罩层
父元素:position:fixed; 让子元素居中对齐:position:absolute;top:0;bottom:0;left:0;right:0;margin:auto; <style& ...
- Tomcat7启动报Error listenerStart错误
问题 Tomcat7在启动时报错,详细信息如下: 十一月 23, 2013 7:21:58 下午 org.apache.catalina.core.StandardContext startInter ...
- tmux用于恢复远程屏幕
1.我主要用tmux在远程登陆后,恢复以前会话时候用. 2.tmux创建新会话: tmux new -s 会话名 3.返回控制台: Ctrl+b d ,Ctrl+b命令是tmux前置命令,每次都要先输 ...
- 懒人习惯之ButterKnife Zelezny
项目地址:https://github.com/avast/android-butterknife-zelezny 这个是Android Studio的插件. 其实就间接帮你把LoadView的过 ...
- MyBatis传入集合 list 数组 map参数的写法
foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合.foreach元素的属性主要有item,index,collection,open,separator,close.ite ...
- 关键词抽取:pagerank,textrank
摘抄自微信公众号:AI学习与实践 TextRank,它利用图模型来提取文章中的关键词.由 Google 著名的网页排序算法 PageRank 改编而来的算法. PageRank PageRank 是一 ...
- 白话 Ruby 与 DSL 以及在 iOS 开发中的运用
每日一篇优秀博文 2017年10月7日 周六 白话 Ruby 与 DSL 以及在 iOS 开发中的运用 阅读本文不需要预先掌握 Ruby 与 DSL 相关的知识 何为 DSL DSL(Domain S ...