Skip to content

Commit a60eb97

Browse files
committed
fix: fix lineGlow
1 parent fcce425 commit a60eb97

File tree

2 files changed

+75
-61
lines changed

2 files changed

+75
-61
lines changed

test/test_addFeatures.js

Lines changed: 49 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,52 @@
1-
import {addFeatures} from '../utils/addFeatures'
1+
import { addFeatures } from '../utils/addFeatures';
22

33
export function test_addFeatures(map) {
4+
const FeatColl = {
5+
type: 'FeatureCollection',
6+
features: [
7+
{
8+
type: 'Feature',
9+
geometry: { type: 'Point', coordinates: [7.042569, 46.881066] },
10+
properties: { id: '49f56x10831cs7p', name: 'Römisches Amphitheater Aventicum' }
11+
},
12+
{
13+
type: 'Feature',
14+
geometry: { type: 'Point', coordinates: [8.7933439, 46.1678596] },
15+
properties: { id: 'qmq36u8z9b2x5nc', name: 'Castello Visconteo' }
16+
},
17+
{
18+
type: 'Feature',
19+
geometry: { type: 'Point', coordinates: [6.9762993, 46.3150334] },
20+
properties: { id: 'c6079rsfypjj863', name: "Château d'Aigle" }
21+
},
22+
{
23+
type: 'Feature',
24+
properties: { id: 'waejkl3782hjkwl', name: 'Connecting Lines' },
25+
geometry: {
26+
type: 'LineString',
27+
coordinates: [
28+
[7.042569, 46.881066],
29+
[8.7933439, 46.1678596],
30+
[6.9762993, 46.3150334]
31+
]
32+
}
33+
}
34+
]
35+
};
436

5-
const FeatColl = {
6-
type: 'FeatureCollection',
7-
features: [
8-
{
9-
type: 'Feature',
10-
geometry: { type: 'Point', coordinates: [7.042569, 46.881066] },
11-
properties: { id: '49f56x10831cs7p', name: 'Römisches Amphitheater Aventicum' }
12-
},
13-
{
14-
type: 'Feature',
15-
geometry: { type: 'Point', coordinates: [8.7933439, 46.1678596] },
16-
properties: { id: 'qmq36u8z9b2x5nc', name: 'Castello Visconteo' }
17-
},
18-
{
19-
type: 'Feature',
20-
geometry: { type: 'Point', coordinates: [6.9762993, 46.3150334] },
21-
properties: { id: 'c6079rsfypjj863', name: "Château d'Aigle" }
22-
},
23-
{
24-
type: "Feature",
25-
properties: { id: 'waejkl3782hjkwl', name: "Connecting Lines" },
26-
geometry: {
27-
"type": "LineString",
28-
"coordinates": [
29-
[7.042569, 46.881066],
30-
[8.7933439, 46.1678596],
31-
[6.9762993, 46.3150334]
32-
],
33-
}
34-
}
35-
]
36-
}
37-
38-
// Add Features
39-
addFeatures(map, FeatColl, {id:"test", linesStyle: {lineWidthForce: 5}});
40-
41-
};
37+
// Add Features
38+
addFeatures(map, FeatColl, {
39+
id: 'test',
40+
linesStyle: {
41+
lineWidthForce: 1,
42+
glowStyle: { lineWidthFactor: 5, glowBlur: 5 },
43+
lineColor: 'black',
44+
hasGlow: true
45+
},
46+
pointsStyle: {
47+
circleStyle: {
48+
circleRadius: 6
49+
}
50+
}
51+
});
52+
}

utils/addLayer.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ function makeLayerInteractive(map, layerId) {
7171
});
7272

7373
map.on('mouseenter', layerId, () => {
74-
map.getCanvas().geoJSONStyle.cursor = 'pointer';
74+
map.getCanvas().style.cursor = 'pointer';
7575
});
7676

7777
map.on('mouseleave', layerId, () => {
78-
map.getCanvas().geoJSONStyle.cursor = '';
78+
map.getCanvas().style.cursor = '';
7979
});
8080
}
8181

