Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@geospatial-sdk/core

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@geospatial-sdk/core - npm Package Compare versions

Comparing version 0.0.5-dev.10 to 0.0.5-dev.11

35

dist/utils/map-context.d.ts

@@ -6,2 +6,37 @@ import { MapContext, MapContextLayer } from "../model";

export declare function getLayerPosition(context: MapContext, layerModel: MapContextLayer): number;
/**
* Adds a layer to the context at a specific position or at the end if no position is specified.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer to be added.
* @param {number} [position] - The position at which to add the layer. If not specified, the layer is added at the end.
* @returns {MapContext} - The new map context with the added layer.
*/
export declare function addLayerToContext(context: MapContext, layerModel: MapContextLayer, position?: number): MapContext;
/**
* Removes a layer from the context.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer to be removed.
* @returns {MapContext} - The new map context without the removed layer.
*/
export declare function removeLayerFromContext(context: MapContext, layerModel: MapContextLayer): MapContext;
/**
* Replaces a layer in the context with a new layer.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer to be replaced.
* @param {MapContextLayer} replacement - The new layer that will replace the old one.
* @returns {MapContext} - The new map context with the replaced layer.
*/
export declare function replaceLayerInContext(context: MapContext, layerModel: MapContextLayer, replacement: MapContextLayer): MapContext;
/**
* Changes the position of a layer in the context.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer whose position is to be changed.
* @param {number} position - The new position for the layer.
* @returns {MapContext} - The new map context with the layer moved to the new position.
*/
export declare function changeLayerPositionInContext(context: MapContext, layerModel: MapContextLayer, position: number): MapContext;
//# sourceMappingURL=map-context.d.ts.map

@@ -37,1 +37,62 @@ export function getLayerHash(layer, includeExtras = false) {

}
/**
* Adds a layer to the context at a specific position or at the end if no position is specified.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer to be added.
* @param {number} [position] - The position at which to add the layer. If not specified, the layer is added at the end.
* @returns {MapContext} - The new map context with the added layer.
*/
export function addLayerToContext(context, layerModel, position) {
const newContext = Object.assign(Object.assign({}, context), { layers: [...context.layers] });
if (position !== undefined) {
newContext.layers.splice(position, 0, layerModel);
}
else {
newContext.layers.push(layerModel);
}
return newContext;
}
/**
* Removes a layer from the context.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer to be removed.
* @returns {MapContext} - The new map context without the removed layer.
*/
export function removeLayerFromContext(context, layerModel) {
const newContext = Object.assign(Object.assign({}, context), { layers: [...context.layers] });
const position = getLayerPosition(context, layerModel);
if (position >= 0) {
newContext.layers.splice(position, 1);
}
return newContext;
}
/**
* Replaces a layer in the context with a new layer.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer to be replaced.
* @param {MapContextLayer} replacement - The new layer that will replace the old one.
* @returns {MapContext} - The new map context with the replaced layer.
*/
export function replaceLayerInContext(context, layerModel, replacement) {
const newContext = Object.assign(Object.assign({}, context), { layers: [...context.layers] });
const position = getLayerPosition(context, layerModel);
if (position >= 0) {
newContext.layers.splice(position, 1, replacement);
}
return newContext;
}
/**
* Changes the position of a layer in the context.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer whose position is to be changed.
* @param {number} position - The new position for the layer.
* @returns {MapContext} - The new map context with the layer moved to the new position.
*/
export function changeLayerPositionInContext(context, layerModel, position) {
const newContext = removeLayerFromContext(context, layerModel);
return addLayerToContext(newContext, layerModel, position);
}

67

lib/utils/map-context.test.ts
import { describe } from "vitest";
import {
getLayerHash,
getLayerPosition,
isLayerSame,
isLayerSameAndUnchanged,
addLayerToContext, changeLayerPositionInContext,
getLayerHash,
getLayerPosition,
isLayerSame,
isLayerSameAndUnchanged, removeLayerFromContext, replaceLayerInContext,
} from "./map-context";
import { MapContext } from "../model";
import {
SAMPLE_CONTEXT,
SAMPLE_LAYER1,
SAMPLE_LAYER2,
SAMPLE_CONTEXT,
SAMPLE_LAYER1,
SAMPLE_LAYER2, SAMPLE_LAYER3,
} from "../../fixtures/map-context.fixtures";

