@geospatial-sdk/openlayers 0.0.5-dev.49 → 0.0.5-dev.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/dist/map/constants.d.ts +2 -0
  2. package/dist/map/constants.d.ts.map +1 -0
  3. package/dist/map/constants.js +1 -0
  4. package/dist/map/create-map.d.ts.map +1 -1
  5. package/dist/map/create-map.js +3 -2
  6. package/dist/map/feature-hover.d.ts +7 -0
  7. package/dist/map/feature-hover.d.ts.map +1 -0
  8. package/dist/map/feature-hover.js +71 -0
  9. package/dist/map/get-features.d.ts +12 -0
  10. package/dist/map/get-features.d.ts.map +1 -0
  11. package/dist/map/get-features.js +50 -0
  12. package/dist/map/index.d.ts +0 -1
  13. package/dist/map/index.d.ts.map +1 -1
  14. package/dist/map/index.js +0 -1
  15. package/dist/map/layer-update.d.ts.map +1 -1
  16. package/dist/map/layer-update.js +10 -0
  17. package/dist/map/register-events.d.ts +0 -8
  18. package/dist/map/register-events.d.ts.map +1 -1
  19. package/dist/map/register-events.js +1 -57
  20. package/lib/map/constants.ts +1 -0
  21. package/lib/map/create-map.test.ts +16 -13
  22. package/lib/map/create-map.ts +3 -1
  23. package/lib/map/feature-hover.ts +96 -0
  24. package/lib/map/get-features.test.ts +109 -0
  25. package/lib/map/get-features.ts +89 -0
  26. package/lib/map/handle-errors.test.ts +0 -1
  27. package/lib/map/index.ts +0 -1
  28. package/lib/map/layer-update.test.ts +27 -1
  29. package/lib/map/layer-update.ts +27 -3
  30. package/lib/map/register-events.test.ts +41 -85
  31. package/lib/map/register-events.ts +2 -97
  32. package/package.json +5 -5
  33. package/dist/map/styles.d.ts +0 -16
  34. package/dist/map/styles.d.ts.map +0 -1
  35. package/dist/map/styles.js +0 -77
  36. package/lib/map/styles.test.ts +0 -217
  37. package/lib/map/styles.ts +0 -103
