JS 實現Map,js實現map
function Map() {this.arr = new Array();var struct = function(key, value) {this.key = key;this.value = value; };this.put = function(key, value){ for (var i = 0; i < this.arr.length; i++) { if ( this.arr[i].key === key ) { this.arr[i].value = value; return; } } this.arr[this.arr.length] = new struct(key, value);};this.get = function(key) { for (var i = 0; i < this.arr.length; i++) { if ( this.arr[i].key === key ) { return this.arr[i].value; } } return null; }; this.values=function(){ var value=[] for (var i = 0; i < this.arr.length; i++) { value.push(this.arr[i].value); } return value.join(","); }; this.remove = function(key) { var v; for (var i = 0; i < this.arr.length; i++) { v = this.arr.pop(); if ( v.key === key ) { continue; } this.arr.unshift(v); } }; this.size = function() { return this.arr.length; }; this.isEmpty = function() { return this.arr.length <= 0; };}var map = new Map();map.put("a","aaaaaaaaaaaaaaa");map.put("b","bbbbbbbbbbb");map.put("c","cccccccccccccc");map.remove("b");console.info(map.values());
JS實現地圖顯示功可以
嗯~~這個~~先來個簡單的alert..回家補充右側顯示~
<script>
var data = [
'黑龍江' : '黑龍江的說明',
'吉林' : '吉林'
];
function show(e) {
alert(data[e.getAttribute('alt')]);
}
</script>
臨時的..沒測試..回家幫你搞~下班鳥~~
google map怎通過js代碼在自己做的網頁上引用,要:開啟網址可以直接定位到自己指定的那個座標上
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MyHtml2.html</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script src="maps.google.com/...Y0AsbQ"
type="text/javascript"></script>
</head>
<script type="text/javascript">
var map;
function initialize() {
if (GBrowserIsCompatible()) {
map= new GMap2(document.getElementById("mapdiv"));
//設定地圖中心點和縮放層級
map.setCenter(new GLatLng(31.262704744996252, 121.50432586669922), 13);
GEvent.addListener(map,"click", function(overlay,point) {
document.getElementById("x").value=point.x;
document.getElementById("y").value=point.y;
// var center = new GLatLng(point);
var marker = new GMarker(point, {draggable: true});
GEvent.addListener(marker, "dragstart", function() {
map.close......餘下全文>>