npm.io
20.0.0 • Published 2 weeks ago

@opengeoweb/core

Licence
Apache-2.0
Version
20.0.0
Deps
0
Vulns
0
Weekly
0

current version coverage

Core

React component library with Core components for the opengeoweb project. This library was generated with Nx.

Installation

npm install @opengeoweb/core @opengeoweb/store @opengeoweb/time-slider

Use

You can use any component exported from core by importing them. Some components need to be wrapped in the CoreThemeProvider, or CoreThemeStoreProvider for a connected component. You can also pass in your own theme if needed. Below you can find a simplified example on how the MapViewConnect component and several mapActions could be used:

import { useDispatch } from 'react-redux';
import {
  MapViewConnect,
  LegendConnect,
  LegendMapButtonConnect,
  CoreThemeStoreProvider,
} from '@opengeoweb/core';
import { storeMiddlewares, storeReducerMap } from '@opengeoweb/store';
import { TimeSliderConnect } from '@opengeoweb/time-slider';
import { configureStore } from '@reduxjs/toolkit';

const store = configureStore({
  reducer: {
    ...storeReducerMap,
  },
  middleware: [...storeMiddlewares],
});

const ConnectedMapWithTimeSlider = ({ mapId }) => {
  const dispatch = useDispatch();

  React.useEffect(() => {
    // set layers
    dispatch(mapActions.setLayers({ layers: [radarLayer], mapId }));
    // baseLayers
    dispatch(
      mapActions.setBaseLayers({
        mapId,
        layers: [baseLayerGrey, overLayer],
      }),
    );
  }, []);

  return (
    <CoreThemeStoreProvider store={store}>
      <LegendConnect initialActiveMapId={mapId} />
      <LegendMapButtonConnect mapId={mapId} />
      <MapViewConnect mapId={mapId} displayTimeInMap />
      <TimeSliderConnect sourceId="timeslider-1" mapId={mapId} />
    </CoreThemeStoreProvider>
  );
};

export default ConnectedMapWithTimeSlider;
TypeScript Documentation