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

mercator-gl

v0.8.2

Published

Tiny library for GLSL web mercator projections

Downloads

10

Readme

MercatorGL

Build Status Coverage Status GZIP size License NPM

MercatorGL is a minimal library for calculating web mercator projections on a GPU using WebGL. It provides utilities to inject GLSL code for projecting longitude/latitude coordinates into already exisiting vertex shader code and calculate the uniforms it requires. MercatorGL focuses on numerical stability by performing most calculations at 64-bit precision, and switching to an "offset mode" at higher zoom levels (using a technique borrowed from deck.gl).

Following Mapbox conventions input coordinates are transformed to a 512x512 Mercator space, with (0, 0) at the top-left and (512, 512) at the bottom-right. Z-coordinates, if provided, are interpreted as meter elevations. The application must provide a projection matrix (via updateMercatorUniforms) to map from Mercator space into clip space.

An example of usage with MapboxGL is shown below.

    let map = new mapboxgl.Map({
        container: mapboxContainer,
        style: "mapbox://styles/mapbox/streets-v9",
        center: [-73.982130, 40.762896],
        zoom: 15
    });

    // NOTE: MercatorGL works with both GLSL 1 and 3 shaders
    let vs = `
        #version 300 es
        layout(location=0) in vec2 lngLatPosition;
        void main() {
            // mercator_gl_lngLatToClip function injected by injectMercatorGLSL().
            // mercator_gl_lngLatToMercator and mercator_gl_mercatorToClip also available to do
            // projection in multiple steps.
            gl_Position = mercator_gl_lngLatToClip(position);
        }
    `;

    let fs = `
        #version 300 es
        precision highp float;
        uniform vec4 color;
        out vec4 fragColor;
        void main() {
            fragColor = color;
        }
    `;


    // Insert projection functions into vertex shader
    let vertexShaderSource = injectMercatorGLSL(vs);
    let fragmentShaderSource =  fs;
    // Create WebGL program from vertexShaderSource and fragmentShaderSource

    let uniforms = {
        // An application uniform, not used by MercatorGL
        color: new Float32Array(1.0, 0.0, 0.0, 1.0);
    };

    // Uniforms used by MercatorGL are added to the map.
    allocateMercatorUniforms(uniforms);

    map.on("render", (e) => {
        let center = map.getCenter().toArray();
        let zoom = map.getZoom();

        // Update the values of MercatorGL uniforms in the map (including projection matrix provided by Mapbox).
        // The application must use the map to update program uniforms used by MercatorGL.
        updateMercatorUniforms(uniforms, center, zoom, map.transform.projMatrix);

        // Draw to canvas
    });