2012-06-11 53 views
2

我正在嘗試將本地搜索工具添加到Leaflet JS庫,之前我從未使用它,所以不太清楚如何去做。我已經複製了變焦控制是如何工作的,所以我已經加入此額外功能:將LocalSearch工具添加到Leaflet JS庫

L.Control.LocalSearch = L.Class.extend({ 
onAdd: function (a) { 
    this._map = a, 
    this._container = L.DomUtil.create("div", "leaflet-control-zoom"), 
    this._localSearch = this._createSearch(leafletmapsmarker_L10n.search_form, "leaflet-control-zoom-in", this._map.zoomIn, this._map), 
    this._container.appendChild(this._localSearch) 
}, 
getContainer: function() { 
    return this._container 
}, 
getPosition: function() { 
    return L.Control.Position.BOTTOM_LEFT 
}, 
_createSearch: function (a, b, c, d) { 
    var e = document.createElement("a"); 
    return e.href = "#", 
    e.title = a, 
    e.className = b, 
    L.Browser.touch || L.DomEvent.disableClickPropagation(e), 
    L.DomEvent.addListener(e, "click", L.DomEvent.preventDefault), 
    L.DomEvent.addListener(e, "click", c, d), 
    e 
} 

然後啓動這個像這樣:

_initControls: function() { 
    this.options.searchControl && this.addControl(new L.Control.LocalSearch), this.options.zoomControl && this.addControl(new L.Control.Zoom), this.options.attributionControl && (this.attributionControl = new L.Control.Attribution, this.addControl(this.attributionControl)) 
}, 

所以基本上我需要弄清楚如何添加功能的搜索。也許我會以錯誤的方式進行討論,但是我無法在網絡上找到關於此的很多信息,所以有人能幫我解決這個問題嗎?

回答