Skip to content

Commit f1cc53c

Browse files
author
ChenGuanglin
committed
2 parents e371635 + dbe4cd4 commit f1cc53c

File tree

3 files changed

+102
-25
lines changed

3 files changed

+102
-25
lines changed

build/jsdocs/template/typeLinkExt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var olapi = "https://openlayers.org/en/v6.1.1/apidoc/";
2-
var lfapi = "https://leafletjs.com/reference-1.5.1.html";
2+
var lfapi = "https://leafletjs.com/reference-1.6.0.html";
33
var mbglapi = "https://www.mapbox.com/mapbox-gl-js/api/";
44
var mapv = "https://github.com/huiyan-fe/mapv/blob/master/src/";
55
var classicapi="https://iclient.supermap.io/web/libs/iclient8c/apidoc/files/SuperMap"
@@ -75,4 +75,4 @@ var typeLinks = {
7575
"GeoJSONObject": geojsonapi
7676

7777
}
78-
exports.typeLinks = typeLinks;
78+
exports.typeLinks = typeLinks;

src/openlayers/core/StyleUtils.js

Lines changed: 90 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import StrokeStyle from 'ol/style/Stroke';
1414
import Text from 'ol/style/Text';
1515

1616
var padding = 8, doublePadding = padding * 2;
17+
const ZERO = 0.0000001;
1718

