npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@barcia/maptools

v1.0.0-alpha.1

Published

A set of GeoJSON tools

Downloads

1

Readme

MapTools

A set of GeoJSON tools

Read GeoJSON Specification

Getting Started

  1. Install the library:

    npm install @barcia/maptools
  2. Import some utility in your JS code

    import { Feature } from 'maptools'
  3. Create a new GeoJSON feature

    const feature = new Feature('Point', [103.32, 34.21], { name: "Interesting point" })
    
    const geojsonFeature = feature.toJSON()

API

Table of Contents

  1. MapTools
    1. Getting Started
    2. API
      1. Table of Contents
      2. Feature
        1. Parameters
        2. Examples
        3. addProperty
          1. Parameters
          2. Examples
        4. toJSON
          1. Examples
        5. fromJSON
          1. Parameters
          2. Examples
      3. FeatureCollection
        1. Parameters
        2. Examples
        3. addFeatures
          1. Parameters
          2. Examples
        4. removeFeatures
          1. Parameters
          2. Examples
        5. toJSON
          1. Examples
        6. fromJSON
          1. Parameters
          2. Examples
      4. Geometry
        1. Parameters
        2. Examples
        3. toJSON
          1. Examples
        4. fromJSON
          1. Parameters
          2. Examples
        5. validate
          1. Parameters
          2. Examples
      5. GeometryCollection
        1. Parameters
        2. Examples
        3. addGeometries
          1. Parameters
          2. Examples
        4. toJSON
          1. Examples
        5. fromJSON
          1. Parameters
          2. Examples

Feature

Create a GeoJSON Feature.

Parameters

  • type ("Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon") The Feature type.
  • coords Array The Feature coordinates with the format [lon, lat, alt], while alt is optional.
  • props Object? The Feature properties.

Examples

const feature = new Feature('Point', [105.0, 4.0], { name: 'foo' });

addProperty

Add a new property to the Feature or update an existing one.

Parameters
  • key string The property key.
  • value any The property value.
Examples
feature.addProperty('desc', 'bar');

toJSON

Return the Feature object.

Examples
feature.toJSON();

Returns Object The Feature object

fromJSON

Create a Feature instance from a GeoJSON feature object.

Parameters
  • json Object A valid GeoJSON feature object.

    • json.type ("Feature") The feature type.

    • json.geometry Object A valid GeoJSON geometry.

      • json.geometry.type ("Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon") The Feature geometry type.
      • json.geometry.coordinates Array The Feature coordinates with the format [lon, lat, alt], while alt is optional.
    • json.properties Object? The Feature properties.

Examples
const feature = Feature.fromJSON({
	type: 'Feature',
	geometry: {
		type: 'Point',
		coordinates: [105.0, 4.0]
	},
	properties: {
		name: 'foo'
	}
});

Returns Feature The Feature instance.

FeatureCollection

Create a FeatureCollection.

Parameters

  • features Array The FeatureCollection features array.
  • props Object? The FeatureCollection properties.

Examples

const featureCollection = new FeatureCollection([
	new Feature('Point', [100.0, 0.0]).toJSON(),
	new Feature('Point', [101.0, 1.0]).toJSON()
], { name: 'foo' });

addFeatures

Add new features to the FeatureCollection.

Parameters
  • features Array The array with Features to add.
Examples
featureCollection.addFeatures([
	new Feature('Point', [103.0, 7.0]).toJSON(),
]);

removeFeatures

Remove features from the FeatureCollection.

Parameters
  • func Function The function to filter the features to remove. Uses native JS Array.filter() method.
  • dryrun boolean IF true, return the features to remove but don't remove them. (optional, default false)
Examples
featureCollection.removeFeatures(feature => feature.properties.name === 'foo');

toJSON

Return the FeatureCollection object.

Examples
featureCollection.toJSON();

Returns Object The FeatureCollection object

fromJSON

Create a FeatureCollection instance from a GeoJSON featureCollection object.

Parameters
  • json Object A valid GeoJSON featureCollection object.

    • json.type ("FeatureCollection") The featureCollection type.
    • json.features Array An array of features.
    • json.properties Object? The FeatureCollection properties.
Examples
const featureCollection = FeatureCollection.fromJSON({
	type: 'FeatureCollection',
	features: [
		{
			type: 'Feature',
			geometry: {
				type: 'Point',
				coordinates: [100.0, 0.0]
			},
		},
	]
});

Returns FeatureCollection The FeatureCollection instance.

Geometry

Create a GeoJSON Geometry.

Parameters

  • type ("Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon") The Geometry type.
  • coords Array The Geometry coordinates with the format [lon, lat, alt], while alt is optional.

Examples

const geometry = new Geometry('Point', [105.0, 4.0]);

toJSON

Return the Geometry object.

Examples
// { type: 'Point', coordinates: [105.0, 4.0] }
geometry.toJSON();

Returns Object The Geometry object

fromJSON

Create a Geometry instance from a GeoJSON geometry object.

Parameters
  • json Object A valid GeoJSON geometry object.

    • json.type ("Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon") The Geometry type.
    • json.coordinates Array The Geometry coordinates with the format [lon, lat, alt], while alt is optional.
Examples
const geometry = Geometry.fromJSON({
		type: 'Point',
		coordinates: [105.0, 4.0]
	});

Returns Geometry The Geometry instance.

validate

Validate a Geometry.

Parameters
  • type ("Point" | "LineString" | "Polygon" | "MultiPoint" | "MultiLineString" | "MultiPolygon") The Geometry type.
  • coords Array The Geometry coordinates with the format [lon, lat, alt], while alt is optional.
Examples
const isValidPoint = Geometry.validate({
		type: 'Point',
		coordinates: [105.0, 4.0]
	});

Returns boolean True if the Geometry is valid, false otherwise.

GeometryCollection

Create a GeometryCollection.

Parameters

  • geometries Array The GeometryCollection features array.

Examples

const geometryCollection = new GeometryCollection([
	new Geometry('Point', [100.0, 0.0]).toJSON(),
	new Geometry('Point', [101.0, 1.0]).toJSON()
]);

addGeometries

Add new geometries to the GeometryCollection.

Parameters
  • geometries Array The array with geometries to add.
Examples
geometryCollection.addGeometries([
	new Geometry('Point', [103.0, 7.0]).toJSON(),
]);

toJSON

Return the GeometryCollection object.

Examples
geometryCollection.toJSON();

Returns Object The GeometryCollection object

fromJSON

Create a GeometryCollection from a GeoJSON geometryCollection object.

Parameters
  • json Object A valid GeoJSON geometryCollection object.

    • json.type ("GeometryCollection") The geometryCollection type.
    • json.geometries Array An array of geometries.
Examples
const geometryCollection = GeometryCollection.fromJSON({
	type: 'GeometryCollection',
	geometries: [
		{
			type: 'Point',
			coordinates: [100.0, 0.0]
		},
		{
			type: 'Point',
			coordinates: [101.0, 1.0]
		}
	]
});

Returns GeometryCollection The GeometryCollection instance.