Giter Site home page Giter Site logo

cainyann / leaflet-side-by-side Goto Github PK

View Code? Open in Web Editor NEW

This project forked from digidem/leaflet-side-by-side

0.0 0.0 0.0 4.14 MB

A Leaflet control to add a split screen to compare two map overlays

Home Page: http://lab.digital-democracy.org/leaflet-side-by-side/

License: MIT License

JavaScript 81.36% CSS 11.95% HTML 6.70%

leaflet-side-by-side's Introduction

leaflet-side-by-side

A Leaflet control to add a split screen to compare two map overlays.

screencast example

L.control.sideBySide(leftLayer[s], rightLayer[s])

Creates a new Leaflet Control for comparing two layers or collections of layers. It does not add the layers to the map - you need to do that manually. Extends L.Control but setPosition() and getPosition are noop because the position is always the same - it does not make sense for this control to be in the corner like other Leaflet controls.

Parameters

parameter type description
leftLayers L.Layer|array A Leaflet Layer or array of layers to show on the left side of the map. Any layer added to the map that is in this array will be shown on the left
rightLayers L.Layer|array A Leaflet Layer or array of layers to show on the right side of the map. Any layer added to the map that is in this array will be shown on the right. These should not be the same as any layers in leftLayers
options Object Options
options.padding Number Padding between slider min/max and the edge of the screen in pixels. Defaults to 44 - the width of the slider thumb

Events

Subscribe to events using these methods

Event Data Description
leftlayeradd LayerEvent Fired when a layer is added to the left-hand-side pane
leftlayerremove LayerEvent Fired when a layer is removed from the left-hand-side pane
rightlayeradd LayerEvent Fired when a layer is added to the right-hand-side pane
rightlayerremove LayerEvent You guessed it... fired when a layer is removed from the right-hand-side pane
dividermove {x: Number} Fired when the divider is moved. Returns an event object with the property x = the pixels of the divider from the left side of the map container.

Methods

Method Returns Description
setLeftLayers this Set the layer(s) for the left side
setRightLayers this Set the layer(s) for the right side

Usage

Add the script to the top of your page (css is included in the javascript):

<script src="leaflet-side-by-side.js"></script>

Or if you are using browserify:

var sideBySide = require('leaflet-side-by-side')

Then create a map, add two layers to it, and create the SideBySide control and add it to the map:

var map = L.map('map').setView([51.505, -0.09], 13);

var myLayer1 = L.tileLayer(...).addTo(map);

var myLayer2 = L.tileLayer(...).addTo(map)

L.control.sideBySide(myLayer1, myLayer2).addTo(map);

Example

Live Example see source

Limitations

  • The divider is not movable with IE.
  • Probably won't work in IE8, but what does?

License

MIT

leaflet-side-by-side's People

Contributors

bertspaan avatar danielbarela avatar ghybs avatar gmaclennan avatar m-mohr avatar ukonhattu 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.