@yaga/geojson-redux
TypeScript icon, indicating that this package has built-in type declarations

1.0.1 • Public • Published

GeoJSON in states with Redux

Build Status Coverage Status FOSSA Status

YAGA's geojson-redux is a predictable state container implementation for GeoJSON in Redux.

How to use

First you have to install this library from npm:

npm install --save @yaga/geojson-redux
# OR
yarn isntall --save @yaga/geojson-redux # for those who prefer yarn...

This module works like a normal Redux module. You should do something like that:

import { createStore, combineReducers } from "redux"
import { geoJSONReducer } from "@yaga/geojson-redux";

const reducer = combineReducers({
    geojson: geoJSONReducer,
    // maybe: anotherReducer
});

const store = createStore(reducer);

If you want to use it in a simple way, just for GeoJSON and not in combination with other Redux reducers:

import { createGeoJSONStore } from "@yaga/geojson-redux";
const store = createGeoJSONStore();

Note: This module is developed in TypeScript. You can specify the Geometry and properties type

import { createGeoJSONStore } from "@yaga/geojson-redux";
import { Point } from "geojson";

interface IMyProperties {
    name: string;
}

const store = createGeoJSONStore<Point, IMyProperties>();

Working with this geojson-redux

After you created your store you can handle your store by actions:

store.dispatch(action);

You can perform the following action:

  • addFeature
  • removeFeature
  • changeGeometry
  • changeProperties

Add feature

const geoJSONFeature = {
    geometry: {
        type: "Point",
        coordinates: [
            // ...
        ],
    },
    properties: {
        // ...
    },
    type: "Feature",
};

const addAction = {
    type: "addFeature",
    feature: geoJSONFeature,
};

store.dispatch(addAction);

Note: every feature will get an autogenerated ID if you not specify one!

Remove feature

const removeAction = {
    type: "removeFeature",
    featureId: "feature-id",
};

store.dispatch(removeAction);

Change geometry of a feature

const geoJSONGeometry = {
    coordinates: [1,2],
    type: "Point",
};
const changeGeometryAction = {
    type: "changeGeometry",
    featureId: "feature-id",
    geometry: geoJSONGeometry,
};

store.dispatch(changeGeometryAction);

Change properties of a feature

const geoJSONProperties = {
    name: "just a test",
    test: "OK",
};
const changePropertiesAction = {
    type: "changeProperties",
    featureId: "feature-id",
    geometry: geoJSONProperties,
};

store.dispatch(changePropertiesAction);

License

This library is released under the ISC License.

FOSSA Status

Readme

Keywords

Package Sidebar

Install

npm i @yaga/geojson-redux

Weekly Downloads

7

Version

1.0.1

License

ISC

Last publish

Collaborators

  • openstevemap
  • atd