@@ -303,2 +304,54 @@

});
describe("addLayerToContext", () => {
it("adds a layer to the context", () => {
const context: MapContext = {
...SAMPLE_CONTEXT,
layers: [SAMPLE_LAYER1],
};
const newLayer = { ...SAMPLE_LAYER2, name: "newLayer" };
const newContext = addLayerToContext(context, newLayer);
expect(newContext.layers).toEqual([SAMPLE_LAYER1, newLayer]);
});
it("adds a layer at a specific position", () => {
const context: MapContext = {
...SAMPLE_CONTEXT,
layers: [SAMPLE_LAYER1, SAMPLE_LAYER2],
};
const newLayer = { ...SAMPLE_LAYER2, name: "newLayer" };
const newContext = addLayerToContext(context, newLayer, 1);
expect(newContext.layers).toEqual([SAMPLE_LAYER1, newLayer, SAMPLE_LAYER2]);
});
});
describe("removeLayerFromContext", () =>{
it("removes a layer from the context", () => {
const context: MapContext = {
...SAMPLE_CONTEXT,
layers: [SAMPLE_LAYER1, SAMPLE_LAYER2],
};
const newContext = removeLayerFromContext(context, SAMPLE_LAYER1);
expect(newContext.layers).toEqual([SAMPLE_LAYER2]);
});
});
describe("replaceLayerInContext", () => {
it("replaces a layer in the context", () => {
const context: MapContext = {
...SAMPLE_CONTEXT,
layers: [SAMPLE_LAYER1, SAMPLE_LAYER2],
};
const replacementLayer = { ...SAMPLE_LAYER3};
const existingLayer = { ...SAMPLE_LAYER1};
const newContext = replaceLayerInContext(context, existingLayer, replacementLayer);
expect(newContext.layers).toEqual([replacementLayer, SAMPLE_LAYER2]);
});
});
describe("changeLayerPositionInContext", () => {
it("changes the position of a layer in the context", () => {
const context: MapContext = {
...SAMPLE_CONTEXT,
layers: [SAMPLE_LAYER1, SAMPLE_LAYER2],
};
const newContext = changeLayerPositionInContext(context, SAMPLE_LAYER1, 1);
expect(newContext.layers).toEqual([SAMPLE_LAYER2, SAMPLE_LAYER1]);
});
});
});

@@ -52,1 +52,84 @@ import { MapContext, MapContextLayer } from "../model";

}
/**
* Adds a layer to the context at a specific position or at the end if no position is specified.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer to be added.
* @param {number} [position] - The position at which to add the layer. If not specified, the layer is added at the end.
* @returns {MapContext} - The new map context with the added layer.
*/
export function addLayerToContext(
context: MapContext,
layerModel: MapContextLayer,
position?: number,
): MapContext {
const newContext = { ...context, layers: [...context.layers]};
if (position !== undefined) {
newContext.layers.splice(position, 0, layerModel);
} else {
newContext.layers.push(layerModel);
}
return newContext;
}
/**
* Removes a layer from the context.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer to be removed.
* @returns {MapContext} - The new map context without the removed layer.
*/
export function removeLayerFromContext(
context: MapContext,
layerModel: MapContextLayer,
): MapContext {
const newContext = { ...context, layers: [...context.layers] };
const position = getLayerPosition(context, layerModel);
if (position >= 0) {
newContext.layers.splice(position, 1);
}
return newContext;
}
/**
* Replaces a layer in the context with a new layer.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer to be replaced.
* @param {MapContextLayer} replacement - The new layer that will replace the old one.
* @returns {MapContext} - The new map context with the replaced layer.
*/
export function replaceLayerInContext(
context: MapContext,
layerModel: MapContextLayer,
replacement: MapContextLayer,
): MapContext {
const newContext = { ...context, layers: [...context.layers] };
const position = getLayerPosition(context, layerModel);
if (position >= 0) {
newContext.layers.splice(position, 1, replacement);
}
return newContext;
}
/**
* Changes the position of a layer in the context.
*
* @param {MapContext} context - The current map context.
* @param {MapContextLayer} layerModel - The layer whose position is to be changed.
* @param {number} position - The new position for the layer.
* @returns {MapContext} - The new map context with the layer moved to the new position.
*/
export function changeLayerPositionInContext(
context: MapContext,
layerModel: MapContextLayer,
position: number,
): MapContext {
const newContext = removeLayerFromContext(context, layerModel);
return addLayerToContext(newContext, layerModel, position);
}

4

package.json
{
"name": "@geospatial-sdk/core",
"version": "0.0.5-dev.10+cc9736c",
"version": "0.0.5-dev.11+a94ee71",
"description": "Core functions and models for the SDK",

@@ -25,3 +25,3 @@ "author": "Olivia <olivia.guyot@camptocamp.com>",

},
"gitHead": "cc9736c7f9471df0304b3beb82ed31f8926ab627"
"gitHead": "a94ee7178decefed3ba074bbfd8a1a7c1813706d"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc