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 🙏

© 2025 – Pkg Stats / Ryan Hefner

trajmap

v0.1.3

Published

GPS trajectory rendering library with map tile backgrounds

Readme

TrajMap

A high-performance GPS trajectory rendering library that transforms Polyline-encoded route data into beautiful PNG images with map tile backgrounds.

Features

  • 🗺️ Map Tile Integration: Seamlessly fetches and stitches OpenStreetMap tiles as backgrounds
  • 🛣️ Polyline Decoding: Native support for Google Polyline encoded trajectory data
  • 🎨 Customizable Styling: Configure trajectory colors, line widths, and marker points
  • 📐 Intelligent Boundary Calculation: Automatically determines optimal display regions and zoom levels
  • 🎯 Precise Projection: Leverages Web Mercator projection for accurate geographic coordinate mapping
  • 🖼️ High-Quality Output: Supports Retina displays and PNG format export
  • 📦 Modular Architecture: Individual processing modules can be used independently

How It Works

Rendering Pipeline

TrajMap employs a sophisticated multi-stage rendering pipeline to ensure high-quality map visualization:

Polyline Input → Preprocessing → Boundary Calculation → Tile Fetching → Image Stitching → Trajectory Projection → Final Rendering

1. Preprocessing Stage

  • Decodes Google Polyline format data into GPS coordinate points
  • Validates configuration parameters
  • Prepares data structures for subsequent processing

2. Boundary Calculation

  • Computes the minimum bounding box for the trajectory
  • Applies a 10% buffer zone to prevent edge clipping
  • Adjusts aspect ratio based on trackRegion specifications
  • Applies expansionRegion for area extension

3. Tile Fetching

  • Calculates optimal zoom level based on boundaries and target dimensions
  • Determines required tile coordinate ranges
  • Downloads OpenStreetMap tiles in parallel
  • Handles tile caching and error retry logic

4. Image Stitching

  • Combines multiple tiles into a complete background image
  • Manages tile boundary alignment
  • Calculates final image geographic boundaries

5. Trajectory Projection

  • Uses Web Mercator projection to convert GPS coordinates to pixel coordinates
  • Renders trajectory paths and marker points
  • Applies custom styling (colors, line widths, etc.)

6. Final Rendering

  • Generates the final PNG image
  • Supports Base64 encoded output
  • Returns trajectory point pixel coordinate information

Coordinate Systems

  • Input Coordinates: WGS84 Geographic Coordinate System (lat/lng)
  • Projection Coordinates: Web Mercator Projection (EPSG:3857)
  • Tile Coordinates: Standard tile pyramid coordinate system
  • Pixel Coordinates: Final image pixel coordinate system

Installation

npm install trajmap

System Requirements

  • Node.js >= 14.0.0
  • Canvas-compatible system environment (canvas dependency auto-installed)

Quick Start

Basic Usage

import { TrajMap } from 'trajmap';

// Simple configuration
const result = await TrajMap.render(
  'your_encoded_polyline_string',
  {
    trackRegion: {
      width: 800,
      height: 600
    }
  }
);

console.log('Rendering complete!');

Complete Configuration Example

import { TrajMap, TrajmapConfig } from 'trajmap';

const polyline = 'u{~vFvyys@fS]z@cNpKoMdQaHbU{FzV}L';

const config: TrajmapConfig = {
  // Required parameters
  trackRegion: {
    width: 1200,
    height: 800
  },
  
  // Optional parameters
  lineColor: '#FF5500',      // Trajectory color
  lineWidth: 4,              // Trajectory line width
  retina: true,              // High-resolution rendering
  
  // Region expansion configuration
  expansionRegion: {
    upPercent: 0.2,          // Expand upward by 20%
    downPercent: 0.2,        // Expand downward by 20%
    leftPercent: 0.1,        // Expand leftward by 10%
    rightPercent: 0.1        // Expand rightward by 10%
  },
  
  // Marker point configuration
  marker: {
    start: 'circle',         // Start point marker: circle
    end: 'square'            // End point marker: square
  }
};

const result = await TrajMap.render(polyline, config);

// Access result information
console.log('Base64 image data:', result.data);
console.log('Trajectory pixel coordinates:', result.points);

Links