@resconet/map-area-tools
v1.1.0
Published
[](https://badge.fury.io/js/%40resconet%2Fmap-area-tools) [](https://opensource.org/licenses/MIT)
Readme
map-area-tools
A JavaScript library for fetching map area geo-polygon with excluded objects, simplifying the map polygons and calculating their area.
Description
This library provides tools for fetching map area geo-polygon with excluded objects, simplifying the map polygons and calculating their area.
Installation
npm
npm install @resconet/map-area-toolsyarn
yarn add @resconet/map-area-toolsUsage
Basic Example
import { createMapAreaFetch, type FetchResult } from "@resconet/map-area-tools";
const onResultFetched = (result?: FetchResult) => {
// Consume result.polygon and result.innerAreas
};
const polygonFetch = await createMapAreaFetch(mapView, buttonContainerElement, onResultFetched, {
timestampProperty: "creation_date",
polygonAreaProperty: "measured_area",
additionalProperties: { name: options.name, id: options.id }, // Set reference or other custom GeoJSON properties
areaUnits: "Hectares",
});
if (options.polygon) {
// Initialize with existing polygons
const innerAreas = options.innerAreas;
await polygonFetch.initialize(JSON.parse(options.polygon), innerAreas ? JSON.parse(innerAreas) : undefined);
}Functions
createMapAreaFetch
Creates map area fetch component on the given map view and adds command buttons to the given button container.
| Function | Type |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| createMapAreaFetch | (mapView: MapView, buttonContainer: HTMLElement, onResultFetched: (result?: FetchResult) => void, options?: GeoJsonOptions): Promise<MapAreaFetch> |
Parameters:
mapView: - Map view where the area fetch component is created.buttonContainer: - HTML element where the buttons are added.onResultFetched: - Callback function that is called when the result is fetched (Save button clicked).options: - Optional fields defining custom GeoJSON properties and map component options.
Returns:
A promise that resolves to the created MapAreaFetch component or undefined if creation failed.