@@ -93,6 +93,8 @@ export function addLayer(
9393
linesStyle = {
9494
// manual styling (values post-fixed with Force will win over geoJSONStyle)
9595
setInvisible: false,
96+
lineColor: 'red',
97+
lineColorForce: 'red',
9698
isDotted: false,
9799
lineBlur: 5,
98100
lineWidth: 5,
@@ -101,7 +103,7 @@ export function addLayer(
101103
lineWidthAtZoom16: 5,
102104
hasGlow: false,
103105
glowStyle: {
104-
lineWidthFactor: 2.5,
106+
lineWidthFactor: 5,
105107
lineBlur: 5
106108
},
107109
isGlow: false // will be set programmatically, not intended for outside use
@@ -263,10 +265,15 @@ export function addLayer(
263265
// Lines
264266
// --------------------------------------
265267
} else if (featureType === 'MultiLineString' || featureType === 'LineString') {
268+
console.log('LINE: ', linesStyle);
269+
266270
// CHECK GLOW AND RE-RUN addLayer
267271
if (linesStyle?.hasGlow) {
272+
let linesStyleOfGlow = { ...linesStyle }; // shallow copy is important!
268273
linesStyleOfGlow.hasGlow = false;
269274
linesStyleOfGlow.isGlow = true;
275+
276+
//
270277
addLayer(
271278
map,
272279
feature,
@@ -278,24 +285,18 @@ export function addLayer(
278285
linesStyleOfGlow,
279286
pointsStyle
280287
);
281-
} else if (linesStyle?.isGlow) {
282-
addLayer(
283-
map,
284-
feature,
285-
FEATURES,
286-
sourceId,
287-
layerId,
288-
geoJSONStyle,
289-
groupNames,
290-
linesStyleOfGlow,
291-
pointsStyle
292-
);
288+
289+
// before continuing, make sure isGlow is false for normal line
290+
linesStyle.isGlow = false;
293291
}
294292

295-
const lineWidthFactor = linesStyle?.isGlow ? linesStyle?.glowStyle?.lineWidthFactor : 1; // glow must be wider
296-
console.log('LINE: ', linesStyle?.lineWidthForce * lineWidthFactor, lineWidthFactor);
293+
const lineWidthFactor = linesStyle?.isGlow ? linesStyle?.glowStyle?.lineWidthFactor || 2.5 : 1; // glow must be wider
294+
const layerIdGlow = `${layerId}-glow`;
295+
296+
console.log(linesStyle?.isGlow, linesStyle?.lineWidthForce, lineWidthFactor);
297+
297298
map.addLayer({
298-
id: linesStyle?.isGlow ? `${layerId}-glow` : layerId,
299+
id: linesStyle?.isGlow ? layerIdGlow : layerId,
299300
type: 'line',
300301
source: sourceId,
301302
metadata: {
@@ -307,10 +308,10 @@ export function addLayer(
307308
// 'line-cap': 'round'
308309
},
309310
paint: {
310-
'line-color': [
311+
'line-color': linesStyle?.lineColorForce || [
311312
'coalesce',
312313
['get', 'lineColor'],
313-
getFromStyle(geoJSONStyle, 'lineColor') || 'red'
314+
getFromStyle(geoJSONStyle, 'lineColor') || linesStyle?.lineColor || 'red'
314315
],
315316
'line-width':
316317
linesStyle?.lineWidthForce * lineWidthFactor ||
@@ -332,9 +333,11 @@ export function addLayer(
332333
}
333334
// filter: ['==', ['get', 'id'], feature.properties.id]
334335
});
335-
// make sure glow is not dashed
336-
if (linesStyle?.hasGlow) {
337-
map.setPaintProperty(id, 'line-dasharray', null);
336+
337+
// Adjustments
338+
// Make sure glow is not dashed
339+
if (linesStyle?.isGlow) {
340+
map.setPaintProperty(layerIdGlow, 'line-dasharray', null);
338341
}
339342

340343
// PUSH TO FEATURES

0 commit comments

Comments
 (0)