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

@fboes/geojson

v1.4.1

Published

This dual-purpose library creates GeoJSON according to RFC 7946 in NodeJS as well as directly in your browser.

Downloads

512

Readme

GeoJSON

This dual-purpose library creates GeoJSON according to RFC 7946 in NodeJS as well as directly in your browser.

It contains all of the basic object types of GeoJSON geometries:

  • GeoJson.Point and GeoJson.MultiPoint
  • GeoJson.LineString and GeoJson.MultiLineString
  • GeoJson.Polygon and GeoJson.MultiPolygon
  • GeoJson.GeometryCollection

…and organizational objects:

  • GeoJson.Feature
  • GeoJson.FeatureCollection

Why do we need classes to build JSON objects?

  • It makes some of the data types of GeoJSON more accessible, as some types like coordinates are just ordered arrays. Now you have named parameters.
  • Working with typed objects allows to see how the objects can be combined.
  • Adding properties to Feature is improved.

Installation

Either download the dist/index.js to a sensible location in your web project, or do a NPM installation:

npm install @fboes/geojson --save

Instead of a local installation you may also load the library from https://unpkg.com/. Beware: This makes https://unpkg.com/ a dependency of your project and may pose data protection issues.

<script type="module" src="https://unpkg.com/@fboes/geojson@latest/dist/index.js"></script>

Everything required for the functionality of this library is contained in dist/index.js.

Usage

Loading the library prior to use:

// 1. NodeJS - NPM installation
import GeoJson from "geojson";

// 2. Local installation and/or browser usage
import GeoJson from "dist/index.js";

Now you are set to build your GeoJSON:

const featureCollection = new GeoJson.FeatureCollection([
  new GeoJson.Feature(new GeoJson.Point(1.53946, 51.04571), {
    title: "Sailing boat",
    "marker-symbol": "harbor",
  }),
  new GeoJson.Feature(new GeoJson.Point(6.5664576, 58.109285), {
    title: "Lighthouse",
    "marker-symbol": "lighthouse",
  }),
]);

console.log(JSON.stringify(featureCollection));

which yields GeoJSON:

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": { "type": "Point", "coordinates": [1.53946, 51.04571] },
      "properties": { "title": "Sailing boat", "marker-symbol": "harbor" }
    },
    {
      "type": "Feature",
      "geometry": { "type": "Point", "coordinates": [6.5664576, 58.109285] },
      "properties": { "title": "Lighthouse", "marker-symbol": "lighthouse" }
    }
  ]
}

Further readings

  • simplestyle-spec: A simple specification for styling GeoJSON data.
  • Maki Icons: Maki is an icon set made for map designers. Maki includes icons for common points of interest like parks, museums, and places of worship.
  • Mapbox GeoJSON integration: This example adds GeoJSON data from an external file and uses it in a layer on the map.

Status

GitHub version npm version MIT license

Legal stuff

Author: Frank Boës

Copyright & license: See LICENSE.txt