当前位置: 首页 > 图文教程 > 网络编程 > Javascript > googlemap 之 javascript实现方法

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 googlemap 之 javascript实现方法


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-10   浏览: 391 ::
收藏到网摘: n/a

这是一个很典型的一个background-position-x的应用。技术含量并不高,但是思想还是值得思考的,证明了DHTML方面有很多东西可以变通的。用背景用map,如果做得更复杂一些,用ajax动态的载入图片的背景,也是一个小型的map了。我不打算在此项深究,因为脚本的速度和效率是有瓶颈的。
预备知识:
background-position-x ------------- 背景图的X坐标。
background-position-y ------------- 背景图的Y坐标。
event.clientX ------------------------鼠标的X坐标。
event.clientY ------------------------鼠标的Y坐标。
JSON --------------------------------- 现在似乎很流行这个词,自从ajax in action出来后,更火了一把,从广义的角色上讲就是javascript的关联数组。JSON(JavaScript Object Notation) 也就是类似这样 var o={name:"never-online",web:"http://www.never-online.net",blog:"http://blog.never-online.net"}从而可以这样用o.name, o.web或者o['name'],o['web']这样的数组关系形式。
问题解决思路:
这个map的主要难点在于,坐标的准确性,也就是鼠标移动时得到background-position的坐标方向。
如果解决掉上面的这个问题,成功了一大半。
我采用惯用的方法
坐标=用鼠标移动后的坐标-原始我们存进的坐标。
原始坐标得到方法为:neverOnlineMap._wrapper.X = event.clientX-parseInt(x.backgroundPositionX);
即用鼠标当前位置-图像背景的X坐标
图片背景坐标=鼠标位置-原始位置
Y坐标和X坐标类似,不再重复。neverOnlineMap._wrapper.Y = event.clientY-parseInt(x.backgroundPositionY);
源码如下:
点击运行可以看到效果:
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]