@@ -1,217 +0,0 @@
1
- import chroma from "chroma-js";
2
- import Style, { StyleFunction } from "ol/style/Style.js";
3
- import Feature from "ol/Feature.js";
4
- import { LineString, Point, Polygon } from "ol/geom.js";
5
- import {
6
- createGeometryStyles,
7
- createStyleFunction,
8
- defaultHighlightStyle,
9
- defaultStyle,
10
- StyleByGeometryType,
11
- } from "./styles.js";
12
- import CircleStyle from "ol/style/Circle.js";
13
-
14
- describe("MapStyleService", () => {
15
- describe("#createGeometryStyles", () => {
16
- let styles: StyleByGeometryType;
17
- let pointStyle: Style;
18
- let lineStyle: Style[];
19
- let polygonStyle: Style;
20
-
21
- describe("unfocused style", () => {
22
- beforeEach(() => {
23
- const options = {
24
- color: "orange",
25
- };
26
- styles = createGeometryStyles(options);
27
- pointStyle = styles.point as Style;
28
- lineStyle = styles.line as Style[];
29
- polygonStyle = styles.polygon as Style;
30
- });
31
- describe("point style", () => {
32
- it("has 1 style", () => {
33
- expect(pointStyle).toBeInstanceOf(Style);
34
- });
35
- it("has correct radius", () => {
36
- expect((pointStyle.getImage() as CircleStyle)?.getRadius()).toBe(7);
37
- });
38
- it("has correct fill color", () => {
39
- expect(
40
- (pointStyle.getImage() as CircleStyle)?.getFill()?.getColor(),
41
- ).toBe("orange");
42
- });
43
- it("has correct stroke color and width", () => {
44
- expect(
45
- (pointStyle.getImage() as CircleStyle)?.getStroke()?.getColor(),
46
- ).toBe("white");
47
- expect(
48
- (pointStyle.getImage() as CircleStyle)?.getStroke()?.getWidth(),
49
- ).toBe(2);
50
- });
51
- });
52
- describe("polygon style", () => {
53
- it("has 1 style", () => {
54
- expect(polygonStyle).toBeInstanceOf(Style);
55
- });
56
- it("has correct fill color", () => {
57
- expect(polygonStyle.getFill()?.getColor()).toBe(
58
- chroma("orange").alpha(0.25).css(),
59
- );
60
- });
61
- it("has correct stroke color and width", () => {
62
- expect(polygonStyle.getStroke()?.getColor()).toBe("white");
63
- expect(polygonStyle.getStroke()?.getWidth()).toBe(2);
64
- });
65
- });
66
- describe("line style", () => {
67
- it("has 2 styles", () => {
68
- expect(lineStyle).toEqual([expect.any(Style), expect.any(Style)]);
69
- });
70
- it("has correct color (back stroke)", () => {
71
- expect(lineStyle[0].getStroke()?.getColor()).toBe("white");
72
- });
73
- it("has correct width (back stroke)", () => {
74
- expect(lineStyle[0].getStroke()?.getWidth()).toBe(6);
75
- });
76
- it("has correct color (front stroke)", () => {
77
- expect(lineStyle[1].getStroke()?.getColor()).toBe("orange");
78
- });
79
- it("has correct width (front stroke)", () => {
80
- expect(lineStyle[1].getStroke()?.getWidth()).toBe(2);
81
- });
82
- });
83
- });
84
- describe("focused style", () => {
85
- beforeEach(() => {
86
- const options = {
87
- color: "pink",
88
- isFocused: true,
89
- };
90
- styles = createGeometryStyles(options);
91
- pointStyle = styles.point as Style;
92
- lineStyle = styles.line as Style[];
93
- polygonStyle = styles.polygon as Style;
94
- });
95
- describe("point style", () => {
96
- it("has correct radius", () => {
97
- expect((pointStyle.getImage() as CircleStyle)?.getRadius()).toBe(8);
98
- });
99
- it("has correct fill color", () => {
100
- expect(
101
- (pointStyle.getImage() as CircleStyle)?.getFill()?.getColor(),
102
- ).toBe("pink");
103
- });
104
- it("has correct stroke color and width", () => {
105
- expect(
106
- (pointStyle.getImage() as CircleStyle)?.getStroke()?.getColor(),
107
- ).toBe("white");
108
- expect(
109
- (pointStyle.getImage() as CircleStyle)?.getStroke()?.getWidth(),
110
- ).toBe(3);
111
- });
112
- });
113
- describe("polygon style", () => {
114
- it("has correct fill color", () => {
115
- expect(polygonStyle.getFill()?.getColor()).toBe(
116
- chroma("pink").alpha(0.25).css(),
117
- );
118
- });
119
- it("has correct stroke color and width", () => {
120
- expect(polygonStyle.getStroke()?.getColor()).toBe("white");
121
- expect(polygonStyle.getStroke()?.getWidth()).toBe(2);
122
- });
123
- });
124
- describe("line style", () => {
125
- it("has correct color (back stroke)", () => {
126
- expect(lineStyle[0].getStroke()?.getColor()).toBe("white");
127
- });
128
- it("has correct width (back stroke)", () => {
129
- expect(lineStyle[0].getStroke()?.getWidth()).toBe(8);
130
- });
131
- it("has correct color (front stroke)", () => {
132
- expect(lineStyle[1].getStroke()?.getColor()).toBe("pink");
133
- });
134
- it("has correct width (front stroke)", () => {
135
- expect(lineStyle[1].getStroke()?.getWidth()).toBe(3);
136
- });
137
- });
138
- });
139
- });
140
-
141
- describe("#createStyleFunction", () => {
142
- let styleFn: StyleFunction;
143
- let feature: Feature;
144
- it("returns a function", () => {
145
- styleFn = createStyleFunction(
146
- createGeometryStyles({
147
- color: "blue",
148
- }),
149
- );
150
- feature = new Feature();
151
- });
152
- describe("with linestring geometry", () => {
153
- beforeEach(() => {
154
- feature.setGeometry(new LineString([]));
155
- });
156
- it("resolves to a double style with stroke", () => {
157
- const style = styleFn(feature, 1) as Style[];
158
- expect(style).toEqual([expect.any(Style), expect.any(Style)]);
159
- expect(style[0].getStroke()).toBeTruthy();
160
- expect(style[0].getFill()).toBeFalsy();
161
- expect(style[0].getImage()).toBeFalsy();
162
- });
163
- });
164
- describe("with point geometry", () => {
165
- beforeEach(() => {
166
- feature.setGeometry(new Point([]));
167
- });
168
- it("resolves to a style with image", () => {
169
- const style = styleFn(feature, 1) as Style;
170
- expect(style.getImage()).toBeTruthy();
171
- expect(style.getFill()).toBeFalsy();
172
- expect(style.getStroke()).toBeFalsy();
173
- });
174
- });
175
- describe("with polygon geometry", () => {
176
- beforeEach(() => {
177
- feature.setGeometry(new Polygon([]));
178
- });
179
- it("resolves to a style with fill and stroke", () => {
180
- const style = styleFn(feature, 1) as Style;
181
- expect(style.getFill()).toBeTruthy();
182
- expect(style.getStroke()).toBeTruthy();
183
- expect(style.getImage()).toBeFalsy();
184
- });
185
- });
186
- });
187
-
188
- describe("built-in styles", () => {
189
- let pointFeature: Feature;
190
- let pointStyle: Style;
191
- beforeEach(() => {
192
- pointFeature = new Feature(new Point([]));
193
- });
194
- describe("default style", () => {
195
- beforeEach(() => {
196
- const styleFn = defaultStyle;
197
- pointStyle = styleFn(pointFeature, 1) as Style;
198
- });
199
- it("uses the primary theme color", () => {
200
- expect(
201
- (pointStyle.getImage() as CircleStyle)?.getFill()?.getColor(),
202
- ).toEqual("blue");
203
- });
204
- });
205
- describe("default highlight style", () => {
206
- beforeEach(() => {
207
- const styleFn = defaultHighlightStyle;
208
- pointStyle = styleFn(pointFeature, 1) as Style;
209
- });
210
- it("uses the secondary theme color", () => {
211
- expect(
212
- (pointStyle.getImage() as CircleStyle)?.getFill()?.getColor(),
213
- ).toEqual("red");
214
- });
215
- });
216
- });
217
- });
package/lib/map/styles.ts DELETED
@@ -1,103 +0,0 @@
1
- import { Circle, Fill, Stroke, Style } from "ol/style.js";
2
- import { StyleFunction } from "ol/style/Style.js";
3
- import { FeatureLike } from "ol/Feature.js";
4
- import chroma from "chroma-js";
5
-
6
- export interface CreateStyleOptions {
7
- color: string;
8
- isFocused?: boolean;
9
- }
10
-
11
- export interface StyleByGeometryType {
12
- line: Style | Style[];
13
- polygon: Style | Style[];
14
- point: Style | Style[];
15
- }
16
-
17
- export function createGeometryStyles(
18
- options: CreateStyleOptions,
19
- ): StyleByGeometryType {
20
- const { color, isFocused } = options;
21
- const zIndex = isFocused ? 10 : undefined;
22
- return {
23
- polygon: new Style({
24
- fill: new Fill({
25
- color: computeTransparentFillColor(color),
26
- }),
27
- stroke: new Stroke({
28
- color: "white",
29
- width: 2,
30
- }),
31
- zIndex,
32
- }),
33
- point: new Style({
34
- image: new Circle({
35
- fill: new Fill({
36
- color,
37
- }),
38
- stroke: new Stroke({
39
- color: "white",
40
- width: isFocused ? 3 : 2,
41
- }),
42
- radius: isFocused ? 8 : 7,
43
- }),
44
- zIndex,
45
- }),
46
- line: [
47
- new Style({
48
- stroke: new Stroke({
49
- color: "white",
50
- width: isFocused ? 8 : 6,
51
- }),
52
- zIndex,
53
- }),
54
- new Style({
55
- stroke: new Stroke({
56
- color,
57
- width: isFocused ? 3 : 2,
58
- }),
59
- zIndex,
60
- }),
61
- ],
62
- };
63
- }
64
-
65
- export function createStyleFunction(
66
- styleByGeometryType: StyleByGeometryType,
67
- ): StyleFunction {
68
- return (feature: FeatureLike): Style | Style[] => {
69
- const geometryType = feature?.getGeometry()?.getType();
70
- switch (geometryType) {
71
- case "LinearRing":
72
- case "LineString":
73
- case "MultiLineString":
74
- return styleByGeometryType.line;
75
- case "Point":
76
- case "MultiPoint":
77
- return styleByGeometryType.point;
78
- case "Circle":
79
- case "Polygon":
80
- case "MultiPolygon":
81
- return styleByGeometryType.polygon;
82
- default:
83
- return styleByGeometryType.point;
84
- }
85
- };
86
- }
87
-
88
- function computeTransparentFillColor(color: string, alpha = 0.25): string {
89
- return chroma(color).alpha(alpha).css();
90
- }
91
-
92
- export const defaultStyle = createStyleFunction(
93
- createGeometryStyles({
94
- color: "blue",
95
- }),
96
- );
97
-
98
- export const defaultHighlightStyle = createStyleFunction(
99
- createGeometryStyles({
100
- color: "red",
101
- isFocused: true,
102
- }),
103
- );