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

maplibre-gl-vector-text-protocol

v0.0.5

Published

Allows various text based vector formats to be used with maplibre gl js

Downloads

286

Readme

maplibre-gl-vector-text-protocol

Supports geospatial text based vector data using MapLibre GL JS in v1.15.0 or later.

It makes use of the addProtocol functionality that was added in version 1.15.0.

It can be used with Mapbox GL JS 1.x.x using the mapbox-gl-custom-protocol library. I haven't tested it with Mapbox GL JS 2+.

Web workers are used to convert CSV, TSV, Topojson, and OSM formats. KML, GPX, and TCX formats are based on XML and use the DOMParser, which isn't available to web workers, so they are converted to GeoJSON in the main thread.

Supported Formats 🗎

  • Topojson - A more compact JSON based format than GeoJSON that takes advantage of shared topologies.
  • OSM - Open Street Map json/xml.
  • KML - Keyhole Markup Language, popularized by Google Earth.
  • GPX - GPS Exchange Format - A common XML-based format used by may GPS devices.
  • TCX - Training Center XML - An XML-based format used by various Garmin devices and applications (e.g. Garmin Connect).
  • CSV - Comma-Separated Values, the old reliable of data formats. No options are exposed, Latitude fields must start with "lat" and Longitude fields must start with "lon" or "lng". Will also work with bar (|) and tab (\t) separated values.
  • TSV - Tab-Separated Value - Same as CSV, but it forces the delimiter to be a tab character (\t).

Objective ✨

The addProtocol feature makes it extremely easy to extend the existing functionality of MapLibre sources without creating a new source type using the addSourceType feature. This makes it very easy to support all kinds of new things in MapLibre.

Inspiration 💡

I have worked on many projects where users want to add their own data to a map, but their data is rarely in the right format. This library makes it as easy as adding a csv:// before the file path to bring a csv file in.

There are a lot of Geospatial File Formats out there, this library is intended to serve the most common formats (CSV, KML, GPX, Topojson, OSM) without creating a huge library. There are other formats I would like to support, but they will be available in different libraries.

External Libraries 📚

This project would not be possible if it weren't for the core libraries that drive it:

  • @tmcw/togeojson - Supported by placemark.io - KML, GPX, TCX support
  • csv2geojson - Supported by Mapbox - CSV, TSV support
  • topojson-client - From Mike Bostock - Topojson support
  • osm2geojson-lite - From tibetty - osm2geojson-lite support

I'd also like to thank the Mapbox🚀 and MapLibre teams for creating such a great project that is easily extendable.

Usage 🛠️

<script src="https://loc8.us/maplibre-gl-vector-text-protocol/dist/maplibre-gl-vector-text-protocol.js"></script>

// Add all types
VectorTextProtocol.addProtocols(maplibregl);

// Individual protocols can be added as well
maplibregl.addProtocol('csv', VectorTextProtocol.VectorTextProtocol);
maplibregl.addProtocol('kml', VectorTextProtocol.VectorTextProtocol);

Examples ⚙️

Codepen