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

leaflet-schematic

v1.1.0

Published

Leaflet SVG viewer for non-cartographic high-detailed schematics

Downloads

15

Readme

Leaflet schematic npm version CircleCI

This is a set of tools to display and work with non-cartographic large high-detailed SVG schematics or blueprints. SVG is a perfect format for the task - it's vector, relatively compact, has all the means to work with templates and symbols, so it can really be a great representation and metadata container at the same time.

Usage

var xhr = require('xhr');
var SVGOverlay = require('leaflet-schematic');

var map = L.map('map', { crs: L.CRS.Simple });
L.svgOverlay('/path/to/svg.svg', {
  load: function(url, callback) {
    // your/your library xhr implementation
    xhr({
      uri: url,
      headers: {
        "Content-Type": "image/svg+xml"
      }
    }, function (err, resp, svg) {
      callback(err, svg);
    });
  }
}).addTo(map);

Problem

The problem is that if you want to work with the SVG as with image overlay, several technical limitations and performance issues strike in:

  • you cannot work on larger scales with the whole canvas because of the dimension restrictions of browsers
  • you have to scale the drawing initially to fit the viewport on the certain zoom level
  • IE (as always) - I wouldn't even call that "SVG support"
    • <use> elements have a special freaky non-compliant API which is also broken
    • css-transforms - unsupported
    • translate() + scale() transform on <g> -doesn't work, use matrix
    • horrible performance - the more SVG nodes you have the slower it is

Approach

  • Use leaflet viewportized layer container to render part of the SVG with padding
  • scale SVG to fit the viewport and zoom levels
  • pack SVG contents into moving <g>
  • for IE - hardcore hacking:
    • render SVG > base64 > <canvas>
    • replace SVG with this canvas on drag and zoom
    • also keep a hidden PNG rendered to overcome IE's performance drop on image scaling, somehow it works like a directive to switch the faulty smoothing off

Know issues

  • SVGs without correctly provided viewBox work really badly and I cannot yet figure out why. I'm trying to calculate viewbox from the contents, but it still looks broken in rendered canvas

License

MIT