6.2.1 • Published 11 months ago

@linzjs/landonline-openlayers-map v6.2.1

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

Landonline OpenLayers map (Lolol)

This library has been designed to wrap a domain agnostic OpenLayers map component to behave more like a React component. This gives the advantages of creating a separation of concerns between the host application and the map component. In addition, isolating the map enables provides a component for more targeted automated testing.

Storybook

A number of stories have been created to demonstrate the capabilities and usage of this component. These can be found here

Component

A component LolOpenLayersMap was created, based on the map created as part of the survey application. This manages a native openlayers Map object, which is associated with a <div> in the DOM.

/**
  * Properties for {@link LolOpenLayersMap}
  */
  export interface LolOpenLayersMapProps {
    /** children will be inserted into the DOM after the `map` div */
    children?: ReactNode;
    /** Defines the view with initial viewport coordinates, projection and scale */
    view: LolOpenLayersViewDef;
    /** Provide a setter to put the openlayers `Map` into state or global */
    setMap?: (map: Map) => void;
    /** Defines the Tile, VectorTile and Vector layers that make up the map */
    layers: LolOpenLayersLayerDef[];
    /** Group layers into a collection that are handled together in Openlayers,
     * see https://openlayers.org/en/latest/apidoc/module-ol_layer_Group-LayerGroup.html
     */
    layerGroup?: LolOpenLayersLayerGroupDef;
    /** Indicated if the map component should manage the loading indicator */
    useLoadingIndicator?: boolean;
    /** Use the QueryClient of the parent - required if using queries*/
    queryClient?: QueryClient;
    /** Buffer the default zoom to bufferfactor, e.g. 1.1 leaves a 10% margin, default is 1.05 **/
    bufferFactor?: number;
    /** Interactions for draw **/
    drawInteraction?: LolOpenLayersDrawInteraction;
    /** Interactions for snap **/
    snapInteraction?: LolOpenLayersSnapInteraction;
    /** Interactions for modify **/
    modifyInteraction?: LolOpenLayersModifyInteraction;
    /** For testing, mock the map rather than using Openlayers **/
    mock?: boolean;
    /** Enable an openlayers Overlay which can have its element accessed (to set contents, etc)
    * with mapContext.getOverlayRef
    * https://openlayers.org/en/latest/apidoc/module-ol_Overlay-Overlay.html
    */
    withOverlay?: boolean;
    /** Show default zoom control or not */
    withDefaultZoom?: boolean;
    /** disable zoom on double click */
    disableDoubleClickZoom?: boolean;
    /** Map z index */
    mapZIndex?: number;
    /** enable auto placement */
    enableAutoPlacement?: boolean;
    /** Show only placed labels, hide unplaced */
    showOnlyPlacedLabels?: boolean;
  }

/**
  * React wrapper for the openlayers https://openlayers.org/en/latest/apidoc/ library
  * to render interactive maps
  *
  * @param props The React properties
  */
  export const LolOpenLayersMap = (props: LolOpenLayersMapProps): JSX.Element

Layers within the map can be defined as LolOpenLayersLayerDef which has subclasses:

  • LolOpenLayersTileLayerDef: defines a tile layer, used for basemap, has LolOpenLayersXYZSourceDef to define a source against e.g. services.arcgisonline.com
  • LolOpenLayersVectorTileLayerDef: defines a vector tile layer, has LolOpenLayersMVTSourceDef to define a source for use with Geoserver.
  • LolOpenLayersVectorLayerDef: defines a vector layer. Source feature data can be loaded using LolOpenLayersFeatureSourceDef directly from an array of IFeatureSource, from a React query or loaded from state.

Context

A context LolOpenLayersMapContext allows components at any level to interact with the state of the map.

