Skip to content

Commit e73471d

Browse files
committed
优化openlayers DataFlow
1 parent 285de81 commit e73471d

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

dist/iclient9-openlayers.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14037,6 +14037,7 @@ var DataFlow = function (_ol$source$Vector) {
1403714037
excludeField: options.excludeField
1403814038
}));
1403914039

14040+
_this.idField = options.idField || 'id';
1404014041
_this.dataService = new _DataFlowService2.default(options.ws, {
1404114042
geometry: options.geometry,
1404214043
prjCoordSys: options.prjCoordSys,
@@ -14052,8 +14053,10 @@ var DataFlow = function (_ol$source$Vector) {
1405214053
me.dataService.on('setFilterParamSuccessed', function (msg) {
1405314054
me.dispatchEvent({ type: "setFilterParamSuccessed", value: msg });
1405414055
});
14056+
_this.featureCache = {};
1405514057
return _this;
1405614058
}
14059+
1405714060
/**
1405814061
* @function ol.source.DataFlow.prototype.setPrjCoordSys
1405914062
* @description 设置坐标参考系
@@ -14091,8 +14094,14 @@ var DataFlow = function (_ol$source$Vector) {
1409114094
}, {
1409214095
key: "_onMessageSuccessed",
1409314096
value: function _onMessageSuccessed(msg) {
14094-
this.clear();
14095-
this.addFeature(new _olDebug2.default.format.GeoJSON().readFeature(msg.value.featureResult));
14097+
//this.clear();
14098+
var geoID = msg.value.featureResult.properties[this.idField];
14099+
var feature = new _olDebug2.default.format.GeoJSON().readFeature(msg.value.featureResult);
14100+
if (geoID !== undefined && this.featureCache[geoID]) {
14101+
this.removeFeature(this.featureCache[geoID]);
14102+
}
14103+
this.addFeature(feature);
14104+
this.featureCache[geoID] = feature;
1409614105
this.dispatchEvent({ type: "dataUpdated", value: { source: this, data: msg.featureResult } });
1409714106
}
1409814107
}]);

dist/iclient9-openlayers.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/leaflet/dataFlowService.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
1111

1212
<script type="text/javascript" src="http://cdn.bootcss.com/leaflet/1.0.3/leaflet-src.js"></script>
13-
<script type="text/javascript" src="../../dist/iclient9-leaflet.js"></script>
13+
<script type="text/javascript" src="../../dist/iclient9-leaflet.min.js"></script>
1414
<script type="text/javascript">
1515
var map, resultLayer,
1616
urlMap = "http://117.122.248.69:8090/iserver/services/map-china400/rest/maps/China",
@@ -77,7 +77,7 @@
7777
geometry: {coordinates: [point[0], point[1]], type: "Point"},
7878
id: 1,
7979
type: "Feature",
80-
properties: {id: count, time: new Date()}
80+
properties: {id: 1, time: new Date()}
8181
};
8282
dataFlowService.broadcast(feature);
8383
count += 3;

examples/openlayers/dataFlowService.html

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,11 @@
145145
window.clearInterval(timer);
146146
return;
147147
}
148-
if (count == 206) {
149-
source.setGeometry({
150-
coordinates: [[[116.381741960923, 39.8765100055449], [116.414681699817, 39.8765100055449], [116.414681699817, 39.8415115329708], [116.381741960923, 39.8415115329708], [116.381741960923, 39.8765100055449]]],
151-
type: "Polygon"
152-
});
153-
}
154148
var point = featureResult.result.recordsets[0].features.features[0].geometry.coordinates[count];
155149
var feature = {
156150
geometry: {coordinates: [point[0], point[1]], type: "Point"},
157-
id: 1,
158151
type: "Feature",
159-
properties: {id: count, time: new Date()}
152+
properties: {id: 1, time: new Date()}
160153
};
161154
dataFlowService.broadcast(feature);
162155
count += 3;

src/openlayers/overlay/DataFlow.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export default class DataFlow extends ol.source.Vector {
1919
prjCoordSys: options.prjCoordSys,
2020
excludeField: options.excludeField,
2121
});
22+
this.idField=options.idField||'id';
2223
this.dataService = new DataFlowService(options.ws, {
2324
geometry: options.geometry,
2425
prjCoordSys: options.prjCoordSys,
@@ -34,7 +35,9 @@ export default class DataFlow extends ol.source.Vector {
3435
me.dataService.on('setFilterParamSuccessed', function (msg) {
3536
me.dispatchEvent({type: "setFilterParamSuccessed", value: msg})
3637
});
38+
this.featureCache = {};
3739
}
40+
3841
/**
3942
* @function ol.source.DataFlow.prototype.setPrjCoordSys
4043
* @description 设置坐标参考系
@@ -63,8 +66,14 @@ export default class DataFlow extends ol.source.Vector {
6366
}
6467

6568
_onMessageSuccessed(msg) {
66-
this.clear();
67-
this.addFeature((new ol.format.GeoJSON()).readFeature(msg.value.featureResult));
69+
//this.clear();
70+
var geoID = msg.value.featureResult.properties[this.idField];
71+
var feature=(new ol.format.GeoJSON()).readFeature(msg.value.featureResult);
72+
if (geoID !== undefined && this.featureCache[geoID]) {
73+
this.removeFeature(this.featureCache[geoID]);
74+
}
75+
this.addFeature(feature);
76+
this.featureCache[geoID] = feature;
6877
this.dispatchEvent({type: "dataUpdated", value: {source: this, data: msg.featureResult}})
6978
}
7079
}

0 commit comments

Comments
 (0)