主题: 百度地图官方代码问题,第二次修正
作者: 丰收之歌, 发布日期: 2013-04-13 09:21:16, 浏览数: 2382
function replaceBaiduMapString(s) {
    var v = s;
    if (v.indexOf("//创建InfoWindow") != -1) {
        var sIndex_0 = v.indexOf("//标注点数组");
        var eIndex_0 = v.indexOf("//创建marker");
        var sStr_0 = v.substring(0, sIndex_0);
        var eStr_0 = v.substring(sIndex_0, eIndex_0);
        eStr_0="//标注点数组\n" + eStr_0.substr("//标注点数组".length).replace(/\s+/, "").replace(/[^}]+$/, "];")+"\n";
        var sIndex_1 = v.indexOf("//创建InfoWindow");
        var eIndex_1 = v.indexOf("//创建一个Icon");
        var sStr_1 = v.substring(eIndex_0 , sIndex_1);
        var eStr_1 = v.substring(eIndex_1, v.length);

        v = sStr_0 + eStr_0+sStr_1 + "\/\/创建InfoWindow\n";
        v += "function createInfoWindow(i){\n";
        v += "var json = markerArr[i];\n";
        v += "var iw = new BMap.InfoWindow(\"<b class='iw_poi_title' title='\" + json.title + \"'>\" + json.title + \"</b><div class='iw_poi_content'>\"+json.content+\"</div>\");\n";
        v += "return iw;\n";
        v += "}\n";
        v += eStr_1;
        return v;
    }
    return s;

}

function addEvent(obj, evt, fn) {
            if (document.all) {
                obj.attachEvent("on" + evt, function () {
                    fn.call(obj, window.event)
                });

            }
            else {
                obj.addEventListener(evt, fn, false);
            }
        }

 KindEditor.ready(function (K) {
            editor = K.create('textarea[name="content1"]', {
                filterMode: false,
                cssPath: '/Manage/js/kindeditor/plugins/code/prettify.css',
                uploadJson: '/Manage/Server/UpMorePic.aspx?cmd=editor&wsid=<%=wsID%>&token=<%=token%>', ///Manage/js/kindeditor/asp.net/upload_json.ashx
                fileManagerJson: '/Manage/js/kindeditor/asp.net/file_manager_json.ashx?wsid=<%=wsID%>&token=<%=token%>',
                allowFileManager: true,
                items: keExtend.items
            });
            addEvent(document.forms[0], "submit", function () {//对百度地图代码进行处理
                var v = document.getElementById("content1").value;
                if (v.indexOf("//创建InfoWindow") != -1) {
                   v=replaceBaiduMapString(v);
                    document.getElementById("content1").value = v;
                }
            });
        });


发表新帖 发表回复