| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4bb3043 commit 9cc245e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,7 +98,7 @@ export var DataServiceQueryView = ComponentsViewBase.extend({ | |||
| 98 | 98 | */ | |
| 99 | 99 | setDataServiceUrl(dataServiceUrl) { | |
| 100 | 100 | this.dataServiceUrl = dataServiceUrl; | |
| 101 | - this.viewModel = new DataServiceQueryViewModel(this.dataServiceUrl); | ||
| 101 | + this.viewModel = new DataServiceQueryViewModel(this.dataServiceUrl, this.options.onEachFeature); | ||
| 102 | 102 | ||
| 103 | 103 | }, | |
| 104 | 104 | /** | |
@@ -127,7 +127,7 @@ export var DataServiceQueryView = ComponentsViewBase.extend({ | |||
| 127 | 127 | */ | |
| 128 | 128 | _initView: function () { | |
| 129 | 129 | // 初始化 ViewModel: | |
| 130 | - this.viewModel = new DataServiceQueryViewModel(this.dataServiceUrl); | ||
| 130 | + this.viewModel = new DataServiceQueryViewModel(this.dataServiceUrl, this.options.onEachFeature); | ||
| 131 | 131 | this.messageBox = new MessageBox(); | |
| 132 | 132 | ||
| 133 | 133 | // 组件 container | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,16 +19,18 @@ import { GetFeaturesByGeometryParameters } from '@supermap/iclient-common/iServe | |||
| 19 | 19 | * @version 9.1.1 | |
| 20 | 20 | * @category Components DataServiceQuery | |
| 21 | 21 | * @param {string} dataserviceUrl - 数据服务地址。 | |
| 22 | + * @param {function} onEachFeature - 给该元素绑定事件和弹窗。 | ||
| 22 | 23 | * @fires DataServiceQueryViewModel#getfeaturessucceeded | |
| 23 | 24 | * @fires DataServiceQueryViewModel#getfeaturesfailed | |
| 24 | 25 | * @extends {L.Evented} | |
| 25 | 26 | * @usage | |
| 26 | 27 | */ | |
| 27 | 28 | export class DataServiceQueryViewModel extends L.Evented { | |
| 28 | 29 | ||
| 29 | - initialize(dataserviceUrl) { | ||
| 30 | + initialize(dataserviceUrl, onEachFeature) { | ||
| 30 | 31 | this.dataserviceUrl = dataserviceUrl; | |
| 31 | 32 | this.resultLayers = []; | |
| 33 | + this.onEachFeature = onEachFeature; | ||
| 32 | 34 | } | |
| 33 | 35 | ||
| 34 | 36 | /** | |
@@ -82,9 +84,7 @@ export class DataServiceQueryViewModel extends L.Evented { | |||
| 82 | 84 | return; | |
| 83 | 85 | } | |
| 84 | 86 | let resultLayer = L.geoJSON(serviceResult.result.features, { | |
| 85 | - onEachFeature: function (feature, layer) { | ||
| 86 | - layer.bindPopup("ID: " + feature.properties.SMID); | ||
| 87 | - }, | ||
| 87 | + onEachFeature: this.onEachFeature, | ||
| 88 | 88 | pointToLayer: function (geoJsonPoint, latLng) { | |
| 89 | 89 | return L.circleMarker(latLng, { radius: 6}) | |
| 90 | 90 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ var dataServiceURL = GlobeParameter.dataServiceURL; | |||
| 10 | 10 | describe('leaflet_DataServiceQuery_DataServiceQueryView', () => { | |
| 11 | 11 | var serviceResult; | |
| 12 | 12 | var originalTimeout; | |
| 13 | + var options; | ||
| 13 | 14 | beforeAll(() => { | |
| 14 | 15 | testDiv = document.createElement("div"); | |
| 15 | 16 | testDiv.id = 'map'; | |
@@ -28,7 +29,12 @@ describe('leaflet_DataServiceQuery_DataServiceQueryView', () => { | |||
| 28 | 29 | tiledMapLayer(url).addTo(map); | |
| 29 | 30 | ||
| 30 | 31 | 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); | ||
| 32 | 38 | dataServiceQuery.addTo(map); | |
| 33 | 39 | }); | |
| 34 | 40 | beforeEach(() => { | |
@@ -67,7 +73,7 @@ describe('leaflet_DataServiceQuery_DataServiceQueryView', () => { | |||
| 67 | 73 | expect(features[0].id).toBe(1); | |
| 68 | 74 | expect(features[1].id).toBe(2); | |
| 69 | 75 | expect(features[2].id).toBe(3); | |
| 70 | - | ||
| 76 | + expect(options.onEachFeature).toHaveBeenCalled(); | ||
| 71 | 77 | dataServiceQuery.off("getfeaturessucceeded", callbackFn); | |
| 72 | 78 | done(); | |
| 73 | 79 | } catch (exception) { | |
@@ -337,6 +343,5 @@ describe('leaflet_DataServiceQuery_DataServiceQueryView', () => { | |||
| 337 | 343 | done(); | |
| 338 | 344 | } | |
| 339 | 345 | }) | |
| 340 | - | ||
| 341 | 346 | }); | |
| 342 | 347 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments