• Stars
    star
    105
  • Rank 328,196 (Top 7 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 11 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A plugin to add a customizable magnifying glass tool to a Leaflet map.

Leaflet Magnifying Glass

This plugin allows you to add a "magnifying glass" effect to a Leaflet map, able to display a portion of the map in a different zoom (and actually display different content).

See it in action:

Support

The development version of the plugin (on the master branch) is targeted at the 1.* version of Leaflet.

For a version of the plugin compatible with the 0.7.* Leaflet releases, use the leaflet-0.7.2 branch.

Not tested on mobile browsers.

Screenshot

screenshot

Default look of the magnifying glass, using the same tile background as the main map and a zoom level offset set to 3.

Usage

  • Add the style sheet and script file to your page;
  • Instantiate a magnifying glass and add it to the map like any other layer:
var magnifyingGlass = L.magnifyingGlass({
    layers: [ ... ]
});

map.addLayer(magnifyingGlass);

Inner layers

For it to display something, you need to pass layers to the constructor. You can simply give a L.TileLayer, but any other type of layers too.

Leaflet layer objets can't be shared between maps. So, don't re-use layer objects already in use by the main map. For example, if you want to use the same tile background on your main map and in the magnifying glass, you need to instantiate two different L.TileLayer objects:

// Share the same tile url...
var tileUrl = 'http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
// but use two independant TileLayer objects
var mapTiles = L.tileLayer(tileUrl),
    magnifiedTiles = L.tileLayer(tileUrl);

var map = L.map('map', {
    center: [0, 0],
    zoom: 5,
    layers: [ mapTiles ]
});

var magnifyingGlass = L.magnifyingGlass({
    layers: [ magnifiedTiles ]
}).addTo(map);

Options

Option Type Default Description
radius Integer 100 The radius of the magnifying glass, in pixels.
zoomOffset Integer 3 The zoom level offset between the main map zoom and the magnifying glass.
fixedZoom Integer -1 If different than -1, defines a fixed zoom level to always use in the magnifying glass, ignoring the main map zoom and the zoomOffet value.
fixedPosition Boolean false If true, the magnifying glass will stay at the same position on the map, not following the mouse cursor.
latLng LatLng [0, 0] The initial position of the magnifying glass, both on the main map and as the center of the magnified view. If fixedPosition is true, it will always keep this position.
layers ILayer[] [] Set of layers to display in the magnified view. These layers shouldn't be already added to a map instance (see note above).

Methods

Method Description
getMap() Returns the L.Map instance used by the magnifying glass. You can use it for example to add/remove magnified layers on the fly.

License

MIT.

More Repositories

1

Leaflet.PolylineDecorator

A plug-in for the JS map library Leaflet, allowing to define patterns (like dashes, arrows, icons, etc.) on Polylines.
JavaScript
493
star
2

Leaflet.RotatedMarker

Leaflet plugin to enable the rotation of map marker icons
JavaScript
257
star
3

Leaflet.PolylineOffset

Apply a relative pixel offset to polylines without changing their coordinates.
JavaScript
151
star
4

jkstra

JavaScript graph routing library
JavaScript
49
star
5

thread-reader-reader

Parse Twitter thread already simplified by third-party Thread Reader app, and produce dead simple HTML
JavaScript
20
star
6

FirefoxOS.GeoTracker

GPS track recording web app for Firefox OS… and mobile browsers in general.
JavaScript
20
star
7

bird-tracking

Interactive data viz of migrating birds
JavaScript
13
star
8

react-staticMapZoom

A React component which mimics the auto zoom mini-map found on geo-tagged photos Flickr pages.
JavaScript
10
star
9

clean-cnrtl

Clean and responsive proxy to CNRTL French dictionary website
CSS
10
star
10

simple-static-map-server

Raster map service based on MapLibre GL JS
JavaScript
9
star
11

metro-pili

JavaScript
5
star
12

irish-tune-map

A map of irish folk tunes
JavaScript
5
star
13

GeoTracker

JavaScript
3
star
14

updatable-priority-queue

A priority queue implementation based on a binary heap, with an efficient update-key operation
JavaScript
3
star
15

mapbox-gl-style-optimizer

Suggests optimizations to Mapbox-GL style files to improve rendering perfs.
JavaScript
3
star
16

place-place

Place-Place, a place positioning game to test spatial knowledge of your city
TypeScript
3
star
17

pw2014

Atelier Paris Web 2014
JavaScript
2
star
18

alt-route-labeller

A library to compute the best position to put labels on multiple routes between two points
JavaScript
2
star
19

bbecquet

1
star