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

@open-formulieren/leaflet-tools

Package Overview
Dependencies
Maintainers
2
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@open-formulieren/leaflet-tools

Shared utilities for Leaflet maps and Dutch (NL) geo standards

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1K
decreased by-6.27%
Maintainers
2
Weekly downloads
 
Created
Source

Leaflet tools

Leaflet tools sets up some commonly shared/copy-pasted snippets for working with Dutch (goverment) geo standards, such as the "Rijksdriehoek" (RD) coordinate system.

Run CI build and tests

Usage

The library ships constants/utilities that can be used both in imperative, vanilla JS or with UI libraries like React.

In vanilla JS

import * as L from 'leaflet';
import {CRS_RD, TILE_LAYER_RD} from '@open-formulieren/leaflet-tools';

const map = L.map('my-map', {
  continuousWorld: true,
  crs: CRS_RD, // use Rijksdriehoek coordinate system
  attributionControl: true,
  center: [52.1326332, 5.291266], // must be provided as EPSG:4326 coordinates, is transformed via `crs` option
  zoom: 3, // value between 0-13
});
const {url, ...options} = TILE_LAYER_RD;
const tiles = L.tileLayer(url, options);
map.addLayer(tiles);

With React

import {MapContainer, TileLayer} from 'react-leaflet';
import {CRS_RD, TILE_LAYER_RD} from '@open-formulieren/leaflet-tools';

const MyMap = () => (
  <MapContainer
    continuousWorld
    crs={CRS_RD}
    attributionControl
    center={[52.1326332, 5.291266]}
    zoom={3}
  >
    <TileLayer {...TILE_LAYER_RD} />
  </MapContainer>
);

Background

While the code itself is not particularly exciting, there are a lot of magic numbers and configuration that require some context to properly judge them and recording that context is arguably the biggest benefit of a standalone library/repository.

The Geoforum thread is quite informative, as it points to the PROJ4 projection that is defined in this library, which itself is taken from an examples repository by @arbakker. It points out a number of issues:

  • the projection has accuracy issues (typically in the order of centimeters)
  • the correct approach is taking a correction grid into consideration, but this requires additional files that are not easily discovered/obtained, let alone used in a Javascript context
  • PROJ4 is apparently quite outdated, PROJ6 and even PROJ7 are a thing by "now" (the thread is from 2020, so this may also be outdated again)
  • A coordinate reference system like EPSG:28992 with just that number doesn't specify much, it basically only guarantees that the coordinates are to be interpreted as distances in meters (unit), but projections themselves also have a number, e.g. EPSG 28992, transformation 9282 properly identifies a certain projection with a particular PROJ4 string, and from there on you can make claims about accuracy.
  • There are probably better (more accurate) transformations, but the maintainers don't fully understand how this relates to bounds, origin and resolutions.

In search of a definitive source on what and how things should be done, we also came across other implementations which use different PROJ4 transformation strings. The particular transformation string in this codebase was not found on epsg.io, but that doesn't really mean anything, as this is not an official/authorative source (!). epsg.org is the actual authorative database, and the Dutch geo organizations submit official dataset there.

Geonovum/kadaster also supports nlmaps.nl, which doesn't appear to apply the RD CRS but instead uses either the global or European coordinate systems. Some transformation strings were found in commented out code.

The data.amsterdam.nl map view was inspected, which yielded the same transformation string as used in this codebase. It is plausible they also took it from @arbakker's example repository.

With regard to a bunch of magic numbers, the document "Nederlandse richtlijn tiling versie 1.1" was quite informative and provided context, such as describing the resolution (in pixels per meter) for each zoom level, where the zoom levels map 1-to-1 to the zoom levels used in Leaflet (leaflet supports 0-20, but the document provides in zoom levels 1-13).

From this short summary, you can conclude that this is an extremely big and complicated topic and the disclaimer then also follows that if (high) accuracy is crucial, you definitely should not be using this library.

References

Keywords

FAQs

Package last updated on 13 Dec 2023

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