Skip to content

Commit 4c4e7ee

Browse files
committed
【fix/API/UT】 fix POI搜索微件不可用问题 review by zhurc
1 parent d592832 commit 4c4e7ee

File tree

8 files changed

+1125
-1057
lines changed

8 files changed

+1125
-1057
lines changed

dist/leaflet/iclient9-leaflet-es6.js

Lines changed: 83 additions & 61 deletions
Large diffs are not rendered by default.

dist/leaflet/iclient9-leaflet-es6.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/leaflet/iclient9-leaflet.js

Lines changed: 778 additions & 751 deletions
Large diffs are not rendered by default.

dist/leaflet/iclient9-leaflet.min.js

Lines changed: 157 additions & 156 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/leaflet/widgets/dataflow/DataFlowViewModel.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {CommontypesConversion} from '../../core/CommontypesConversion';
1111
* @classdesc 数据流微件功能类。
1212
* @version 9.1.1
1313
* @category Widgets DataFlow
14-
* @param {L.Map} map - 当前微件所在的底图
14+
* @param {L.Map} map - 当前微件所在的地图
1515
* @param {Object} [dataFlowLayerOptions] - 数据流服务返回数据数据展示样式,默认采用 ViewModel 默认样式。
1616
* @param {Object} options - 可选参数。
1717
* @param {Function} [options.style] - 定义点、线、面要素样式。参数为{@link L.Path-option}。</br>
@@ -49,7 +49,7 @@ export var DataFlowViewModel = L.Evented.extend({
4949
if (map) {
5050
/**
5151
* @member {L.Map} [L.supermap.widgets.dataFlowViewModel.prototype.map]
52-
* @description 当前微件所在的底图
52+
* @description 当前微件所在的地图
5353
*/
5454
this.map = map;
5555
} else {

src/leaflet/widgets/search/SearchView.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,27 @@ import {
3131
* @param {Object|Array.<string>} [options.cityConfig] - 城市地址匹配配置,默认为全国城市,与 options.cityGeoCodingConfig 支持匹配的服务对应;
3232
* 配置两种格式:{key1:{A:[],B:[]}, key2:{C:[],D:[]}} 或 ["成都市","北京市"],用户可根据自己的项目需求进行配置
3333
* @param {Object} [options.cityGeoCodingConfig] - 城市地址匹配服务配置,包括:{addressUrl:"",key:""} 默认为 online 地址匹配服务,与 options.cityConfig 对应
34-
* @param {boolean} [options.isGeoCoding=true] - 是否支持城市地址匹配功能
34+
* @param {boolean} [options.isGeoCoding=true] - 是否支持城市地址匹配功能。
35+
* @param {boolean} [options.pageSize=10] - 返回记录结果数,最大设置为 20。
36+
* @param {boolean} [options.pageNum=1] - 分页页码,默认 1 代表第一页。
3537
* @param {string} [options.position='topright'] - 微件在地图中显示的位置,包括:'topleft','topright','bottomleft' 和 'bottomright',继承自 leaflet control。
3638
* @param {function} [options.style] - 设置图层点线面默认样式,点样式返回 maker 或者 circleMaker;线和面返回 L.path 样式。
3739
* @param {function} [options.onEachFeature] - 在创建和设置样式后,将为每个创建的要素调用一次的函数。用于将事件和弹出窗口附加到要素。默认情况下,对新创建的图层不执行任何操作。
3840
* @extends {L.Control}
39-
* @fires L.supermap.widgets.search#searchsucceed
41+
* @fires L.supermap.widgets.search#searchlayersucceed
4042
* @fires L.supermap.widgets.search#searchfailed
43+
* @fires L.supermap.widgets.search#geocodesucceed
4144
*/
4245
export var SearchView = WidgetsViewBase.extend({
4346
options: {
4447
cityConfig: config,
4548
cityGeoCodingConfig: {
46-
addressUrl: "http://www.supermapol.com/iserver/services/location-china/rest/locationanalyst/China",
49+
addressUrl: "http://www.supermapol.com/iserver/services/localsearch/rest/searchdatas/China/poiinfos",
4750
key: "fvV2osxwuZWlY0wJb8FEb2i5"
4851
},
49-
isGeoCoding: true
52+
isGeoCoding: true,
53+
pageSize: 10,
54+
pageNum: 1
5055
},
5156

5257
initialize(options) {
@@ -55,6 +60,7 @@ export var SearchView = WidgetsViewBase.extend({
5560
this.currentSearchLayerName = "";
5661
this.isSearchLayer = false;
5762
},
63+
5864
/*------以下是一些接口-----*/
5965
/**
6066
* @function L.supermap.widgets.search.prototype.onAdd
@@ -67,6 +73,7 @@ export var SearchView = WidgetsViewBase.extend({
6773
this.viewModel = new SearchViewModel(map, this.options);
6874
return WidgetsViewBase.prototype.onAdd.apply(this, [map]);
6975
},
76+
7077
/**
7178
* @function L.supermap.widgets.search.prototype.addSearchLayer
7279
* @description 添加可查询的图层。
@@ -457,7 +464,7 @@ export var SearchView = WidgetsViewBase.extend({
457464
});
458465

459466
//----图层查询结果监听
460-
this.viewModel.on("searchsucceed", (e) => {
467+
this.viewModel.on("searchlayersucceed", (e) => {
461468
const data = e.result;
462469
this.clearSearchResult();
463470
this.searchResultLayer = L.featureGroup(data, {
@@ -470,7 +477,12 @@ export var SearchView = WidgetsViewBase.extend({
470477

471478
//查询结果列表:
472479
this._prepareResultData(data);
473-
this._event.fire("searchsucceed", {
480+
/**
481+
* @event L.supermap.widgets.search#searchlayersucceed
482+
* @description 图层查询成功后触发。
483+
* @property {Object} result - 事件返回的 GeoJSON 格式数据对象。
484+
*/
485+
this._event.fire("searchlayersucceed", {
474486
result: this.searchResultLayer.toGeoJSON()
475487
});
476488
});
@@ -492,11 +504,11 @@ export var SearchView = WidgetsViewBase.extend({
492504
//查询结果列表:
493505
this._prepareResultData(data);
494506
/**
495-
* @event L.supermap.widgets.search#searchsucceed
496-
* @description 数据流服务成功返回数据后触发
507+
* @event L.supermap.widgets.search#geocodesucceed
508+
* @description 地址匹配服务成功后触发
497509
* @property {Object} result - 事件返回的 GeoJSON 格式数据对象。
498510
*/
499-
this._event.fire("searchsucceed", { result: data });
511+
this._event.fire("geocodesucceed", { result: data });
500512
});
501513

502514
//----地址匹配或图层查询失败监听

src/leaflet/widgets/search/SearchViewModel.js

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,8 @@
44
import L from "leaflet";
55
import '../../core/Base';
66
import {
7-
GeoCodingParameter
7+
FetchRequest
88
} from '@supermap/iclient-common';
9-
import {
10-
AddressMatchService
11-
} from '../../services/AddressMatchService';
129
import {
1310
GeoJsonLayersDataModel
1411
} from '../commonmodels/GeoJsonLayersModel';
@@ -19,16 +16,16 @@ import {
1916
* @version 9.1.1
2017
* @category Widgets Search
2118
* @param {Object} options - 可选参
22-
* @param {Object} [options.cityGeoCodingConfig] - 城市地址匹配服务配置,包括:{addressUrl:"",key:""} 默认为 online 地址匹配服务,与 options.cityConfig 对应
19+
* @param {Object} [options.cityGeoCodingConfig] - 城市地址匹配服务配置,包括:{addressUrl:"",key:""} 默认为 online 本地搜索服务
2320
* @fires L.supermap.widgets.searchViewModel#newlayeradded
24-
* @fires L.supermap.widgets.searchViewModel#searchsucceed
21+
* @fires L.supermap.widgets.searchViewModel#searchlayersucceed
2522
* @fires L.supermap.widgets.searchViewModel#searchfailed
2623
* @fires L.supermap.widgets.searchViewModel#geocodesucceed
2724
*/
2825
export var SearchViewModel = L.Evented.extend({
2926
options: {
3027
cityGeoCodingConfig: {
31-
addressUrl: "http://www.supermapol.com/iserver/services/location-china/rest/locationanalyst/China",
28+
addressUrl: "http://www.supermapol.com/iserver/services/localsearch/rest/searchdatas/China/poiinfos",
3229
key: "fvV2osxwuZWlY0wJb8FEb2i5"
3330
}
3431
},
@@ -37,7 +34,7 @@ export var SearchViewModel = L.Evented.extend({
3734
if (map) {
3835
/**
3936
* @member {L.Map} [L.supermap.widgets.searchViewModel.prototype.map]
40-
* @description 当前微件所在的底图
37+
* @description 当前微件所在的地图
4138
*/
4239
this.map = map;
4340
} else {
@@ -49,29 +46,25 @@ export var SearchViewModel = L.Evented.extend({
4946
this.dataModel = new GeoJsonLayersDataModel();
5047
//初始话地址匹配服务
5148

52-
this.geoCodeService = new AddressMatchService(this.options.cityGeoCodingConfig.addressUrl);
53-
this.geoCodeParam = new GeoCodingParameter({
54-
address: null,
49+
this.geoCodeParam = {
50+
keyWords: '北京市',
5551
city: "北京市",
56-
maxResult: 70,
57-
prjCoordSys: JSON.stringify({
58-
epsgCode: 4326
59-
}),
60-
key: this.options.cityGeoCodingConfig.key
61-
});
52+
pageSize: this.options.pageSize,
53+
pageNum: this.options.pageNum
54+
};
6255
//查询缓存
6356
this.searchCache = {};
6457
},
6558

6659
/**
6760
* @function L.supermap.widgets.searchViewModel.prototype.search
6861
* @description 查询。
69-
* @param {string} keyWord - 查询的关键字。
62+
* @param {string} keyWords - 查询的关键字。
7063
* @param {string} [searchLayerName] - 执行的查询类型,支执行矢量图层属性查询,当为 "geocode" 则执行地址匹配。
7164
*/
7265
search(keyWord, searchLayerName) {
7366
if (!searchLayerName) {
74-
this.searchFromCityGeocodeService(keyWord);
67+
this.searchFromCityLocalSearchService(keyWord);
7568
} else {
7669
this.searchFromLayer(keyWord, searchLayerName);
7770
}
@@ -88,11 +81,11 @@ export var SearchViewModel = L.Evented.extend({
8881
let resultFeatures = this.dataModel.layers[searchLayerName].getFeaturesByKeyWord(keyWord);
8982
if (resultFeatures && resultFeatures.length > 0) {
9083
/**
91-
* @event L.supermap.widgets.searchViewModel#searchsucceed
84+
* @event L.supermap.widgets.searchViewModel#searchlayersucceed
9285
* @description 图层属性查询成功后触发。
9386
* @property {Object} result - 图层数据。
9487
*/
95-
this.fire("searchsucceed", {
88+
this.fire("searchlayersucceed", {
9689
result: resultFeatures
9790
});
9891
} else {
@@ -109,11 +102,11 @@ export var SearchViewModel = L.Evented.extend({
109102
},
110103

111104
/**
112-
* @function L.supermap.widgets.searchViewModel.prototype.searchFromCityGeocodeService
105+
* @function L.supermap.widgets.searchViewModel.prototype.searchFromCityLocalSearchService
113106
* @description 城市地址匹配查询。
114107
* @param {string} keyWords - 城市地址匹配查询关键字。
115108
*/
116-
searchFromCityGeocodeService(keyWords) {
109+
searchFromCityLocalSearchService(keyWords) {
117110
//todo 是否保留缓存?请求过的数据保留一份缓存?
118111
if (this.searchCache[keyWords]) {
119112
/**
@@ -125,23 +118,25 @@ export var SearchViewModel = L.Evented.extend({
125118
result: this.searchCache[keyWords]
126119
});
127120
} else {
128-
this.geoCodeParam.address = keyWords;
121+
this.geoCodeParam.keyWords = keyWords || this.geoCodeParam.city;
129122
const self = this;
130-
this.geoCodeService.code(this.geoCodeParam, (geocodingResult) => {
131-
if (geocodingResult.result) {
132-
if (geocodingResult.result.error || geocodingResult.result.length === 0) {
133-
self.fire("searchfailed", {
134-
searchType: "searchGeocodeField"
135-
});
136-
return;
137-
}
138-
const geoJsonResult = self._dataToGeoJson(geocodingResult.result,self.geoCodeParam);
123+
let url = this._getSearchUrl(this.geoCodeParam);
124+
FetchRequest.get(url).then((response) => {
125+
return response.json();
126+
}).then((geocodingResult) => {
127+
if (geocodingResult.error || geocodingResult.poiInfos.length === 0) {
128+
self.fire("searchfailed", {
129+
searchType: "searchGeocodeField"
130+
});
131+
return;
132+
}
133+
if (geocodingResult.poiInfos) {
134+
const geoJsonResult = self._dataToGeoJson(geocodingResult.poiInfos, self.geoCodeParam);
139135
self.fire("geocodesucceed", {
140136
result: geoJsonResult
141137
});
142138
}
143-
144-
});
139+
})
145140
}
146141
},
147142

@@ -181,30 +176,32 @@ export var SearchViewModel = L.Evented.extend({
181176
* @param {string} city - 指定缩放的城市名。
182177
*/
183178
panToCity(city) {
184-
this.geoCodeParam.address = city;
179+
this.geoCodeParam.keyWords = city;
185180
this.geoCodeParam.city = city;
186181
const self = this;
187-
this.geoCodeService.code(this.geoCodeParam, (geocodingResult) => {
188-
if (geocodingResult.result.length > 0) {
182+
let url = this._getSearchUrl(this.geoCodeParam);
183+
FetchRequest.get(url).then((response) => {
184+
return response.json();
185+
}).then((geocodingResult) => {
186+
if (geocodingResult.poiInfos.length > 0) {
189187
//缩放至城市
190-
const center = L.latLng(geocodingResult.result[0].location.y, geocodingResult.result[0].location.x);
188+
const center = L.latLng(geocodingResult.poiInfos[0].location.y, geocodingResult.poiInfos[0].location.x);
191189
self.map.setView(center, 8);
192190
} else {
193191
self.fire("searchfailed", {
194192
searchType: "cityGeocodeField"
195193
});
196194
}
197-
198-
});
199-
195+
})
200196
},
201197

198+
202199
/**
203200
* @description 将地址匹配返回的数据转为geoJson 格式数据
204201
* @param data
205202
* @private
206203
*/
207-
_dataToGeoJson(data,geoCodeParam) {
204+
_dataToGeoJson(data, geoCodeParam) {
208205
let features = [];
209206
for (let i = 0; i < data.length; i++) {
210207
let feature = {
@@ -214,16 +211,27 @@ export var SearchViewModel = L.Evented.extend({
214211
coordinates: [data[i].location.x, data[i].location.y]
215212
},
216213
properties: {
217-
name: data[i].name || geoCodeParam.address,
214+
name: data[i].name || geoCodeParam.keyWords,
218215
address: data[i].formatedAddress || data[i].address
219216
}
220217
};
221218
features.push(feature);
222219
}
223220

224221
return features;
225-
}
222+
},
226223

224+
/**
225+
* /**
226+
* @function L.supermap.widgets.searchViewModel.prototype._getSearchUrl
227+
* @description 获取地理编码查询地址。
228+
* @param {Object} geoCodeParam - 地理编码查询参数。
229+
* @private
230+
*/
231+
_getSearchUrl(geoCodeParam) {
232+
let url = this.options.cityGeoCodingConfig.addressUrl + `.json?keywords=${geoCodeParam.keyWords}&city=${geoCodeParam.city}&pageSize=${geoCodeParam.pageSize}&pageNum=${geoCodeParam.pageNum}&key=${this.options.cityGeoCodingConfig.key}`;
233+
return url;
234+
}
227235
});
228236

229237
export var searchViewModel = function (options) {

0 commit comments

Comments
 (0)