Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrated mode for simpler integration #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions examples/example.integrated.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">

<title>Leaflet MagnifyingGlass example</title>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet/v1.0.0-rc.1/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet/v1.0.0-rc.1/leaflet.js"></script>

<link rel="stylesheet" href="../leaflet.magnifyingglass.css" />
<style>
html, body {
height: 100%;
}
#map {
width:100%;
height:600px;
}
</style>

<script src="../leaflet.magnifyingglass.js"></script>
<script src="example.integrated.js"></script>
</head>

<body>
<div id="map"></div>
<div>
<p>Default look and behavior of the magnifying glass, following cursor, and using a zoom level offset set to 3. The magnifying glass uses the same tiles as the main map.</p>
<p>Use the button in the zoom controls to toggle the glass and click it to make it disappear.</p>
<p><a href="https://github.com/bbecquet/Leaflet.MagnifyingGlass">Check the code!</a></p>
</div>
</body>
</html>
26 changes: 26 additions & 0 deletions examples/example.integrated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function init() {
var tileUrl = 'http://b.tile.openstreetmap.org/{z}/{x}/{y}.png';
var tileOptions = {
attribution: '&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors',
subdomains: '1234'
};

var map = new L.Map('map', {
center: [50.0, 10.0],
zoom: 5,
layers: [
L.tileLayer(tileUrl, tileOptions)
]
});

var magnifyingGlass = L.magnifyingGlass({
zoomOffset: 3,
layers: [
L.tileLayer(tileUrl, tileOptions)
],
map: map,
title: 'Magnifying glass'
});
}

window.onload = init;
5 changes: 5 additions & 0 deletions leaflet.magnifyingglass.css
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ applied to the map container */
.leaflet-magnifying-glass-webkit {
border-radius: 50%;
-webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC);
}

.glass-icon {
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAQAAABKfvVzAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QAAKqNIzIAAAAJcEhZcwAADdcAAA3XAUIom3gAAAAHdElNRQfiBxMODTtp744rAAABLklEQVQ4y73SMUoDURSF4S8hYKe1CMFGC+tEGJLOzg2oRTbgEiS9lSsQphcbbezsIhITN2CjRdIGXIBci4xxJjNRK88rHtx3/3vgvFvzrcSBthbGRu49+kEbUrF0UhvlxhrouLKFJwNjtHTtY+rIQ9X0iTDTQ81uVu2ZCZMql1SYaVpz7l0s6k0zIV1uT4TQs+bZh0vHubeeEJIi0BeGOPfhsOQ+FPr5Ql0bAzWnUnclYIB2EZjnvmPdfUXc88xyamT3Sxbwr6qXZxTUylxywAjdlUAXo+pYq1QZ6/fHLWvFxxVXIz/9azU2F9Es1DERwtCFEycuDIUw0bHtzXUZWbXe296EqEJI9N2amrrVl2Aza1+JLKvhOuf4P8jZ70ARef0LkEdu/gbQcObVjb1PNLaOIqanI2gAAAAldEVYdGRhdGU6Y3JlYXRlADIwMTgtMDctMTlUMTQ6MTM6NTkrMDI6MDDTp1sGAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE4LTA3LTE5VDE0OjEzOjU5KzAyOjAwovrjugAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAAASUVORK5CYII=);
background-size:50%;
}
41 changes: 40 additions & 1 deletion leaflet.magnifyingglass.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,55 @@ L.MagnifyingGlass = L.Layer.extend({
layers: [ ],
fixedPosition: false,
latLng: [0, 0],
fixedZoom: -1
fixedZoom: -1,
title: 'Show glass'
},

initialize: function(options) {
L.Util.setOptions(this, options);
this._fixedZoom = (this.options.fixedZoom != -1);
this._mainMap = null;
this._glassMap = null;

if (options.map)
this.linkToMap(options.map);
},

linkToMap: function (map) {

var container;
if (map.zoomControl) {
container = map.zoomControl._container;
} else {
container = L.DomUtil.create('div', 'leaflet-bar');
}

this._createButton(this.options.title, container, function () {
if (map.hasLayer(this))
map.removeLayer(this);
else
map.addLayer(this);
}, this);

this.on('click', function () {
map.removeLayer(this);
});

},

_createButton: function (title, container, handler, context) {
this.link = L.DomUtil.create('a', 'leaflet-touch glass-icon', container);
this.link.href = '#';
this.link.title = title;

L.DomEvent
.addListener(this.link, 'click', L.DomEvent.stopPropagation)
.addListener(this.link, 'click', L.DomEvent.preventDefault)
.addListener(this.link, 'click', handler, context);

return this.link;
},

getMap: function(){
return this._glassMap;
},
Expand Down