show you the code!
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<title>多点标注</title>
<script src="/static/jquery/jquery-1.11.1.min.js"></script>
<link href="/static/materialize/css/materialize.min.css" rel="stylesheet">
<script src="/static/materialize/js/materialize.min.js"></script>
<link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
<script src="http://webapi.amap.com/maps?v=1.3&key=6d116d4252d7f7ce90a808ace0812248"></script> <!--引入高德地图api,key为你自己获取的key值-->
<script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
<style>
.amap-logo{
display: none; /*隐藏左下角地图logo*/
}
.amap-copyright{
display: none!important;
}
</style>
</head>
<body>
<div id="container" style="width:100%;height:100%"></div>
<div id="tip"></div>
<script>
var map = new AMap.Map('container', {});
map.plugin(["AMap.ToolBar"], function() {
map.addControl(new AMap.ToolBar());
});
var infoWindow = new AMap.InfoWindow({}); //创建信息窗口对象 ps.高德目前不支持多信息窗口,即使创建多个窗口对象,也只会显示一个
var lnglats= [["116.4123","39.906422"],["116.4352","39.906933"],["116.445435","39.9054345"]];
var data = [{"id":1,"name":"我是第1个点","type":1},{"id":2,"name":"我是第2个点","type":3},{"id":3,"name":"我是第3个点","type":7}];
for(var i= 0;i<lnglats.length;i++){
var marker=new AMap.Marker({
position:lnglats[i], //采用默认样式,无需自定义
map:map
});
content = [];
content.push('ID:'+data[i].id);
content.push('名称:'+data[i].name);
marker.content = content;
marker.title = data[i].id+"."+data[i].name; //标记点的title
// if(data[i].id==2){ //默认打开第二个点的信息窗口
infoWindow.setContent(content.join("<br/>"));
infoWindow.open(map,lnglats[i]);
// }
marker.on('dblclick',openAmap); //这里采用调到新页面方式导航,也可直接定义带导航功能的信息窗体,请参考http://lbs.amap.com/api/javascript-api/example/infowindow/infowindow-has-search-function/
//给Marker绑定单击事件
marker.on('click', markerClick);
}
map.setFitView();
//跳至地图当中导航
function openAmap(e){
e.target.markOnAMAP({
name:e.target.title,
position:e.target.getPosition()
})
}
//信息窗口
function markerClick(e){
infoWindow.setContent(e.target.content.join('<br/>'));
infoWindow.open(map, e.target.getPosition());
}
//地图加载完成事件
map.on('complete', function() {
Materialize.toast('地图图块加载完毕!', 4000)
// document.getElementById('tip').innerHTML = "地图图块加载完毕!当前地图中心点为:" + data[0].name;
});
</script>
</body>
</html>
搜索
标签
study
ab
amap
apache
apahe
awk
aws
bat
centos
CFS
chrome
cmd
cnpm
composer
consul
crontab
css
curl
cygwin
devops
di
docker
docker,docker-compose
ethereum
excel
fiddler
fluentd
framework
front-end
git
gitgui
github
glide
go
golang
gorm
grafana
gzip
ioc
item2
iterm2
javascript
jenkins
jsonp
kafka
laradock
laravel
larval
linux
liunux
log
mac
mac, wi-fi
macos
magento
mariaDB
minikube
mongoDB
msp
mysql
netbeans
nginx
nodejs
nohup
npm
nsq
php
php-fpm
php7
phpstorm
php扩展
Protobuf
python
redis
scp
server
shell
soap
socket
socket5
sql
sre
ssdb
ssh
ssl
study
sublime
swift
system
td-agent
uml
v2ray
vagrant
vagrnat
vim
vpn
vue
vue.js
webpack
webrtc
websocket
webtatic
windows
windows7
word
wps
xdebug
yarn
yii2
yum
zookeeper
世界国家
互联网
以太坊
分类
前端
小程序
打印机
排序算法
搞笑
权限
粤语
缓存
网络
虚拟机
视频
设计模式
项目管理
热门文章
友情链接