5.3.3 • Published 1 month ago

@linzjs/landonline-openlayers-map v5.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month 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");

5.3.3

1 month ago

5.3.2

1 month ago

5.3.1

1 month ago

5.3.0

2 months ago

5.2.0

2 months ago

5.1.10

2 months ago

5.1.9

3 months ago

5.1.8

3 months ago

5.1.7

3 months ago

5.1.6

4 months ago

4.0.1

10 months ago

4.0.0

10 months ago

4.0.3

9 months ago

4.0.2

10 months ago

5.0.1

7 months ago

5.0.0

7 months ago

5.1.5

5 months ago

5.1.4

6 months ago

5.1.3

6 months ago

5.1.2

6 months ago

5.1.1

6 months ago

5.1.0

7 months ago

3.0.1

10 months ago

3.0.0

10 months ago

2.7.0

10 months ago

4.3.2

8 months ago

4.3.1

8 months ago

4.3.4

7 months ago

4.3.3

8 months ago

4.3.0

8 months ago

4.3.6

7 months ago

4.3.5

7 months ago

4.2.0

9 months ago

4.1.0

9 months ago

4.1.1

9 months ago

2.6.2

10 months ago

2.4.1

11 months ago

2.4.0

11 months ago

2.4.3

11 months ago

2.4.2

11 months ago

2.3.0

11 months ago

2.2.0

11 months ago

2.1.2

12 months ago

2.1.1

12 months ago

2.1.4

12 months ago

2.1.3

12 months ago

2.1.6

11 months ago

2.1.5

12 months ago

2.1.8

11 months ago

2.1.7

11 months ago

2.1.0

12 months ago

2.0.1

12 months ago

2.0.0

1 year ago

2.1.9

11 months ago

2.6.1

10 months ago

2.6.0

11 months ago

2.5.0

11 months ago

2.5.2

11 months ago

2.5.1

11 months ago

2.5.3

11 months ago

1.4.3

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.2.1

1 year ago

1.1.11

1 year ago

1.1.10

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.0.1

1 year ago

0.48.2

2 years ago

0.48.3

2 years ago

0.48.0

2 years ago

0.48.1

2 years ago

0.48.8

2 years ago

0.48.9

2 years ago

0.48.6

2 years ago

0.48.7

2 years ago

0.48.4

2 years ago

0.48.5

2 years ago

0.49.1

2 years ago

0.49.2

2 years ago

0.49.0

2 years ago

0.49.5

2 years ago

0.49.6

2 years ago

0.49.3

2 years ago

0.49.4

2 years ago

1.0.0

2 years ago

0.48.12

2 years ago

0.48.11

2 years ago

0.48.10

2 years ago

0.50.1

2 years ago

0.50.2

2 years ago

0.50.0

2 years ago

0.47.3

2 years ago

0.47.4

2 years ago

0.47.2

2 years ago

0.47.7

2 years ago

0.47.8

2 years ago

0.47.5

2 years ago

0.47.6

2 years ago

0.43.0

2 years ago

0.44.6

2 years ago

0.44.7

2 years ago

0.44.4

2 years ago

0.44.5

2 years ago

0.44.2

2 years ago

0.44.3

2 years ago

0.44.0

2 years ago

0.44.1

2 years ago

0.44.8

2 years ago

0.44.9

2 years ago

0.44.10

2 years ago

0.45.5

2 years ago

0.44.11

2 years ago

0.45.6

2 years ago

0.44.12

2 years ago

0.45.3

2 years ago

0.44.13

2 years ago

0.45.4

2 years ago

0.44.14

2 years ago

0.45.1

2 years ago

0.45.2

2 years ago

0.45.0

2 years ago

0.41.1

2 years ago

0.41.2

2 years ago

0.41.0

2 years ago

0.38.2

2 years ago

0.38.1

2 years ago

0.38.0

2 years ago

0.38.4

2 years ago

0.38.3

2 years ago

0.42.4

2 years ago

0.42.5

2 years ago

0.42.2

2 years ago

0.42.3

2 years ago

0.42.0

2 years ago

0.42.1

2 years ago

0.39.0

2 years ago

0.43.7

2 years ago

0.43.8

2 years ago

0.43.5

2 years ago

0.43.6

2 years ago

0.43.3

2 years ago

0.43.4

2 years ago

0.43.1

2 years ago

0.43.2

2 years ago

0.36.0

2 years ago

0.40.2

2 years ago

0.40.3

2 years ago

0.40.0

2 years ago

0.40.1

2 years ago

0.37.1

2 years ago

0.37.0

2 years ago

0.41.3

2 years ago

0.46.0

