Skip to content

Commit 9cc245e

Browse files
fix icl-1517 Leaflet使用DataServiceQueryView,设置onEachFeature不生效 review by luox
1 parent 4bb3043 commit 9cc245e

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

src/leaflet/components/dataservicequery/DataServiceQueryView.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export var DataServiceQueryView = ComponentsViewBase.extend({
9898
*/
9999
setDataServiceUrl(dataServiceUrl) {
100100
this.dataServiceUrl = dataServiceUrl;
101-
this.viewModel = new DataServiceQueryViewModel(this.dataServiceUrl);
101+
this.viewModel = new DataServiceQueryViewModel(this.dataServiceUrl, this.options.onEachFeature);
102102

103103
},
104104
/**
@@ -127,7 +127,7 @@ export var DataServiceQueryView = ComponentsViewBase.extend({
127127
*/
128128
_initView: function () {
129129
// 初始化 ViewModel:
130-
this.viewModel = new DataServiceQueryViewModel(this.dataServiceUrl);
130+
this.viewModel = new DataServiceQueryViewModel(this.dataServiceUrl, this.options.onEachFeature);
131131
this.messageBox = new MessageBox();
132132

133133
// 组件 container

src/leaflet/components/dataservicequery/DataServiceQueryViewModel.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,18 @@ import { GetFeaturesByGeometryParameters } from '@supermap/iclient-common/iServe
1919
* @version 9.1.1
2020
* @category Components DataServiceQuery
2121
* @param {string} dataserviceUrl - 数据服务地址。
22+
* @param {function} onEachFeature - 给该元素绑定事件和弹窗。
2223
* @fires DataServiceQueryViewModel#getfeaturessucceeded
2324
* @fires DataServiceQueryViewModel#getfeaturesfailed
2425
* @extends {L.Evented}
2526
* @usage
2627
*/
2728
export class DataServiceQueryViewModel extends L.Evented {
2829

29-
initialize(dataserviceUrl) {
30+
initialize(dataserviceUrl, onEachFeature) {
3031
this.dataserviceUrl = dataserviceUrl;
3132
this.resultLayers = [];
33+
this.onEachFeature = onEachFeature;
3234
}
3335

3436
/**
@@ -82,9 +84,7 @@ export class DataServiceQueryViewModel extends L.Evented {
8284
return;
8385
}
8486
let resultLayer = L.geoJSON(serviceResult.result.features, {
85-
onEachFeature: function (feature, layer) {
86-
layer.bindPopup("ID: " + feature.properties.SMID);
87-
},
87+
onEachFeature: this.onEachFeature,
8888
pointToLayer: function (geoJsonPoint, latLng) {
8989
return L.circleMarker(latLng, { radius: 6})
9090
}

test/leaflet/components/dataservicequery/DataServiceQueryViewSpec.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var dataServiceURL = GlobeParameter.dataServiceURL;
1010
describe('leaflet_DataServiceQuery_DataServiceQueryView', () => {
1111
var serviceResult;
1212
var originalTimeout;
13+
var options;
1314
beforeAll(() => {
1415
testDiv = document.createElement("div");
1516
testDiv.id = 'map';
@@ -28,7 +29,12 @@ describe('leaflet_DataServiceQuery_DataServiceQueryView', () => {
2829
tiledMapLayer(url).addTo(map);
2930

3031
var dataSetNames = ['World:Countries'];
31-
dataServiceQuery = dataServiceQueryView(dataServiceURL, dataSetNames);
32+
options = {
33+
onEachFeature(feature, layer) {
34+
}
35+
}
36+
spyOn(options, 'onEachFeature');
37+
dataServiceQuery = dataServiceQueryView(dataServiceURL, dataSetNames, options);
3238
dataServiceQuery.addTo(map);
3339
});
3440
beforeEach(() => {
@@ -67,7 +73,7 @@ describe('leaflet_DataServiceQuery_DataServiceQueryView', () => {
6773
expect(features[0].id).toBe(1);
6874
expect(features[1].id).toBe(2);
6975
expect(features[2].id).toBe(3);
70-
76+
expect(options.onEachFeature).toHaveBeenCalled();
7177
dataServiceQuery.off("getfeaturessucceeded", callbackFn);
7278
done();
7379
} catch (exception) {
@@ -337,6 +343,5 @@ describe('leaflet_DataServiceQuery_DataServiceQueryView', () => {
337343
done();
338344
}
339345
})
340-
341346
});
342347

0 commit comments

Comments
 (0)