转地址:http://www.byywee.com/page/M0/S556/556950.html
搜索关键字: baidu API搜索用户自己数据库里的数据
|
,
new
BMap.Size(json.w,json.h),{imageOffset:
new
BMap.Size(
-
json.l,
-
json.t),infoWindowOffset:
new
BMap.Size(json.lb
+
5
,
1
),offset:
new
BMap.Size(json.x,json.h)})
return
icon; }
function
SearchClass(data){
this
.datas
=
data; }
//
rule = {k:"title",d:"酒店",s:"all",t:"single"}=>t{single:(key=?),more:(key like[%?%])}//t:{single|more},s{all|!all}
SearchClass.prototype.search
=
function
(rule){
if
(
this
.datas
==
null
){alert(
"
数据不存在!
"
);
return
false
;}
if
(
this
.trim(rule)
==
""
||
this
.trim(rule.d)
==
""
||
this
.trim(rule.k)
==
""
||
this
.trim(rule.t)
==
""
){alert(
"
请指定要搜索内容!
"
);
return
false
;}
var
reval
=
[];
var
datas
=
this
.datas;
var
len
=
datas.length;
var
me
=
this
;
var
ruleReg
=
new
RegExp(
this
.trim(rule.d));
var
hasOpen
=
false
;
var
addData
=
function
(data,isOpen){
//
第一条数据打开信息窗口
if
(isOpen
&&
!
hasOpen){ hasOpen
=
true
; data.isOpen
=
1
; }
else
{ data.isOpen
=
0
; } reval.push(data); }
var
getData
=
function
(data,key){
var
ks
=
me.trim(key).split(
/
\.
/
);
var
i
=
null
,s
=
"
data
"
;
if
(ks.length
==
0
){
return
data; }
else
{
for
(
var
i
=
0
; i
<
ks.length; i
++
){ s
+=
""
["
""
+
ks[i]
+
""
"]
""
; }
return
eval(s); } }
for
(
var
cnt
=
0
; cnt
<
len; cnt
++
){
var
data
=
datas[cnt];
var
d
=
getData(data,rule.k);
if
(rule.t
==
"
single
"
&&
rule.d
==
d){ addData(data,
true
); }
else
if
(rule.t
!=
"
single
"
&&
ruleReg.test(d)){ addData(data,
true
); }
else
if
(rule.s
==
"
all
"
){ addData(data,
false
); } }
return
reval; } SearchClass.prototype.setData
=
function
(data){
this
.datas
=
data; } SearchClass.prototype.trim
=
function
(str){
if
(str
==
null
){str
=
""
;}
else
{ str
=
str.toString();}
return
str.replace(
/
(^[\s\t\xa0\u3000]+)|([\u3000\xa0\s\t]+$)
/
g,
""
); } initMap();
//
创建和初始化地图
script
>
四、示例运行请点击以下网址 http://dev.baidu.com/wiki/static/map/API/examples/?v=1.1&3_6#3&6 在新的科学宫里,胜利属于新型的勇敢的人,他们有大胆的科学幻想,心里燃烧着探求新事物的热情。——阿·费尔斯曼 |
|
上海网站建设Copyright 2005-2010 All Rights Reserved 地址:上海市天云路259号 电话:021-57700304 传真:57661889 沪ICP备05011021号 |