2 years ago

0.47.1

2 years ago

0.47.0

2 years ago

0.19.22

2 years ago

0.20.1

2 years ago

0.20.0

2 years ago

0.19.20

2 years ago

0.19.21

2 years ago

0.17.6

2 years ago

0.32.3

2 years ago

0.17.7

2 years ago

0.32.2

2 years ago

0.17.8

2 years ago

0.32.1

2 years ago

0.17.9

2 years ago

0.17.10

2 years ago

0.17.12

2 years ago

0.17.11

2 years ago

0.17.14

2 years ago

0.17.13

2 years ago

0.17.16

2 years ago

0.17.15

2 years ago

0.32.0

2 years ago

0.29.0

2 years ago

0.25.2

2 years ago

0.25.1

2 years ago

0.25.0

2 years ago

0.21.1

2 years ago

0.17.18

2 years ago

0.17.17

2 years ago

0.17.19

2 years ago

0.29.2

2 years ago

0.29.1

2 years ago

0.17.21

2 years ago

0.17.20

2 years ago

0.17.22

2 years ago

0.21.0

2 years ago

0.18.9

2 years ago

0.18.1

2 years ago

0.18.2

2 years ago

0.18.3

2 years ago

0.18.4

2 years ago

0.18.5

2 years ago

0.33.2

2 years ago

0.18.6

2 years ago

0.33.1

2 years ago

0.18.7

2 years ago

0.33.0

2 years ago

0.18.8

2 years ago

0.18.0

2 years ago

0.26.0

2 years ago

0.22.3

2 years ago

0.22.2

2 years ago

0.22.1

2 years ago

0.22.0

2 years ago

0.18.11

2 years ago

0.18.10

2 years ago

0.18.13

2 years ago

0.18.12

2 years ago

0.18.15

2 years ago

0.18.14

2 years ago

0.18.17

2 years ago

0.18.16

2 years ago

0.19.8

2 years ago

0.19.9

2 years ago

0.34.6

2 years ago

0.19.0

2 years ago

0.34.5

2 years ago

0.19.1

2 years ago

0.34.4

2 years ago

0.19.2

2 years ago

0.34.3

2 years ago

0.19.3

2 years ago

0.34.2

2 years ago

0.19.4

2 years ago

0.34.1

2 years ago

0.19.5

2 years ago

0.34.0

2 years ago

0.19.6

2 years ago

0.19.7

2 years ago

0.18.19

2 years ago

0.18.18

2 years ago

0.18.22

2 years ago

0.18.21

2 years ago

0.18.24

2 years ago

0.18.23

2 years ago

0.18.26

2 years ago

0.18.25

2 years ago

0.18.28

2 years ago

0.18.27

2 years ago

0.30.0

2 years ago

0.18.20

2 years ago

0.27.2

2 years ago

0.23.6

2 years ago

0.27.1

2 years ago

0.23.5

2 years ago

0.27.0

2 years ago

0.23.4

2 years ago

0.23.3

2 years ago

0.23.2

2 years ago

0.23.1

2 years ago

0.23.0

2 years ago

0.18.29

2 years ago

0.27.5

2 years ago

0.23.9

2 years ago

0.27.4

2 years ago

0.23.8

2 years ago

0.27.3

2 years ago

0.23.7

2 years ago

0.18.33

2 years ago

0.18.32

2 years ago

0.18.35

2 years ago

0.18.34

2 years ago

0.18.37

2 years ago

0.18.36

2 years ago

0.18.39

2 years ago

0.18.38

2 years ago

0.18.31

2 years ago

0.18.30

2 years ago

0.35.1

2 years ago

0.31.5

2 years ago

0.35.0

2 years ago

0.31.4

2 years ago

0.31.3

2 years ago

0.31.2

2 years ago

0.19.11

2 years ago

0.19.12

2 years ago

0.19.13

2 years ago

0.19.14

2 years ago

0.19.15

2 years ago

0.19.16

2 years ago

0.19.17

2 years ago

0.19.18

2 years ago

0.31.1

2 years ago

0.31.0

2 years ago

0.19.10

2 years ago

0.28.1

2 years ago

0.28.0

2 years ago

0.20.7

2 years ago

0.20.6

2 years ago

0.24.1

2 years ago

0.20.5

2 years ago

0.24.0

2 years ago

0.20.4

2 years ago

0.20.3

2 years ago

0.20.2

2 years ago

0.19.19

2 years ago

0.28.2

2 years ago

0.17.5

2 years ago

0.17.4

2 years ago

0.17.3

2 years ago

0.17.2

2 years ago

0.17.1

2 years ago

0.17.0

2 years ago