From 01b2a892432f4c19a114a341cfc1e1e4866ab35c Mon Sep 17 00:00:00 2001 From: ronitjadhav Date: Tue, 17 Dec 2024 12:06:59 +0100 Subject: [PATCH] Resolved PR comments --- packages/legend/README.md | 15 ++++----------- .../legend/lib/create-legend/from-layer.test.ts | 12 ++++++------ packages/legend/lib/create-legend/from-layer.ts | 13 ++++++------- 3 files changed, 16 insertions(+), 24 deletions(-) diff --git a/packages/legend/README.md b/packages/legend/README.md index a35ec0c..16d2410 100644 --- a/packages/legend/README.md +++ b/packages/legend/README.md @@ -26,17 +26,10 @@ createLegendFromLayer(layer).then((legendDiv) => { }); ``` -## API Documentation +## Documentation -### `createLegendFromLayer(layer: Layer): Promise` +For more detailed API documentation, see the [documentation website](https://camptocamp.github.io/geospatial-sdk/docs/). -Creates a legend from a layer. +## Examples -#### Parameters - -- `layer: (MapContextLayer)`: The layer to create the legend from. -- `options: (LegendOptions, optional)`: The options to create the legend. - -#### Returns - -- `Promise`: A promise that resolves to the legend element or `false` if the legend could not be created. +For examples and demos, see the [examples website](https://camptocamp.github.io/geospatial-sdk/). diff --git a/packages/legend/lib/create-legend/from-layer.test.ts b/packages/legend/lib/create-legend/from-layer.test.ts index b73d003..406895e 100644 --- a/packages/legend/lib/create-legend/from-layer.test.ts +++ b/packages/legend/lib/create-legend/from-layer.test.ts @@ -100,28 +100,28 @@ describe("createLegendFromLayer", () => { ); }); - it("returns false for invalid layer type", async () => { + it("returns null for invalid layer type", async () => { const invalidLayer = { ...baseWmsLayer, type: "invalid" as any }; const result = await createLegendFromLayer(invalidLayer); - expect(result).toBe(false); + expect(result).toBe(null); }); - it("returns false for layer without URL", async () => { + it("returns null for layer without URL", async () => { const layerWithoutUrl = { ...baseWmsLayer, url: "" }; const result = await createLegendFromLayer(layerWithoutUrl); - expect(result).toBe(false); + expect(result).toBe(null); }); - it("returns false for layer without name", async () => { + it("returns null for layer without name", async () => { const layerWithoutName = { ...baseWmsLayer, name: "" }; const result = await createLegendFromLayer(layerWithoutName); - expect(result).toBe(false); + expect(result).toBe(null); }); it("handles image load error", async () => { diff --git a/packages/legend/lib/create-legend/from-layer.ts b/packages/legend/lib/create-legend/from-layer.ts index 279761a..5d142d8 100644 --- a/packages/legend/lib/create-legend/from-layer.ts +++ b/packages/legend/lib/create-legend/from-layer.ts @@ -82,24 +82,23 @@ async function createWmtsLegendUrl( } /** - * Create a legend from a layer + * Creates a legend from a layer. * - * - * @param layer - The MapContextLayer to create a legend from - * @param options - Optional configuration for legend generation - * @returns The legend as a DOM element or false if the legend could not be created + * @param {MapContextLayer} layer - The layer to create the legend from. + * @param {LegendOptions} [options] - The options to create the legend. + * @returns {Promise} A promise that resolves to the legend element or `null` if the legend could not be created. */ export async function createLegendFromLayer( layer: MapContextLayer, options: LegendOptions = {}, -): Promise { +): Promise { if ( (layer.type !== "wms" && layer.type !== "wmts") || !layer.url || !layer.name ) { console.error("Invalid layer for legend creation"); - return false; + return null; } // Create a container for the legend