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.
- package/CHANGELOG.md +2 -0
- package/dist/common.d.ts +2 -0
- package/dist/modes/base.mode.d.ts +5 -2
- package/dist/modes/circle/circle.mode.d.ts +5 -5
- package/dist/modes/freehand/freehand.mode.d.ts +9 -9
- package/dist/modes/greatcircle/great-circle.mode.d.ts +7 -7
- package/dist/modes/linestring/linestring.mode.d.ts +7 -7
- package/dist/modes/point/point.mode.d.ts +5 -5
- package/dist/modes/polygon/polygon.mode.d.ts +9 -9
- package/dist/modes/rectangle/rectangle.mode.d.ts +5 -5
- package/dist/modes/render/render.mode.d.ts +16 -5
- package/dist/modes/select/select.mode.d.ts +19 -19
- package/dist/terra-draw.cjs +1 -1
- package/dist/terra-draw.cjs.map +1 -1
- package/dist/terra-draw.modern.js +1 -1
- package/dist/terra-draw.modern.js.map +1 -1
- package/dist/terra-draw.module.js +1 -1
- package/dist/terra-draw.module.js.map +1 -1
- package/dist/terra-draw.umd.js +1 -1
- package/dist/terra-draw.umd.js.map +1 -1
- package/guides/GETTING_STARTED.md +40 -0
- package/package.json +1 -1
|
@@ -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
|
+
```
|