Skip to content

Commit 20873d1

Browse files
[fix]isvj-5215 单值专题图修改geojson数据 web添加 review by qiw
1 parent 96f5ed7 commit 20873d1

File tree

4 files changed

+167
-1
lines changed

4 files changed

+167
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
"fetch-jsonp": "1.1.3",
133133
"jsonsql": "0.2.5",
134134
"leaflet": "1.7.1",
135+
"lodash.difference": "^4.5.0",
135136
"lodash.remove": "^4.7.0",
136137
"lodash.topairs": "4.3.0",
137138
"mapbox-gl": "1.13.2",

src/openlayers/mapping/WebMap.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ import StrokeStyle from 'ol/style/Stroke';
5151
import Text from 'ol/style/Text';
5252
import Collection from 'ol/Collection';
5353
import {containsCoordinate, getCenter} from "ol/extent";
54+
import difference from 'lodash.difference';
5455

5556
window.proj4 = proj4;
5657
window.Proj4js = proj4;
@@ -3166,6 +3167,9 @@ export class WebMap extends Observable {
31663167

31673168
//生成styleGroup
31683169
let styleGroup = [];
3170+
const usedColors = this.getCustomSettingColors(customSettings, names, featureType).map(item => item.toLowerCase());
3171+
const curentColors = this.getUniqueColors(themeSetting.colors || this.defaultParameters.themeSetting.colors, names.length + Object.keys(customSettings).length).map(item => item.toLowerCase());
3172+
const newColors = difference(curentColors, usedColors);
31693173
for(let index = 0; index < names.length; index++) {
31703174
const name = names[index];
31713175
//兼容之前自定义是用key,现在因为数据支持编辑,需要用属性值。
@@ -3176,6 +3180,9 @@ export class WebMap extends Observable {
31763180
custom = this.getCustomSetting(style, custom, featureType);
31773181
customSettings[key] = custom;
31783182
}
3183+
if (!custom) {
3184+
custom = this.getCustomSetting(style, newColors.shift(), featureType);
3185+
}
31793186

31803187
// 转化成 ol 样式
31813188
let olStyle, type = custom.type;
@@ -3214,6 +3221,23 @@ export class WebMap extends Observable {
32143221
return customSetting;
32153222
}
32163223

3224+
getCustomSettingColors(customSettings, featureType) {
3225+
const keys = Object.keys(customSettings);
3226+
const colors = [];
3227+
keys.forEach(key => {
3228+
if (featureType === "LINE") {
3229+
colors.push(customSettings[key].strokeColor);
3230+
} else {
3231+
colors.push(customSettings[key].fillColor);
3232+
}
3233+
});
3234+
return colors;
3235+
}
3236+
3237+
getUniqueColors(colors, valuesLen) {
3238+
return ColorsPickerUtil.getGradientColors(colors, valuesLen);
3239+
}
3240+
32173241
/**
32183242
* @private
32193243
* @function WebMap.prototype.createRangeLayer

src/openlayers/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@supermap/iclient-common": "11.1.0-dev",
2323
"proj4": "2.8.0",
2424
"canvg": "3.0.10",
25-
"lodash.remove": "^4.7.0"
25+
"lodash.remove": "^4.7.0",
26+
"lodash.difference": "^4.5.0"
2627
}
2728
}

test/openlayers/mapping/WebMapSpec.js

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,146 @@ describe('openlayers_WebMap', () => {
202202
done();
203203
}
204204
});
205+
it('isvj-5215', (done) => {
206+
let options = {
207+
server: server,
208+
successCallback,
209+
errorCallback: function () {}
210+
};
211+
spyOn(FetchRequest, 'get').and.callFake((url) => {
212+
if (url.indexOf('map.json') > -1) {
213+
var mapJson = datavizWebMap_BAIDU;
214+
return Promise.resolve(new Response(mapJson));
215+
}
216+
return Promise.resolve();
217+
});
218+
var datavizWebmap = new WebMap(id, options);
219+
220+
async function successCallback() {
221+
const parameters = {
222+
"layerType": "UNIQUE",
223+
"visible": true,
224+
"themeSetting": {
225+
"themeField": "UserID",
226+
"customSettings": {
227+
"0": {
228+
"fillColor": "#D53E4F",
229+
"strokeWidth": 1,
230+
"offsetX": 0,
231+
"offsetY": 0,
232+
"fillOpacity": 0.9,
233+
"type": "BASIC_POINT",
234+
"radius": 15,
235+
"strokeColor": "#ffffff",
236+
"strokeOpacity": 1
237+
},
238+
"1": {
239+
"fillColor": "#3288BD",
240+
"strokeWidth": 1,
241+
"offsetX": 0,
242+
"offsetY": 0,
243+
"fillOpacity": 0.9,
244+
"type": "BASIC_POINT",
245+
"radius": 15,
246+
"strokeColor": "#ffffff",
247+
"strokeOpacity": 1
248+
},
249+
"2": {
250+
"fillColor": "#FC8D59",
251+
"strokeWidth": 1,
252+
"offsetX": 0,
253+
"offsetY": 0,
254+
"fillOpacity": 0.9,
255+
"type": "BASIC_POINT",
256+
"radius": 15,
257+
"strokeColor": "#ffffff",
258+
"strokeOpacity": 1
259+
},
260+
"3": {
261+
"fillColor": "#99D594",
262+
"strokeWidth": 1,
263+
"offsetX": 0,
264+
"offsetY": 0,
265+
"fillOpacity": 0.9,
266+
"type": "BASIC_POINT",
267+
"radius": 15,
268+
"strokeColor": "#ffffff",
269+
"strokeOpacity": 1
270+
},
271+
"5": {
272+
"fillColor": "#FEE08B",
273+
"strokeWidth": 1,
274+
"offsetX": 0,
275+
"offsetY": 0,
276+
"fillOpacity": 0.9,
277+
"type": "BASIC_POINT",
278+
"radius": 15,
279+
"strokeColor": "#ffffff",
280+
"strokeOpacity": 1
281+
},
282+
"8": {
283+
"fillColor": "#E6F598",
284+
"strokeWidth": 1,
285+
"offsetX": 0,
286+
"offsetY": 0,
287+
"fillOpacity": 0.9,
288+
"type": "BASIC_POINT",
289+
"radius": 15,
290+
"strokeColor": "#ffffff",
291+
"strokeOpacity": 1
292+
}
293+
},
294+
"colors": [
295+
"#D53E4F",
296+
"#FC8D59",
297+
"#FEE08B",
298+
"#FFFFBF",
299+
"#E6F598",
300+
"#99D594",
301+
"#3288BD"
302+
]
303+
},
304+
"name": "isvj-5215",
305+
"featureType": "POINT",
306+
"labelStyle": {
307+
"offsetX": 0,
308+
"textBaseline": "bottom",
309+
"fontFamily": "黑体",
310+
"offsetY": -19,
311+
"outlineWidth": 0,
312+
"textAlign": "center",
313+
"outlineColor": "#000000",
314+
"fontSize": "14px",
315+
"fill": "#333",
316+
"backgroundFill": [
317+
255,
318+
255,
319+
255,
320+
0.8
321+
],
322+
"labelField": "UserID"
323+
},
324+
"style": {
325+
"strokeWidth": 1,
326+
"offsetX": 0,
327+
"fillColor": "#E6F598",
328+
"offsetY": 0,
329+
"fillOpacity": 0.9,
330+
"radius": 15,
331+
"strokeColor": "#ffffff",
332+
"type": "BASIC_POINT",
333+
"strokeOpacity": 1
334+
},
335+
"projection": "EPSG:4326",
336+
"enableFields": [
337+
"UserID"
338+
]
339+
}
340+
const res = await datavizWebmap.getUniqueStyleGroup(parameters, [{ get: () => ({ 'UserID': 30, 'UserID': 0 }) }]);
341+
expect(res.length).toBe(2);
342+
done();
343+
}
344+
});
205345
it('initialize_OPENSTREET', (done) => {
206346
let options = {
207347
server: server,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy