Skip to content

Commit d4e4355

Browse files
committed
feat: complete separation of addLayer and addFeature and many fixes and renames
1 parent 65f2cab commit d4e4355

File tree

9 files changed

+772
-607
lines changed

9 files changed

+772
-607
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { makeDraggableWithClone } from 'vvvyyynet_utils_maplibre';
3030
- **Fill-Pattern:** Unfortunately, the `fill-pattern` property cannot be unset. Either set it to the id of a registered image (could be completely transparent...), or remove the line. This is sort of a restriction for a standalone-wrapper-function that does not do the wrapping part... //! SOLVE THIS!
3131
- **LineDashArray and Glow:** Since line-dasharray is in units of line-width it will affect the glow differently leading to two unsynced dashed lines. To compensate for this, all values of glow.lineDashArray property must be set inversely proportional.
3232
33+
**LineGlow:** Available for lines and contourlines. In addition to the `line-blur` property, you can set a different color. Internally, a second layer is drawn with a pre-/postfixed layerId. The glow must be slightly wider than the line. You can either provide a `lineWidth` or a multiplication factor (`lineWidthGlowFactor`). Note that the latter not work, if the lineWidth defaults to the maplibregl-fallback linewidth (wich would be very tiny anyways), since the multiplication is handled inside the wrapper but not forwarded to maplibregl...
34+
3335
### Shared features
3436
3537
### Features for clone-dragging
@@ -48,8 +50,11 @@ import { makeDraggableWithClone } from 'vvvyyynet_utils_maplibre';
4850
- fix: move imports of CAPITALISED GLOBALS like FEATURES etc. to function arguments
4951
- fix: improve the checks and fallbacks inside addLayer for the various nested stylings
5052
- refactor: consider moving points_style inside style alltogether
53+
- fix: copy lineCap of Glow from regular line
5154
5255
### Features
56+
- feat: unset-all inside force
57+
- feat: unset specific inside force (e.g. fillPattern or iconImage)
5358
- feat: appart from 'circle'... are there any other maplibregl-default icons?
5459
5560
### Chore and Refactor

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import { registerSVG } from './utils/registerSVG';
2323
//----------------------------------------------
2424
// Add Features
2525
import { addFeatureCollection } from './utils/addFeatureCollection'; //! NEW
26-
import { addLayer } from './utils/addLayer';
26+
import { addFeature } from './utils/addFeature'; //!NEW
27+
import { addLayer } from './utils/addLayer'; //!NEW
2728

2829
//----------------------------------------------
2930
// Add Georeferenced Images to Map
@@ -67,9 +68,10 @@ export {
6768
drawTestPoints,
6869
drawTestLines,
6970
addFeatureCollection,
71+
addFeature,
72+
addLayer,
7073
addFeatureGroupsFromDB,
7174
addStaticFeatures,
72-
addLayer,
7375
consoleLogAllLayers,
7476
getMapPosition,
7577
loadBasemaps,

test/DEFAULT_STYLES.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ export const styleset = {
1717
circleStrokeWidth: 1
1818
},
1919
// ICON
20-
icon: {
21-
hasIconBackdrop: false,
20+
symbol: {
21+
hasBackdropCircle: false,
2222
// BACKDROP CIRCLE
23-
backdrop: {
23+
backdropCircle: {
2424
// Paint properties
2525
setInvisible: false,
2626
circleRadius: 18,

test/test_addFeatures.js

Lines changed: 47 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,30 @@
1-
import { addFeatures } from 'vvvyyynet_utils_maplibre/utils/addFeatureCollection';
2-
import {styleset} from './DEFAULT_STYLES';
1+
import { addFeatureCollection } from '../utils/addFeatureCollection';
2+
import { styleset } from './DEFAULT_STYLES';
33

44
console.log('dStyles: ', styleset);
55

66
export function test_addFeatures(map) {
77
const FeatColl = {
88
type: 'FeatureCollection',
99
features: [
10-
11-
// A Point
10+
// A Point
1211
{
1312
type: 'Feature',
1413
geometry: { type: 'Point', coordinates: [7.042569, 46.881066] },
1514
properties: {
1615
id: '49f56x10831cs7p',
1716
name: 'Römisches Amphitheater Aventicum',
18-
style: {
19-
circleColor: 'red',
20-
points: {
21-
type: 'icon',
22-
icon: { iconImage: 'butterfly' }
23-
}
24-
}
17+
temperature: 100,
18+
style: {}
2519
}
2620
},
27-
28-
// A Line
21+
// A Line
2922
{
3023
type: 'Feature',
3124
properties: {
3225
id: 'feature-1',
3326
name: 'Connecting Lines',
27+
myLineWidth: 20,
3428
style: {}
3529
},
3630
geometry: {
@@ -42,22 +36,22 @@ export function test_addFeatures(map) {
4236
]
4337
}
4438
},
45-
// Two more Points
39+
// Two more Points
4640
{
4741
type: 'Feature',
4842
geometry: { type: 'Point', coordinates: [8.7933439, 46.1678596] },
49-
properties: { id: 'feature-2', name: 'Castello Visconteo' }
43+
properties: { id: 'feature-2', name: 'Castello Visconteo', temperature: 20 }
5044
},
5145
{
5246
type: 'Feature',
5347
geometry: { type: 'Point', coordinates: [6.9762993, 46.3150334] },
54-
properties: { id: 'feature-3', name: "Château d'Aigle" }
48+
properties: { id: 'feature-3', name: "Château d'Aigle", temperature: 10 }
5549
},
5650

57-
// Polygon
51+
// Polygon
5852
{
5953
type: 'Feature',
60-
properties: { id: 'feature-4' },
54+
properties: { id: 'feature-4', mycolor: 'purple' },
6155
geometry: {
6256
type: 'Polygon',
6357
coordinates: [
@@ -80,45 +74,45 @@ export function test_addFeatures(map) {
8074
};
8175

8276
// Add Features
83-
addFeatures(map, FeatColl, {
77+
let idCollector;
78+
({ map: map, idCollector: idCollector } = addFeatureCollection(map, FeatColl, {
8479
id: 'test',
8580
// sortByTypesArray: ['lines', 'points', 'polygons'],
8681
// allowDirectAccess: true,
8782
manualStyleset: {
8883
force: {
89-
points: {
90-
type: 'circle',
91-
circle: {
92-
circleRadius: 16,
93-
circleColor: 'lightblue'
94-
}
95-
},
96-
lines: {
97-
lineDashArray: [4,4],
98-
lineWidth: 10,
99-
lineCap: 'round',
100-
lineJoin: 'round',
101-
hasGlow: true,
102-
glow: { lineWidthGlowFactor: 2, lineBlur: 5, lineColor: 'red', lineDashArray: [2,2] }
103-
},
104-
polygons: {
105-
106-
}
107-
},
108-
points: {
109-
110-
},
111-
lines: {
112-
lineColor: 'blue',
113-
},
114-
polygons: {
115-
lineWidth: 5,
116-
lineColor: 'green',
117-
fillColor: 'green',
118-
hasGlow: true,
119-
glow: { lineWidthGlowFactor: 5, lineBlur: 5 }
84+
points: {
85+
type: 'circle',
86+
circle: {
87+
circleRadius: 25,
88+
circleColor: ['rgb', ['get', 'temperature'], 0, ['-', 100, ['get', 'temperature']]]
89+
}
90+
},
91+
lines: {
92+
lineDashArray: [4, 4],
93+
lineCap: 'round',
94+
lineJoin: 'round',
95+
lineColor: 'black',
96+
hasGlow: true,
97+
lineWidth: ['interpolate', ['linear'], ['zoom'], 0, 20, 10, 5, 20, 900],
98+
glow: {
99+
lineWidthGlowFactor: 1.6,
100+
lineColor: 'red',
101+
lineCap: 'round',
102+
lineBlur: 5,
103+
lineDashArray: [2, 2]
104+
}
105+
},
106+
polygons: {
107+
fillColor: ['coalesce', ['string', ['get', 'mycolor']], ['rgb', 255, 200, 0]]
108+
}
120109
},
121-
},
122-
defaultStyleset: styleset
123-
});
110+
points: {},
111+
lines: {},
112+
polygons: {}
113+
}
114+
// defaultStyleset: styleset
115+
}));
116+
117+
console.log(idCollector);
124118
}

0 commit comments

Comments
 (0)