terra-draw 0.0.1-alpha.41 → 0.0.1-alpha.42

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.
@@ -290,3 +290,43 @@ draw.start();
290
290
  ```
291
291
 
292
292
  Please note at the moment it is not possible to style against specific modes but only universally against geometry type (Point, LineString, Polygon)
293
+
294
+ ## Styling Specific Features
295
+
296
+ Terra Draw supports styling overrides of individual features if required. This can be achieved by providing a styling function rather than a string or a number to a feature. As an example here we can style each polygon feature as a random color:
297
+
298
+ ```typescript
299
+ // Function to generate a random hex color - can adjust as needed
300
+ function getRandomColor() {
301
+ const letters = "0123456789ABCDEF";
302
+ let color = "#";
303
+ for (let i = 0; i < 6; i++) {
304
+ color += letters[Math.floor(Math.random() * 16)];
305
+ }
306
+ return color;
307
+ }
308
+
309
+ // Cache for each feature id mapped to a hex color string
310
+ const colorCache: Record<string, HexColor> = {};
311
+
312
+ const draw = new TerraDraw({
313
+ adapter: new TerraDrawMapboxGLAdapter({
314
+ map, // Assume this is defined further up
315
+ coordinatePrecision: 9,
316
+ }),
317
+ modes: {
318
+ polygon: new TerraDrawPolygonMode({
319
+ styles: {
320
+ fillColor: ({ id }) => {
321
+ // Get the color from the cache or generate a new one
322
+ colorCache[id] = colorCache[id] || getRandomColor();
323
+ return colorCache[id];
324
+ },
325
+ },
326
+ }),
327
+ },
328
+ });
329
+
330
+ // Ensure the color cache is clead up on deletion of features
331
+ draw.on("delete", (ids) => ids.forEach((id) => delete cache[id]));
332
+ ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "terra-draw",
3
- "version": "0.0.1-alpha.41",
3
+ "version": "0.0.1-alpha.42",
4
4
  "description": "Frictionless map drawing across mapping provider",
5
5
  "scripts": {
6
6
  "docs": "typedoc",