export type LolOpenLayersMapContextType = {
  /** The status (visibility, etc) of each layer */
  layerStatus: (layerName: string) => ILayerStatus;
  setLayerStatus: (layerName: string, layerStatus: ILayerStatus) => void;
  /** The features dispalyed on a vector layer */
  featureData: (layerName: string) => IFeatureSource[] | undefined;
  setFeatureData: (layerName: string, features: IFeatureSource[]) => void;
  /** Ids of features that are selected, can be changed using set or interactively in the map */
  setFeatureSelect: (layerName: string, selectIds: number[]) => void;
  featureSelect: (layerName: string) => number[];
  /** Incrementing this causes the map to zoom to fit identified layers */
  zoomToFit: number;
  setZoomToFit: React.Dispatch<React.SetStateAction<number>>;
  /** The resolution (e.g. scale) of the map */
  mapResolution: number;
  setMapResolution: (r: number) => void;

  /** Used by LolOpenLayersMap to reflect when features have been changed */
  featuresChanged: (layerName: string) => boolean;
  clearFeaturesChanged: (layerName: string) => void;
  clearFeatureSelectChanged: (layerName: string) => void;
  featureSelectChanged: (layerName: string) => boolean;
};

Development

Using a local copy

If you want to work on this module in the context of your app (e.g https://github.com/linz/landonline-survey) some tweakage is needed: [ Don't commit these, the pipeline won't like it ]

  • Checkout this repo, branch and edit as desired.
  • In your app:
  • npm i --legacy-peer-deps -S <path>\landonline-openlayers-map
  • npm link --legacy-peer-deps -S <path>\landonline-openlayers-map\node_modules\react

(The last step ensures that React uses the version in lolmap and we don't get a hook error. And fixing react-dates might avoid this).

Alternatively, use npm pack in this module to create a tgz file and import this into the application/module by a file:// path.

Logging

This library uses the loglevel package for logging.

To enable logging from a caller, use e.g:

logOpenlayersMap.setLevel(logOpenlayersMap.levels.DEBUG);

To add logs inside the library, import and use log.

Releases

This library uses semantic-release to manage version numbers.

The commit message on master drives the release:

Commit messageRelease type
fix(landonline-openlayers-map): fix a bug with no API changePatch Fix Release
feat(landonline-openlayers-map): enhance with no breaking changeMinor Feature Release
perf(landonline-openlayers-map): make a breaking changeBREAKING CHANGE: The graphiteWidth option has been removed.The default graphite width of 10mm is always used for performance reasons.Major Breaking Release (Note that the BREAKING CHANGE: token must be in the footer of the commit)

"@babel/plugin-proposal-private-property-in-object"

This is required because we use eslint-config-react-app which uses babel-preset-react-app which was causing warning

One of your dependencies, babel-preset-react-app, is importing the
"@babel/plugin-proposal-private-property-in-object" package without
declaring it in its dependencies. This is currently working because
"@babel/plugin-proposal-private-property-in-object" is already in your
node_modules folder for unrelated reasons, but it may break at any time.

is not maintianed anymore. It is thus unlikely that this bug will
ever be fixed. Add "@babel/plugin-proposal-private-property-in-object" to
your devDependencies to work around this error. This will make this message
go away.

If we remove eslint-config-react-app can safely be removed @babel/plugin-proposal-private-property-in-object

Changes

5.2.0

This upgrades OpenLayers to 7.5.2

The following changes in the caller may be required:

  • Enumerated types have been replaced by allowable string types in Openlayers, so you may need to enum constants to strings and remove the type ref

    Examples:

    • GeometryType
    • OverlayPositioning
    • IconAnchorUnits
  • The options to some constructors now need a cast:

    • DrawOptions
    • CanvasTextAlign
  • The Map component calls ResizeObserver which is not implemented in jest-dom.

    You should include the `resize-observer-polyfill` NPM module and add in setupTests.ts: 

    global.ResizeObserver = require("resize-observer-polyfill");

6.0.1

12 months ago

6.0.0

12 months ago

5.3.5

1 year ago

5.3.4

1 year ago

6.1.0

11 months ago

6.2.1

11 months ago

6.2.0

11 months ago

5.3.3

1 year ago

5.3.2

1 year ago

5.3.1

1 year ago

5.3.0

1 year ago

5.2.0

1 year ago

5.1.10

1 year ago

5.1.9

1 year ago

5.1.8

1 year ago

5.1.7

1 year ago

5.1.6

1 year ago

4.0.1

2 years ago

4.0.0

2 years ago

4.0.3

2 years ago

4.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

5.1.5

2 years ago

5.1.4

2 years ago

5.1.3

2 years ago

5.1.2

2 years ago

5.1.1

2 years ago

5.1.0

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.7.0

2 years ago

4.3.2

2 years ago

4.3.1

2 years ago

4.3.4

2 years ago

4.3.3

2 years ago

4.3.0

2 years ago

4.3.6

2 years ago

4.3.5

2 years ago

4.2.0

2 years ago

4.1.0

2 years ago

4.1.1

2 years ago

2.6.2

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.4.3

2 years ago

2.4.2

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.8

2 years ago

2.1.7

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.1.9

2 years ago

2.6.1

2 years ago

2.6.0

2 years ago

2.5.0

2 years ago

2.5.2

2 years ago

2.5.1

2 years ago

2.5.3

2 years ago

1.4.3

2 years ago

1.4.2

2 years ago

1.4.1

2 years ago

1.4.0

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.2.1

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.1

3 years ago

0.48.2

3 years ago

0.48.3

3 years ago

0.48.0

3 years ago

0.48.1

3 years ago

0.48.8

3 years ago

0.48.9

3 years ago

0.48.6

3 years ago

0.48.7

3 years ago

0.48.4

3 years ago

0.48.5

3 years ago

0.49.1

3 years ago

0.49.2

3 years ago

0.49.0

3 years ago

0.49.5

3 years ago

0.49.6

3 years ago

0.49.3

3 years ago

0.49.4

3 years ago

1.0.0

3 years ago

0.48.12

3 years ago

0.48.11

3 years ago

0.48.10

3 years ago

0.50.1

3 years ago

0.50.2

3 years ago

0.50.0

3 years ago

0.47.3

3 years ago

0.47.4

3 years ago

0.47.2

3 years ago

0.47.7

3 years ago

0.47.8

3 years ago

0.47.5

3 years ago

0.47.6

3 years ago

0.43.0

3 years ago

0.44.6

3 years ago

0.44.7

3 years ago

0.44.4

3 years ago

0.44.5

3 years ago

0.44.2

3 years ago

0.44.3

3 years ago

0.44.0

3 years ago

0.44.1

3 years ago

0.44.8

3 years ago

0.44.9

3 years ago

0.44.10

3 years ago

0.45.5

3 years ago

0.44.11

3 years ago

0.45.6

3 years ago

0.44.12

3 years ago

0.45.3

3 years ago

0.44.13

3 years ago

0.45.4

3 years ago

0.44.14

3 years ago

0.45.1

3 years ago

0.45.2

3 years ago

0.45.0

3 years ago

0.41.1

3 years ago

0.41.2

3 years ago

0.41.0

3 years ago

0.38.2

3 years ago

0.38.1

3 years ago

0.38.0

3 years ago

0.38.4

3 years ago

0.38.3

3 years ago

0.42.4

3 years ago

0.42.5

3 years ago

0.42.2

3 years ago

0.42.3

3 years ago

0.42.0

3 years ago

0.42.1

3 years ago

0.39.0

3 years ago

0.43.7

3 years ago

0.43.8

3 years ago

0.43.5

3 years ago

0.43.6

3 years ago

0.43.3

3 years ago

0.43.4

3 years ago

0.43.1

3 years ago

0.43.2

3 years ago

0.36.0

3 years ago

0.40.2

3 years ago

0.40.3

3 years ago

0.40.0

3 years ago

0.40.1

3 years ago

0.37.1

3 years ago

0.37.0

3 years ago

0.41.3

3 years ago

0.46.0

3 years ago

0.47.1

3 years ago

0.47.0

3 years ago

0.19.22

3 years ago

0.20.1

3 years ago

0.20.0

3 years ago

0.19.20

3 years ago

0.19.21

3 years ago

0.17.6

3 years ago

0.32.3

3 years ago

0.17.7

3 years ago

0.32.2

3 years ago

0.17.8

3 years ago

0.32.1

3 years ago

0.17.9

3 years ago

0.17.10

3 years ago

0.17.12

3 years ago

0.17.11

3 years ago

0.17.14

3 years ago

0.17.13

3 years ago

0.17.16

3 years ago

0.17.15

3 years ago

0.32.0

3 years ago

0.29.0

3 years ago

0.25.2

3 years ago

0.25.1

3 years ago

0.25.0

3 years ago

0.21.1

3 years ago

0.17.18

3 years ago

0.17.17

3 years ago

0.17.19

3 years ago

0.29.2

3 years ago

0.29.1

3 years ago

0.17.21

3 years ago

0.17.20

3 years ago

0.17.22

3 years ago

0.21.0

3 years ago

0.18.9

3 years ago

0.18.1

3 years ago

0.18.2

3 years ago

0.18.3

3 years ago

0.18.4

3 years ago

0.18.5

3 years ago

0.33.2

3 years ago

0.18.6

3 years ago

0.33.1

3 years ago

0.18.7

3 years ago

0.33.0

3 years ago

0.18.8

3 years ago

0.18.0

3 years ago

0.26.0

3 years ago

0.22.3

3 years ago

0.22.2

3 years ago

0.22.1

3 years ago

0.22.0

3 years ago

0.18.11

3 years ago

0.18.10

3 years ago

0.18.13

3 years ago

0.18.12

3 years ago

0.18.15

3 years ago

0.18.14

3 years ago

0.18.17

3 years ago

0.18.16

3 years ago

0.19.8

3 years ago

0.19.9

3 years ago

0.34.6

3 years ago

0.19.0

3 years ago

0.34.5

3 years ago

0.19.1

3 years ago

0.34.4

3 years ago

0.19.2

3 years ago

0.34.3

3 years ago

0.19.3

3 years ago

0.34.2

3 years ago

0.19.4

3 years ago

0.34.1

3 years ago

0.19.5

3 years ago

0.34.0

3 years ago

0.19.6

3 years ago

0.19.7

3 years ago

0.18.19

3 years ago

0.18.18

3 years ago

0.18.22

3 years ago

0.18.21

3 years ago

0.18.24

3 years ago

0.18.23

3 years ago

0.18.26

3 years ago

0.18.25

3 years ago

0.18.28

3 years ago

0.18.27

3 years ago

0.30.0

3 years ago

0.18.20

3 years ago

0.27.2

3 years ago

0.23.6

3 years ago

0.27.1

3 years ago

0.23.5

3 years ago

0.27.0

3 years ago

0.23.4

3 years ago

0.23.3

3 years ago

0.23.2

3 years ago

0.23.1

3 years ago

0.23.0

3 years ago

0.18.29

3 years ago

0.27.5

3 years ago

0.23.9

3 years ago

0.27.4

3 years ago

0.23.8

3 years ago

0.27.3

3 years ago

0.23.7

3 years ago

0.18.33

3 years ago

0.18.32

3 years ago

0.18.35

3 years ago

0.18.34

3 years ago

0.18.37

3 years ago

0.18.36

3 years ago

0.18.39

3 years ago

0.18.38

3 years ago

0.18.31

3 years ago

0.18.30

3 years ago

0.35.1

3 years ago

0.31.5

3 years ago

0.35.0

3 years ago

0.31.4

3 years ago

0.31.3

3 years ago

0.31.2

3 years ago

0.19.11

3 years ago

0.19.12

3 years ago

0.19.13

3 years ago

0.19.14

3 years ago

0.19.15

3 years ago

0.19.16

3 years ago

0.19.17

3 years ago

0.19.18

3 years ago

0.31.1

3 years ago

0.31.0

3 years ago

0.19.10

3 years ago

0.28.1

3 years ago

0.28.0

3 years ago

0.20.7

3 years ago

0.20.6

3 years ago

0.24.1

3 years ago

0.20.5

3 years ago

0.24.0

3 years ago

0.20.4

3 years ago

0.20.3

3 years ago

0.20.2

3 years ago

0.19.19

3 years ago

0.28.2

3 years ago

0.17.5

3 years ago

0.17.4

3 years ago

0.17.3

3 years ago

0.17.2

3 years ago

0.17.1

3 years ago

0.17.0

3 years ago