var BMapLib = window.BMapLib = BMapLib || {}; (function() { var baidu = baidu || { guid : "$BAIDU$" }; (function() { window[baidu.guid] = {}; baidu.extend = function(target, source) { for ( var p in source) { if (source.hasOwnProperty(p)) { target[p] = source[p]; } } return target; }; baidu.lang = baidu.lang || {}; baidu.lang.guid = function() { return "TANGRAM__" + (window[baidu.guid]._counter++).toString(36); }; window[baidu.guid]._counter = window[baidu.guid]._counter || 1; window[baidu.guid]._instances = window[baidu.guid]._instances || {}; baidu.lang.Class = function(guid) { this.guid = guid || baidu.lang.guid(); window[baidu.guid]._instances[this.guid] = this; }; window[baidu.guid]._instances = window[baidu.guid]._instances || {}; baidu.lang.isString = function(source) { return "[object String]" == Object.prototype.toString.call(source); }; baidu.lang.isFunction = function(source) { return "[object Function]" == Object.prototype.toString .call(source); }; baidu.lang.Class.prototype.toString = function() { return "[object " + (this._className || "Object") + "]"; }; baidu.lang.Event = function(type, target) { this.type = type; this.returnValue = true; this.target = target || null; this.currentTarget = null; }; baidu.lang.Class.prototype.addEventListener = function(type, handler, key) { if (!baidu.lang.isFunction(handler)) { return; } !this.__listeners && (this.__listeners = {}); var t = this.__listeners, id; if (typeof key == "string" && key) { if (/[^\w\-]/.test(key)) { throw ("nonstandard key:" + key); } else { handler.hashCode = key; id = key; } } type.indexOf("on") != 0 && (type = "on" + type); typeof t[type] != "object" && (t[type] = {}); id = id || baidu.lang.guid(); handler.hashCode = id; t[type][id] = handler; }; baidu.lang.Class.prototype.removeEventListener = function(type, handler) { if (baidu.lang.isFunction(handler)) { handler = handler.hashCode; } else { if (!baidu.lang.isString(handler)) { return; } } !this.__listeners && (this.__listeners = {}); type.indexOf("on") != 0 && (type = "on" + type); var t = this.__listeners; if (!t[type]) { return; } t[type][handler] && delete t[type][handler]; }; baidu.lang.Class.prototype.dispatchEvent = function(event, options) { if (baidu.lang.isString(event)) { event = new baidu.lang.Event(event); } !this.__listeners && (this.__listeners = {}); options = options || {}; for ( var i in options) { event[i] = options[i]; } var i, t = this.__listeners, p = event.type; event.target = event.target || this; event.currentTarget = this; p.indexOf("on") != 0 && (p = "on" + p); baidu.lang.isFunction(this[p]) && this[p].apply(this, arguments); if (typeof t[p] == "object") { for (i in t[p]) { t[p][i].apply(this, arguments); } } return event.returnValue; }; baidu.lang.inherits = function(subClass, superClass, className) { var key, proto, selfProps = subClass.prototype, clazz = new Function(); clazz.prototype = superClass.prototype; proto = subClass.prototype = new clazz(); for (key in selfProps) { proto[key] = selfProps[key]; } subClass.prototype.constructor = subClass; subClass.superClass = superClass.prototype; if ("string" == typeof className) { proto._className = className; } ; }; baidu.dom = baidu.dom || {}; baidu.g = baidu.dom.g = function(id) { if ("string" == typeof id || id instanceof String) { return document.getElementById(id); } else { if (id && id.nodeName && (id.nodeType == 1 || id.nodeType == 9)) { return id; } } return null; }; baidu.browser = baidu.browser || {}; if (/msie (\d+\.\d)/i.test(navigator.userAgent)) { baidu.browser.ie = baidu.ie = document.documentMode || +RegExp["\x241"]; } baidu.dom._NAME_ATTRS = (function() { var result = { cellpadding : "cellPadding", cellspacing : "cellSpacing", colspan : "colSpan", rowspan : "rowSpan", valign : "vAlign", usemap : "useMap", frameborder : "frameBorder" }; if (baidu.browser.ie < 8) { result["for"] = "htmlFor"; result["class"] = "className"; } else { result.htmlFor = "for"; result.className = "class"; } return result; })(); baidu.getAttr = baidu.dom.getAttr = function(element, key) { element = baidu.dom.g(element); if ("style" == key) { return element.style.cssText; } key = baidu.dom._NAME_ATTRS[key] || key; return element.getAttribute(key); }; baidu.event = baidu.event || {}; baidu.event._listeners = baidu.event._listeners || []; baidu.on = baidu.event.on = function(element, type, listener) { type = type.replace(/^on/i, ""); element = baidu.g(element); var realListener = function(ev) { listener.call(element, ev); }, lis = baidu.event._listeners, filter = baidu.event._eventFilter, afterFilter, realType = type; type = type.toLowerCase(); if (filter && filter[type]) { afterFilter = filter[type](element, type, realListener); realType = afterFilter.type; realListener = afterFilter.listener; } if (element.addEventListener) { element.addEventListener(realType, realListener, false); } else { if (element.attachEvent) { element.attachEvent("on" + realType, realListener); } } lis[lis.length] = [ element, type, listener, realListener, realType ]; return element; }; })(); BMapLib.COUNTRY_TYPE_CODE = 0; BMapLib.PROVINCE_TYPE_CODE = 1; BMapLib.CITY_TYPE_CODE = 2; var CityList = BMapLib.CityList = function(opts) { opts = opts || {}; this._opts = baidu.extend(baidu.extend(this._opts || {}, { container : null, map : null }), opts); this._data = null; this._css = [ ".bmaplib_cityList{color:#333;font:12px arial,sans-serif;padding-left:10px;}", ".bmaplib_cityList h4{font-size:12px;font-weight:normal;margin:0;}", ".bmaplib_cityList hr{height:1px;border-top:solid 1px #ccc; border-bottom:none;}", ".bmaplib_cityList form,.bmaplib_cityList dl{margin:0;}", ".bmaplib_cityList dd,.bmaplib_cityList h4,.bmaplib_cityList dt{padding: 2px 0; vertical-align: top;line-height: 150%;}", ".bmaplib_cityList dt{float:left;width:52px;}", ".bmaplib_cityList dd{margin-left:52px;}", ".bmaplib_cityList a{color:#0000CC;text-decoration:underline;outline:none;margin-right: 8px;}", ".bmaplib_cityList dt a{margin-right:0;}", ".bmaplib_cityListDescript{color:#999;}", ".bmaplib_cityList .black{color:#000;}", ".bmaplib_cityList form span{color:red;}" ]; this._getDataFromMapServer(); }; baidu.lang.inherits(CityList, baidu.lang.Class, "CityList"); var _citylistCount = 1; var _outputData = null; CityList.prototype._getDataFromMapServer = function() { var me = this; scriptRequest( "http://api.map.baidu.com/library/CityList/1.2/src/data/CityData.js", function() { me._callback(); }); }; CityList.prototype._callback = function() { if (BMapLib.CityList._cityData) { this._data = BMapLib.CityList._cityData; BMapLib.CityList._cityData = null; _outputData = this._formatCityData(this._data); this._renderHtml(); this._bind(); } }; CityList.prototype._renderHtml = function() { if (!this._opts.container || !baidu.g(this._opts.container)) { return } this._execCss(); var htm = [], data = this._data, vds = "javascript:void(0)", newData = {}; htm.push("