diff --git a/src/leaflet/components/search/SearchView.js b/src/leaflet/components/search/SearchView.js index da55b7e80..25407a52a 100644 --- a/src/leaflet/components/search/SearchView.js +++ b/src/leaflet/components/search/SearchView.js @@ -664,8 +664,10 @@ export var SearchView = ComponentsViewBase.extend({ this.map.closePopup(); //若当前是查询图层的结果,则不删除图层,只修改样式 !this.isSearchLayer && this.map.removeLayer(this.searchResultLayer); - this._selectMarkerFeature && this.map.removeLayer(this._selectMarkerFeature); - this._selectFeaturethis && this.map.removeLayer(this._selectFeature); + if (this._selectMarkerFeature) { + this.map.removeLayer(this._selectMarkerFeature); + this.isSearchLayer && this._selectFeature.addTo(this.map); + } this._selectMarkerFeature = null; this._selectFeature = null; this.searchResultLayer = null; @@ -737,7 +739,7 @@ export var SearchView = ComponentsViewBase.extend({ return L.marker(latlng, { icon: L.divIcon({ className: 'component-select-marker-icon', - iconAnchor: [15, 0] + iconAnchor: [15, 42] }) }) }, @@ -755,7 +757,8 @@ export var SearchView = ComponentsViewBase.extend({ attributes: layer.feature.properties })).getElement() }, { - closeOnClick: false + closeOnClick: false, + offset: [0, -36] }).openPopup().addTo(this.map); this._flyToBounds(this.searchResultLayer.getBounds()); diff --git a/test/leaflet/components/search/SearchViewSpec.js b/test/leaflet/components/search/SearchViewSpec.js index 5e28e07ea..cad5a1533 100644 --- a/test/leaflet/components/search/SearchViewSpec.js +++ b/test/leaflet/components/search/SearchViewSpec.js @@ -192,4 +192,16 @@ describe('leaflet_search_SearchView', () => { document.getElementsByClassName('component-citytabpag__content')[0].childNodes[0].click(); }) + + it('clearSearchResult', (done) => { + poiSearch._selectMarkerFeature = {}; + poiSearch.isSearchLayer = true; + poiSearch._selectFeature = { + addTo: () => {} + }; + const spy = spyOn(poiSearch._selectFeature, 'addTo'); + poiSearch.clearSearchResult(); + expect(spy).toHaveBeenCalled(); + done(); + }) })