2

我正在尝试将本地搜索工具添加到 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))
},

所以基本上我需要弄清楚如何为搜索添加功能。也许我以错误的方式解决这个问题,但我在网上找不到太多关于这个的信息,所以有人可以帮我解决这个问题吗?

4

1 回答 1

0

试试这个新的传单插件: leaflet-search

在这里可以尝试更多的演示:

https://opengeo.tech/maps/leaflet-search/

于 2013-03-02T03:27:22.237 回答