Giter Club home page Giter Club logo

leaflet-schematic's Introduction

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

leaflet-schematic's People

Contributors

w8r avatar rumax avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.