google maps v3 添加自定义图标(marker,overlay)
google搜了很久都没找到符合v3版本的google maps自定义图标,可以让图标使用自己的html,都是V2版本的,依靠重写google api属性来完成.
然后就找了个jquery下的google maps插件: GMAP3(http://gmap3.net)
经过研究发现...这货很方便,而且我也实现了自己的图标!
我的自定义图标使用的是bootstrap插件:font-awesome中的icon.
首先,引入
<link href="bootstrap.css" rel="stylesheet"/>
<link href="bootstrap-responsive.css" rel="stylesheet"/>
<link href="font-awesome.css" rel="stylesheet"/>
<script type="text/javascript" src="jquery.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?&sensor=false" type="text/javascript"></script>
<script type="text/javascript" src="gmap3.js"></script>
然后简历一个json
var $values = [
{
latLng: [48.8620722, 2.352047], data: "Paris !",
options: {
icon: "marker_icon_bg.png",
content: '<i style="color:#fff" class="icon-food"></i>',
offset: {
y: -32,
x: -6
}
}
},
{
address: "86000 Poitiers, France", data: "Poitiers : great city !",
options: {
icon: "marker_icon_bg.png",
content: '<i style="color:#fff" class="icon-picture"></i>',
offset: {
y: -32,
x: -8
}
}
},
{
address: "66000 Perpignan, France", data: "Perpignan ! <br> GO USAP !",
options: {
icon: "marker_icon_bg.png",
content: '<i style="color:#fff" class="icon-building"></i>',
offset: {
y: -32,
x: -6
}
}
}
];
直接调用gmap3的方法:
$(function () {
$('#map_canvas').gmap3({
map: {
options: {
center: [46.578498, 2.457275],
zoom: 5
}
},
marker: {
values: $values,
options: {
draggable: false
},
events: {
mouseover: function (marker, event, context) {
var map = $(this).gmap3("get"),
infowindow = $(this).gmap3({ get: { name: "infowindow" } });
if (infowindow) {
infowindow.open(map, marker);
infowindow.setContent(context.data);
} else {
$(this).gmap3({
infowindow: {
anchor: marker,
options: { content: context.data }
}
});
}
},
mouseout: function () {
var infowindow = $(this).gmap3({ get: { name: "infowindow" } });
if (infowindow) {
infowindow.close();
}
}
}
},
overlay: {
values: $values
}
});
});
Body部分:
<body>
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
相当方便!直接产生了地标背景上出现图标,而且还是json方式的,方便我们生成!
google maps v3 添加自定义图标(marker,overlay)的更多相关文章
- Google Maps V3 之 路线服务
概述 您可以使用 DirectionsService 对象计算路线(使用各种交通方式).此对象与 Google Maps API 路线服务进行通信,该服务会接收路线请求并返回计算的结果.您可以自行处理 ...
- [Google Maps API 3]Marker从Clusterer中分离及Marker置于Cluster上一层的解决办法
在Google Maps API的使用中,经常用到Clusterer来避免过密的Marker显示.但仔细看一下Clusterer的设置参数中并没有直接将某些Marker除外的方法,那遇到这样的需求,怎 ...
- Google Maps API V3 之绘图库 信息窗口
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- Google Maps API V3 之 图层
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- Google Maps API V3 之 路线服务
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- ☀【移动】Google Maps JavaScript API v3
Google Maps JavaScript API v3https://developers.google.com/maps/documentation/javascript/tutorial?hl ...
- google maps js v3 api教程(3) -- 创建infowindow
原文地址 前面我们学习了地图和标记的创建.那么今天我们来学习怎样在地图上显示一个窗口(infowindow) infowindow构造函数为:InfoWindow(opts?:InfoWindowOp ...
- google maps js v3 api教程(2) -- 在地图上添加标记
原文链接 google maps javascript官方文档:https://developers.google.com/maps/documentation/javascript/ 我们在创建地图 ...
- [转]MBTiles 离线地图演示 - 基于 Google Maps JavaScript API v3 + SQLite
MBTiles 是一种地图瓦片存储的数据规范,它使用SQLite数据库,可大大提高海量地图瓦片的读取速度,比通过瓦片文件方式的读取要快很多,适用于Android.IPhone等智能手机的离线地图存储. ...
随机推荐
- asp.net中的Application概述
全局应用程序类 从Application这个单词上大致可以看出Application状态是整个应用程序全局的.在ASP时代我们通常会在Application中存储一些公共数据,而ASP.NET中App ...
- Factory Method模式
Factory Method(工厂方法)模式属于GoF设计模式中的创建型分组,它用于在不之制定待创建对象的具体类的情况下创建对象.--<asp.net设计模式> 说白了就是一个人想要出国旅 ...
- Gitlab 与 Git Windows 客户端一起使用的入门流程
我的技术博客经常被流氓网站恶意爬取转载.请移步原文:http://www.cnblogs.com/hamhog/p/3824934.html,享受整齐的排版.有效的链接.正确的代码缩进.更好的阅读体验 ...
- [java学习笔记]java语言基础概述之内存的划分&堆和栈
1.内存的划分 1.寄存器 cpu处理 2.本地方法区 和所在系统相关 3.方法区 方法加载进内存,其实就是开辟了一块该方法的方法区 方法区中还可以有静态区,用于存放静态变量(类变量) 4.栈内存 5 ...
- awk!字符问题,修复中!.......
awk '条件类型1{动作1} 条件类型2{动作2}' file1 file2 变量名称:1.NF 每一行($0表示文本所有域)拥有的字段数. 2.NR目前awk处理的"第n行"数 ...
- IE下不支持option的onclick事件
<select> <option onclick="test('www.hao123.com')"value="www.hao123.com" ...
- 鼠标滑过提示title
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1. ...
- DataGridView 分页显示
DataGridView 分页显示函数 1.获取当前页的子数据表函数 public static DataTable GetPagedTable(DataTable dt, int PageIndex ...
- Android 生命周期 和 onWindowFocusChanged
转载 http://blog.csdn.net/pi9nc/article/details/9237031 onWindowFocusChanged重要作用 Activity生命周期中,onStart ...
- php curl 伪造IP来源的代码分享
php curl 可以模仿用户登录,还可以模仿用户IP地址.伪造IP来源. 1,curl发出请求的文件fake_ip.php: <?php $ch = curl_init(); $url = & ...