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 🙏

© 2026 – Pkg Stats / Ryan Hefner

maplibre-gl-kmz-layer

v0.1.2

Published

KMZ/KML layer support for MapLibre GL JS

Downloads

154

Readme

maplibre-gl-kmz-layer

A KMZ/KML layer plugin for MapLibre GL JS

🌐 Live Demo | 📖 日本語版

Features

  • Load KMZ files (compressed KML) directly
  • Support for KML files
  • Support for Point, LineString, Polygon, and MultiGeometry
  • Automatic application of KML styles (LineStyle, PolyStyle, IconStyle)
  • NetworkLink support with automatic refresh
  • Large dataset optimization (performance optimization, clustering, LOD)
  • Full icon support (automatic icon extraction from KMZ)
  • TypeScript support
  • Lightweight and fast

Installation

npm install maplibre-gl-kmz-layer

Or install directly from GitHub:

npm install github:northprint/maplibre-gl-kmz-layer

Usage

import { KMZLayer } from 'maplibre-gl-kmz-layer';

// Initialize MapLibre GL map
const map = new maplibregl.Map({
  container: 'map',
  style: 'your-style-url',
  center: [139.7670, 35.6814],
  zoom: 10
});

// Create KMZ layer
const kmzLayer = new KMZLayer({
  id: 'my-kmz-layer',
  url: 'path/to/your/file.kmz',
  onLoad: (data) => {
    console.log('KMZ loaded:', data);
  },
  onError: (error) => {
    console.error('Error loading KMZ:', error);
  }
});

// Add to map
await kmzLayer.addTo(map);

Loading from Local File

const fileInput = document.getElementById('file-input');
fileInput.addEventListener('change', async (e) => {
  const file = e.target.files[0];
  const reader = new FileReader();
  
  reader.onload = async (event) => {
    const kmzLayer = new KMZLayer({
      id: 'local-kmz',
      data: event.target.result,
      onLoad: (data) => {
        console.log('Local KMZ loaded:', data);
      }
    });
    
    await kmzLayer.addTo(map);
  };
  
  reader.readAsArrayBuffer(file);
});

Optimizing Large Datasets

const kmzLayer = new KMZLayer({
  id: 'large-dataset',
  url: 'path/to/large-file.kmz',
  optimization: {
    enabled: true,
    maxFeatures: 10000,
    clusterPoints: true,
    clusterRadius: 50,
    simplifyTolerance: 0.0001,
    enableLOD: true
  }
});

Using NetworkLinks

const kmzLayer = new KMZLayer({
  id: 'dynamic-kmz',
  url: 'path/to/network-linked.kmz',
  followNetworkLinks: true,
  networkLinkOptions: {
    maxDepth: 3,
    refreshInterval: 60000 // Refresh every minute
  }
});

API

Constructor Options

interface KMZLayerOptions {
  id: string;                    // Unique layer ID
  url?: string;                  // KMZ file URL
  data?: ArrayBuffer | Blob;     // KMZ file binary data
  visible?: boolean;             // Initial visibility (default: true)
  minzoom?: number;              // Minimum zoom level
  maxzoom?: number;              // Maximum zoom level
  onLoad?: (data: KMZParseResult) => void;   // Load complete callback
  onError?: (error: Error) => void;          // Error callback
  
  // NetworkLink options
  followNetworkLinks?: boolean;  // Automatically load NetworkLinks
  networkLinkOptions?: {
    maxDepth?: number;           // Maximum NetworkLink depth
    refreshInterval?: number;    // Refresh interval (milliseconds)
  };
  
  // Performance optimization options
  optimization?: {
    enabled?: boolean;           // Enable optimization
    maxFeatures?: number;        // Maximum number of features
    simplifyTolerance?: number;  // Simplification tolerance
    clusterPoints?: boolean;     // Cluster points
    clusterRadius?: number;      // Clustering radius
    enableLOD?: boolean;         // Enable Level of Detail
  };
}

Methods

addTo(map: MaplibreMap): Promise<void>

Add the layer to a map.

show(): void

Show the layer.

hide(): void

Hide the layer.

toggle(): void

Toggle layer visibility.

remove(): void

Remove the layer from the map.

getData(): KMZParseResult | null

Get the parsed KMZ data.

zoomToFeature(featureId: number): void

Zoom to a specific feature.

Parse Result Structure

interface KMZParseResult {
  features: FeatureCollection;  // GeoJSON FeatureCollection
  styles: Record<string, KMLStyle>;  // Style information
  metadata?: {                  // Metadata
    name?: string;
    description?: string;
    author?: string;
  };
}

Supported KML Elements

  • Geometry: Point, LineString, Polygon, MultiGeometry
  • Styles: LineStyle, PolyStyle, IconStyle (with automatic icon extraction)
  • Data: name, description, ExtendedData
  • Dynamic Elements: NetworkLink (with auto-refresh)

Browser Support

  • Chrome (latest)
  • Firefox (latest)
  • Safari (latest)
  • Edge (latest)

Development

# Install dependencies
npm install

# Build
npm run build

# Development mode
npm run dev

# Run tests
npm run test

License

MIT License

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.