Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@planet/maps

Package Overview
Dependencies
Maintainers
7
Versions
596
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@planet/maps

Declarative mapping components for React

  • 8.0.0-dev.1667791975053
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
693
increased by10.17%
Maintainers
7
Weekly downloads
 
Created
Source

@planet/maps

Test Status

Declarative mapping components

Use

npm install @planet/maps

Import the components you need for your map. Provide an options prop to pass to the underlying OpenLayers constructor. Provide other props for values that you want to update with state changes.

import Map from '@planet/maps/lib/Map';
import OSM from '@planet/maps/lib/source/OSM';
import ScaleLine from '@planet/maps/lib/control/ScaleLine';
import View from '@planet/maps/lib/View';
import WebGLTile from '@planet/maps/lib/layer/WebGLTile';

function MyApp() {
  return (
    <Map style={{width: '100%', height: '100%'}}>
      <View options={{center: [0, 0], zoom: 1}} />
      <WebGLTile>
        <OSM />
      </WebGLTile>
      <ScaleLine />
    </Map>
  );
}

You can also listen to any events on the map, view, controls, interactions, layers, or sources; use refs to get access to the underlying OpenLayers instances; and more.

Background

React lets you build interactive UIs with (mostly) declarative syntax. OpenLayers provides an imperative API for building mapping apps. It can be awkward to map React's component API to an imperative API. However, the React team provides a package for creating custom renderers: react-reconciler. This is how they integrate with imperative APIs themselves. The react-dom package uses react-reconciler to provide a mapping to the imperative DOM API. react-native uses react-reconciler to map to imperative native APIs.

This library provides declarative mapping components representing imperative APIs from OpenLayers.

Design Goals

The purpose of this project is to provide a mapping between React's declarative components and OpenLayers' imperative API. In other words, this project provides a React renderer for OpenLayers.

Here are some of the goals of this project:

  • Ideally, the renderer would not have any additional dependencies beyond what is bundled with an OpenLayers map.
  • Components exported by this package map 1:1 with classes exported by OpenLayers.
  • Component props map directly to properties that are settable on instances of OpenLayers classes. Exceptions to this are props like options (passed to the constructor only), listener props (e.g. onChange), and ref.
  • Components accept a ref that provide access to the underlying OpenLayers instance.
  • The renderer should add negligible overhead in terms of bundle size, memory consumption, or processing.
  • Code components can be generated by using OpenLayers sources. Exceptions to this are the map component (responsible for invoking the custom renderer) and components that map to classes without subclasses (e.g. the view).

Non-Goals

This project does not intend to provide any of the following:

  • Higher level abstractions or components that combine logic from multiple OpenLayers instances (e.g. an editable layer component that wraps a layer, source, and editing interactions).
  • Styled widgets (e.g. a layer switcher/browser).
  • Other utilities for working with vector data, projections, etc.

We hope that this package can provide the foundation for other, higher-level libraries with more opinions about the look and feel of mapping components.

Development

The development setup depends on Node 18 (most things work on 16, but not all).

Install project dependencies:

npm install

The rendering tests use Playwright for visual snapshot comparison. See the tests/rendering/readme.md for more detail.

Prior Art

Other projects like react-openlayers-fiber and react-ol-fiber use a similar approach and provided inspiration for this project. The major difference between this project and those is that this project provides importable components for OpenLayers layers, sources, controls, and interactions. The other projects bundle all of OpenLayers in their renderer. So a simple "hello world" map with one of the existing projects is about 1.5 MB while the same with this project is about 460 KB.

FAQs

Package last updated on 07 Nov 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc