Giter VIP home page Giter VIP logo

leaflet.zoomfs's Introduction

Leaflet.Control.ZoomFS

This is a simple extension of Leaflet.Control.Zoom that adds a fullscreen button above the zoom in and zoom out controls.

You can make a Leaflet map fullscreen programatically by changing the CSS of the map container. This extension simply integrates that functionality into the Leaflet interface.

Usage

Be sure to include the leaflet.zoomfs.js script somewhere after Leaflet is loaded.

<script src="http://cdn.leafletjs.com/leaflet-0.4.4/leaflet.js"></script>
<script src="leaflet.zoomfs.js"></script>

Do all your normal Leaflet initialization stuff, except make sure that you initialize the map without the default zoom controls:

<!-- map container -->
<div id="map"></div>

// init map
var map = new L.Map('map', { zoomControl:false });

Then, instantiate the ZoomFS control and add it to the map:

var zoomFS = new L.Control.ZoomFS(); 
map.addControl(zoomFS);

Events

There are 2 events you can bind to: enterFullscreen and exitFullscreen. Note that these events are triggered on the Map object; not ZoomFS.

map.on('enterFullscreen', function(){
  if(window.console) window.console.log('enterFullscreen');
});

map.on('exitFullscreen', function(){
  if(window.console) window.console.log('exitFullscreen');
});

Style

This extension applies the following inline styles to make the map fullscreen. We also apply a class of leaflet-fullscreen to the map container.

<div id="map" class="leaflet-container leaflet-fullscreen" style="position: fixed; left: 0px; top: 0px; width: 100%; height: 100%;">

No style is applied to the fullscreen button itself. Basic style is handled internally by Leaflet.Control.Zoom, but you'll need to add your own button style:

.leaflet-control-fullscreen {
  background-image: url(your/amazing/icon.png);
  margin-bottom: 5px;
}

Caveat

All inline style on your map container will be removed when exitFullscreen is triggered. position:relative is re-applied automatically if you do not have a position declared in your base styles (as this is required by Leaflet). A height is required by Leaflet core, and it should be declared in your base CSS (not inline) like so:

#map {
  position: relative;
  height: 400px;
}

Notes

  • This extension was built and tested for Leaflet version 0.4.4. If you need this to work with Leaflet 0.3.1 there's an old version in tag v0.1
  • If you want the fullscreen button below the zoom in and zoom out buttons simply switch the order in which the controls are added in leaflet.zoomfs.js.
  • Ideally some of this code should reside in Leaflet.Map... I've done some initial work on that here: https://github.com/elidupuis/Leaflet.

leaflet.zoomfs's People

Contributors

elidupuis avatar

Watchers

 avatar  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.