Skip to content

Commit 5948ede

Browse files
committed
【feature】1) webmap 保持和dv专题图feature格式统一
(reviewed by chengl)
1 parent 49c6307 commit 5948ede

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

src/openlayers/core/Util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ export class Util {
393393
let properties = [];
394394
if (Util.isArray(features) && features.length) {
395395
features.forEach(feature => {
396-
let property = feature.attributes || feature.get('Properties');
396+
let property = feature.get('attributes');
397397
property && properties.push(property);
398398
});
399399
}

src/openlayers/mapping/WebMap.js

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,9 +1470,8 @@ export class WebMap extends ol.Observable {
14701470
}
14711471
let feature = new ol.Feature({
14721472
geometry: olGeom,
1473-
Properties: attributes
1473+
attributes: attributes
14741474
});
1475-
feature.attributes = attributes;
14761475
features.push(feature);
14771476
}
14781477
}
@@ -1490,6 +1489,9 @@ export class WebMap extends ol.Observable {
14901489
let allFeatures = geojson.features,
14911490
features = [];
14921491
for (let i = 0, len = allFeatures.length; i < len; i++) {
1492+
//转换前删除properties,这样转换后属性不会重复存储
1493+
let featureAttr = allFeatures[i].properties || {};
1494+
delete allFeatures[i].properties;
14931495
let feature = transformTools.readFeature(allFeatures[i], {
14941496
dataProjection: layerInfo.projection || 'EPSG:4326',
14951497
featureProjection: this.baseProjection || 'ESPG:4326'
@@ -1503,15 +1505,14 @@ export class WebMap extends ol.Observable {
15031505
allFeatures[i].properties.lat = coordinate[1];
15041506
}
15051507
}
1506-
feature.attributes = allFeatures[i].properties || {};
15071508

15081509
// 标注图层特殊处理
15091510
let isMarker = false;
15101511
let attributes;
15111512
let useStyle;
15121513
if (allFeatures[i].dv_v5_markerInfo) {
15131514
//因为优化代码之前,属性字段都存储在propertise上,markerInfo没有
1514-
attributes = Object.assign({}, allFeatures[i].dv_v5_markerInfo, feature.attributes);
1515+
attributes = Object.assign({}, allFeatures[i].dv_v5_markerInfo, featureAttr);
15151516
if(attributes.lon) {
15161517
//标注图层不需要
15171518
delete attributes.lon;
@@ -1531,13 +1532,10 @@ export class WebMap extends ol.Observable {
15311532
});
15321533
//feature上添加图层的id,为了对应图层
15331534
feature.layerId = layerInfo.timeId;
1534-
//删除不需要的属性,因为这两个属性存储在properties上
1535-
delete feature.attributes.attributes;
1536-
delete feature.attributes.useStyle;
15371535
} else if (layerInfo.featureStyles) {
15381536
//V4 版本标注图层处理
15391537
let style = JSON.parse(layerInfo.featureStyles[i].style);
1540-
let attr = feature.attributes;
1538+
let attr = featureAttr;
15411539
let imgUrl;
15421540
if (attr._smiportal_imgLinkUrl.indexOf('http://') > -1 || attr._smiportal_imgLinkUrl.indexOf('https://') > -1) {
15431541
imgUrl = attr._smiportal_imgLinkUrl;
@@ -1566,7 +1564,7 @@ export class WebMap extends ol.Observable {
15661564
delete attr._smiportal_title;
15671565
delete attr._smiportal_otherLinkUrl;
15681566
} else {
1569-
properties = feature.attributes;
1567+
properties = {attributes: featureAttr};
15701568
}
15711569

15721570
feature.setProperties(properties);
@@ -1586,19 +1584,20 @@ export class WebMap extends ol.Observable {
15861584
let allFeatures = metaData.allDatas.features,
15871585
features = [];
15881586
for (let i = 0, len = allFeatures.length; i < len; i++) {
1587+
let properties = allFeatures[i].properties;
1588+
delete allFeatures[i].properties;
15891589
let feature = transformTools.readFeature(allFeatures[i], {
15901590
dataProjection: metaData.fileCode || 'EPSG:4326',
15911591
featureProjection: metaData.featureProjection || Util.getBaseLayerProj() || 'EPSG:4326'
15921592
});
15931593
//geojson格式的feature属性没有坐标系字段,为了统一,再次加上
15941594
let coordinate = feature.getGeometry().getCoordinates();
15951595
if (allFeatures[i].geometry.type === 'Point') {
1596-
allFeatures[i].properties.lon = coordinate[0];
1597-
allFeatures[i].properties.lat = coordinate[1];
1596+
properties.lon = coordinate[0];
1597+
properties.lat = coordinate[1];
15981598
}
1599-
feature.attributes = allFeatures[i].properties || {};
16001599
feature.setProperties({
1601-
Properties: feature.attributes
1600+
attributes: properties
16021601
});
16031602
features.push(feature);
16041603
}
@@ -1786,7 +1785,7 @@ export class WebMap extends ol.Observable {
17861785
let filterResult = false;
17871786
try {
17881787
filterResult = window.jsonsql.query(sql, {
1789-
attributes: feature.attributes
1788+
attributes: feature.get('attributes')
17901789
});
17911790
} catch (err) {
17921791
//必须把要过滤得内容封装成一个对象,主要是处理jsonsql(line : 62)中由于with语句遍历对象造成的问题
@@ -1848,8 +1847,9 @@ export class WebMap extends ol.Observable {
18481847
let graphics = [];
18491848
//构建graphic
18501849
for (let i in features) {
1851-
let graphic = new ol.Graphic(features[i].getGeometry(), features[i].attributes);
1850+
let graphic = new ol.Graphic(features[i].getGeometry());
18521851
graphic.setStyle(shape);
1852+
graphic.setProperties({attributes: features[i].get('attributes')})
18531853
graphics.push(graphic);
18541854
}
18551855
return graphics;
@@ -1896,7 +1896,7 @@ export class WebMap extends ol.Observable {
18961896
});
18971897
layer.setStyle(features => {
18981898
let labelField = labelStyle.labelField;
1899-
let label = features.attributes[labelField.trim()] + "";
1899+
let label = features.get('attributes')[labelField.trim()] + "";
19001900
if (label === "undefined") {
19011901
return null;
19021902
}
@@ -2013,7 +2013,7 @@ export class WebMap extends ol.Observable {
20132013
this.getMaxValue(features, weightFeild);
20142014
let maxValue = this.fieldMaxValue[weightFeild];
20152015
features.forEach(function (feature) {
2016-
let attributes = feature.get("Properties") || feature.attributes;
2016+
let attributes = feature.get('attributes');
20172017
try {
20182018
let value = attributes[weightFeild];
20192019
feature.set('weight', value / maxValue);
@@ -2038,7 +2038,7 @@ export class WebMap extends ol.Observable {
20382038
}
20392039
features.forEach(function (feature) {
20402040
//收集当前权重字段对应的所有值
2041-
attributes = feature.get("Properties") || feature.attributes;
2041+
attributes = feature.get('attributes');
20422042
try {
20432043
values.push(parseFloat(attributes[field]));
20442044
} catch (e) {
@@ -2067,7 +2067,7 @@ export class WebMap extends ol.Observable {
20672067
layer.setStyle(feature => {
20682068
let styleSource = layer.get('styleSource');
20692069
let labelField = styleSource.themeField;
2070-
let label = feature.attributes[labelField];
2070+
let label = feature.get('attributes')[labelField];
20712071
return styleSource.styleGroups[label].olStyle;
20722072
});
20732073

@@ -2114,7 +2114,7 @@ export class WebMap extends ol.Observable {
21142114
let names = [],
21152115
customSettings = themeSetting.customSettings;
21162116
for (let i in features) {
2117-
let attributes = features[i].attributes;
2117+
let attributes = features[i].get('attributes');
21182118
let name = attributes[fieldName];
21192119
let isSaved = false;
21202120
for (let j in names) {
@@ -2180,7 +2180,7 @@ export class WebMap extends ol.Observable {
21802180
let styleSource = layer.get('styleSource');
21812181
if (styleSource) {
21822182
let labelField = styleSource.themeField;
2183-
let value = Number(feature.attributes[labelField.trim()]);
2183+
let value = Number(feature.get('attributes')[labelField.trim()]);
21842184
let styleGroups = styleSource.styleGroups;
21852185
for (let i = 0; i < styleGroups.length; i++) {
21862186
if (i === 0) {
@@ -2245,7 +2245,7 @@ export class WebMap extends ol.Observable {
22452245
let segmentMethod = method;
22462246
let that = this;
22472247
features.forEach(function (feature) {
2248-
attributes = feature.get("Properties") || feature.attributes;
2248+
attributes = feature.get("attributes");
22492249
try {
22502250
if (attributes) {
22512251
//过滤掉非数值的数据
@@ -2404,7 +2404,7 @@ export class WebMap extends ol.Observable {
24042404
let condition = that.replaceFilterCharacter(layerInfo.filterCondition);
24052405
let sql = "select * from json where (" + condition + ")";
24062406
let filterResult = window.jsonsql.query(sql, {
2407-
attributes: feature.attributes
2407+
attributes: feature.get('attributes')
24082408
});
24092409
if (filterResult && filterResult.length > 0) {
24102410
that.addDataflowFeature(feature, layerInfo.identifyField, {
@@ -2492,7 +2492,7 @@ export class WebMap extends ol.Observable {
24922492
//有转向字段
24932493
let value, image;
24942494
if(directionField !== undefined && directionField !== "未设置" && directionField !== "None") {
2495-
value = feature.attributes[directionField];
2495+
value = feature.get('attributes')[directionField];
24962496
} else {
24972497
value = 0;
24982498
}
@@ -2555,7 +2555,7 @@ export class WebMap extends ol.Observable {
25552555
let condition = that.replaceFilterCharacter(layerInfo.filterCondition);
25562556
let sql = "select * from json where (" + condition + ")";
25572557
let filterResult = window.jsonsql.query(sql, {
2558-
attributes: feature.attributes
2558+
attributes: feature.get('attributes')
25592559
});
25602560
if (filterResult && filterResult.length > 0) {
25612561
that.addDataflowFeature(feature, layerInfo.identifyField, {
@@ -2598,7 +2598,6 @@ export class WebMap extends ol.Observable {
25982598
}*/
25992599
featureCache[geoID].setGeometry(feature.getGeometry());
26002600
featureCache[geoID].setProperties(feature.getProperties());
2601-
featureCache[geoID].attributes = feature.attributes;
26022601
source.changed();
26032602
} else {
26042603
source.addFeature(feature);
@@ -2621,7 +2620,7 @@ export class WebMap extends ol.Observable {
26212620
dataProjection: "EPSG:4326", // todo 坐标系
26222621
featureProjection: that.baseProjection || 'EPSG:4326'
26232622
});
2624-
feature.attributes = geojson.properties;
2623+
feature.setProperties({attributes: geojson.properties});
26252624
callback(feature);
26262625

26272626
});
@@ -2672,7 +2671,7 @@ export class WebMap extends ol.Observable {
26722671
* @returns {*}
26732672
*/
26742673
setFeatureInfo(feature) {
2675-
let attributes = feature.getProperties().attributes,
2674+
let attributes = feature.get('attributes'),
26762675
defaultAttr = {
26772676
dataViz_title: '',
26782677
dataViz_description: '',
@@ -2711,7 +2710,7 @@ export class WebMap extends ol.Observable {
27112710
layer.setStyle(feature => {
27122711
let styleSource = layer.get('styleSource');
27132712
let themeField = styleSource.parameters.themeSetting.themeField;
2714-
let value = Number(feature.attributes[themeField]);
2713+
let value = Number(feature.get('attributes')[themeField]);
27152714
let styleGroups = styleSource.styleGroups;
27162715
for (let i = 0, len = styleGroups.length; i < len; i++) {
27172716
if (value >= styleGroups[i].start && value < styleGroups[i].end) {
@@ -2758,7 +2757,7 @@ export class WebMap extends ol.Observable {
27582757
minR = parameters.themeSetting.minRadius,
27592758
maxR = parameters.themeSetting.maxRadius;
27602759
features.forEach(feature => {
2761-
let attributes = feature.attributes,
2760+
let attributes = feature.get('attributes'),
27622761
value = attributes[themeField];
27632762
// 过滤掉空值和非数值
27642763
if (value == null || !Util.isNumber(value)) {

0 commit comments

Comments
 (0)