使用函数在kml文件中搜索两个文本值而不仅仅是一个Javascript?

时间:2014-05-13 11:49:04

标签: javascript google-maps kml

好的,我有这个:

filterMarkersstyle: function (text) {
    if (text === undefined || text === null) {
        text = '';
    }
    var t = text.toLowerCase().trim(),
        isVisible,
        ms = this.mapshapes,
        mss, shapeId, it;
    for (shapeId in ms) {
        if (ms.hasOwnProperty(shapeId)) {
            mss = ms[shapeId];
            if (t === undefined && t === '') {
                this.setMapObjectVisibility(mss, true);
            } else {
                descrip = mss.description;
                if (descrip !== undefined) {
                    it = descrip.toLowerCase();
                    isVisible = (it.search(t) !== -1) ? true : false;
                    this.setMapObjectVisibility(mss, isVisible);
                }
            }
        }
    }
},

当前在kml文件中搜索地图标记,如果传递给该功能的文本存在,则将显示设置为可见。
我需要扩展它以处理各种标记类型而不仅仅是一种 我该怎么做?

1 个答案:

答案 0 :(得分:0)

好的,填写一些细节,我最后发送一个正则表达式到kml解析器:

像这样:

var arr = ['place1', 'place2'];
var joined = arr.map(function (val) {
    return val + ' all ' + name;
}).join('|');
var kmlmatcher = '(' + joined + ')';
var regnew = new RegExp(kmlmatcher, "i");
kmlLayer.filterMarkersstyle(regnew);