1819
/**
1920
* @class ol.supermap.StyleUtils
@@ -599,7 +600,6 @@ export class StyleUtils {
599600
style = style || this.getDefaultStyle();
600601
let olStyle = new Style();
601602
let newImage, newFill, newStroke;
602-
const ZERO = 0.0000001;
603603
let {
604604
fillColor,
605605
fillOpacity,
@@ -1152,26 +1152,95 @@ export class StyleUtils {
11521152
* @returns {Object} style对象
11531153
*/
11541154
static getImageStyle(styleParams) {
1155-
let size = styleParams.imageInfo.size,
1156-
scale = 2 * styleParams.radius / size.w;
1157-
let imageInfo = styleParams.imageInfo;
1158-
let imgDom = imageInfo.img;
1159-
if (!imgDom || !imgDom.src) {
1160-
imgDom = new Image();
1161-
//要组装成完整的url
1162-
imgDom.src = imageInfo.url;
1163-
}
1164-
const { offsetX, offsetY, rotation } = styleParams;
1165-
let anchor = this.getIconAnchor(offsetX, offsetY);
1166-
return new Style({
1167-
image: new Icon({
1168-
img: imgDom,
1169-
scale,
1170-
imgSize: [size.w, size.h],
1171-
anchor: anchor || [0.5, 0.5],
1172-
anchorOrigin: 'bottom-right',
1173-
rotation
1174-
})
1155+
let size = styleParams.imageInfo.size,
1156+
scale = 2 * styleParams.radius / size.w;
1157+
let imageInfo = styleParams.imageInfo;
1158+
let imgDom = imageInfo.img;
1159+
if (!imgDom || !imgDom.src) {
1160+
imgDom = new Image();
1161+
//要组装成完整的url
1162+
imgDom.src = imageInfo.url;
1163+
}
1164+
const { offsetX, offsetY, rotation } = styleParams;
1165+
let anchor = this.getIconAnchor(offsetX, offsetY);
1166+
return new Style({
1167+
image: new Icon({
1168+
img: imgDom,
1169+
scale,
1170+
imgSize: [size.w, size.h],
1171+
anchor: anchor || [0.5, 0.5],
1172+
anchorOrigin: 'bottom-right',
1173+
rotation
1174+
})
1175+
});
1176+
}
1177+
/**
1178+
* @function ol.supermap.StyleUtils.getRoadPath 获取道路样式
1179+
* @param {object} style - 样式参数
1180+
* @param {object} outlineStyle - 轮廓样式参数
1181+
* @returns {Object} style对象
1182+
*/
1183+
static getRoadPath(style, outlineStyle) {
1184+
const { strokeWidth=ZERO, lineCap, strokeColor, strokeOpacity } = style;
1185+
// 道路线都是solid
1186+
let strokeColorArray = this.hexToRgb(strokeColor);
1187+
strokeColorArray && strokeColorArray.push(strokeOpacity);
1188+
var stroke = new Style({
1189+
stroke: new StrokeStyle({
1190+
width: strokeWidth || ZERO,
1191+
color: strokeColorArray,
1192+
lineCap: lineCap || 'round',
1193+
lineDash: [0]
1194+
})
1195+
});
1196+
1197+
const { strokeColor: outlineColor } = outlineStyle;
1198+
let outlineColorArray = this.hexToRgb(outlineColor);
1199+
// opacity使用style的透明度。保持两根线透明度一致
1200+
outlineColorArray && outlineColorArray.push(strokeOpacity);
1201+
let outlineWidth = strokeWidth === 0 ? ZERO : strokeWidth + 2; //外部宽度=内部样式宽度 + 2
1202+
var outlineStroke = new Style({
1203+
stroke: new StrokeStyle({
1204+
width: outlineWidth, //外部宽度=内部样式宽度 + 2
1205+
color: outlineColorArray,
1206+
lineCap: lineCap || 'round',
1207+
lineDash: [0]
1208+
})
1209+
});
1210+
return [outlineStroke, stroke];
1211+
}
1212+
/**
1213+
* @function ol.supermap.StyleUtils.getPathway 获取铁路样式
1214+
* @param {object} style - 样式参数
1215+
* @param {object} outlineStyle - 轮廓样式参数
1216+
* @returns {Object} style对象
1217+
*/
1218+
static getPathway(style, outlineStyle) {
1219+
let { strokeWidth=ZERO, strokeColor, strokeOpacity } = style;
1220+
// 道路线都是solid, lineCap都是直角
1221+
const lineDash = (w => [w, w + strokeWidth * 2])(4 * strokeWidth), lineCap= 'square';
1222+
let strokeColorArray = this.hexToRgb(strokeColor);
1223+
strokeColorArray && strokeColorArray.push(strokeOpacity);
1224+
var stroke = new Style({
1225+
stroke: new StrokeStyle({
1226+
width: strokeWidth*0.5 || ZERO,
1227+
color: strokeColorArray,
1228+
lineCap,
1229+
lineDash
1230+
})
1231+
});
1232+
1233+
const { strokeColor: outlineColor } = outlineStyle;
1234+
let outlineColorArray = this.hexToRgb(outlineColor);
1235+
// opacity使用style的透明度。保持两根线透明度一致
1236+
outlineColorArray && outlineColorArray.push(strokeOpacity);
1237+
var outlineStroke = new Style({
1238+
stroke: new StrokeStyle({
1239+
width: strokeWidth || ZERO,
1240+
color: outlineColorArray,
1241+
lineCap
1242+
})
11751243
});
1244+
return [outlineStroke, stroke];
11761245
}
11771246
}

src/openlayers/mapping/WebMap.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2538,9 +2538,17 @@ export class WebMap extends Observable {
25382538
* @returns {ol/layer/Vector} 矢量图层
25392539
*/
25402540
createVectorLayer(layerInfo, features) {
2541-
let style = StyleUtils.toOpenLayersStyle(layerInfo.style, layerInfo.featureType);
2541+
const {featureType, style} = layerInfo;
2542+
let newStyle;
2543+
if(featureType === 'LINE' && Util.isArray(style)) {
2544+
const [outlineStyle, strokeStyle] = style;
2545+
newStyle = strokeStyle.lineDash === 'solid' ? StyleUtils.getRoadPath(strokeStyle, outlineStyle)
2546+
: StyleUtils.getPathway(strokeStyle, outlineStyle);
2547+
} else {
2548+
newStyle = StyleUtils.toOpenLayersStyle(layerInfo.style, layerInfo.featureType);
2549+
}
25422550
return new olLayer.Vector({
2543-
style: style,
2551+
style: newStyle,
25442552
source: new olSource.Vector({
25452553
features: layerInfo.filterCondition ? this.getFiterFeatures(layerInfo.filterCondition, features) : features,
25462554
wrapX: false

0 commit comments

Comments
 (0)