ASP.NET Google Maps Javascript API V3 实战基础篇一在事件侦听器中使用闭包
2010-10-18 15:50
411 查看
ASP.NET Google Maps Javascript API V3 实战基础篇一在事件侦听器中使用闭包
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Event_Closure.aspx.cs"Inherits="Samples.Events.Event_Closure" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>在事件侦听器中使用闭包</title>
<style type="text/css">
#maps
{
height: 500px;
}
</style>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&language=zh-CN"></script>
<script language="javascript" type="text/javascript">
var map;
//初始化
function initialize() {
var LatLng = new google.maps.LatLng(-25.363882, 131.044922);
var Options = {
zoom: 4, center: LatLng, mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("maps"), Options);
var southWest = new google.maps.LatLng(-31.203405, 125.244141);
var northEast = new google.maps.LatLng(-25.363882, 131.044922);
var bounds = new google.maps.LatLngBounds(southWest, northEast);
map.fitBounds(bounds);
var lngSpan = northEast.lng() - southWest.lng();
var latSpan = northEast.lat() - southWest.lat();
//生成五个点并生成标记
for (var i = 0; i < 5; i++) {
var location = new google.maps.LatLng(southWest.lat() + latSpan * Math.random(), southWest.lng() + lngSpan * Math.random());
var marker = new google.maps.Marker({
position: location, map: map
});
var j = i + 1;
marker.setTitle(j.toString());
attachSecretMessae(marker, i);
}
}
//生成相应信息窗口
function attachSecretMessae(marker, number) {
var message = ["This", "is", "the", "secret", "message"];
var infowindow = new google.maps.InfoWindow({
content: message[number], size: new google.maps.Size(50, 50)
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
//在window的load事件中进行加载
google.maps.event.addDomListener(window, "load", initialize);
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="maps">
</div>
</form>
</body>
</html>
相关文章推荐
- ASP.NET Google Maps Javascript API V3 实战基础篇一获取和设置事件处理程序中的属性
- ASP.NET Google Maps Javascript API V3 实战基础篇一获取和设置事件处理程序中的属性
- ASP.NET Google Maps Javascript API V3 实战基础篇一地图事件
- ASP.NET Google Maps Javascript API V3 实战基础篇一地图事件
- ASP.NET Google Maps Javascript API V3 实战基础篇一访问用户界面事件中的参数
- ASP.NET Google Maps Javascript API V3 实战基础篇一停用默认用户界面
- ASP.NET Web 应用开发实战快速上手系列 2——C#基础
- ASP.NET使用三层架构时候注意的问题+基础使用
- 在ASP.NET页面中推荐使用覆写(Override)而不是事件处理(EventHandler)
- 【ASP.NET】1.ASP.NET页面事件加载顺序以及Global.asax文件的使用
- 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【十】——使用CacheCow和ETag缓存资源
- 使用ASP .NET察看和清除你的事件日志
- 使用javascript绑定键盘enter事件到asp.net的button控件
- asp.net错误捕获(错误处理)page_error事件使用方法
- 使用ASP.NET WEB API构建基于REST风格的服务实战系列教程(一)——使用EF6构建数据库及模型
- asp.net基础学习之控件的使用方法
- 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【六】——实现资源间的关联
- ASP.NET中使用三层架构事务的技巧实战
- ASP.NET Google Maps Javascript API V3 实战基础篇一检测用户位置
- 使用Code First建模自引用关系笔记 asp.net core上使用redis探索(1) asp.net mvc控制器激活全分析 语言入门必学的基础知识你还记得么? 反射