Norkart / Leaflet-MiniMap

A minimap control plugin for Leaflet
BSD 2-Clause "Simplified" License
395 stars 125 forks source link

Add centerFixed option when initializing MiniMap (to disable panning and/or zooming) #95

Closed mnquintana closed 9 years ago

mnquintana commented 9 years ago

Closes #94 Closes #77

This PR adds a new option, centerFixed, that fixes the MiniMap on a point, but still allows zooming. When centerFixed is enabled, the MiniMap won't change when the main map is panned - only if it's zoomed, and when it's zoomed, the MiniMap will always zoom centered around the point passed on initialization.

var miniMap = new L.Control.MiniMap(osm2, {
  centerFixed: [40.7842, -73.9919]
}).addTo(map);

If you want to disable panning and zooming (ala #77), just initialize a MiniMap with both centerFixed and zoomLevelFixed, like this:

var miniMap = new L.Control.MiniMap(osm2, {
  centerFixed: [40.7842, -73.9919],
  zoomLevelFixed: 15
}).addTo(map);

This PR also adds examples for creating both a MiniMap with a fixed center and a MiniMap with a fixed view (ie. no panning or zooming).

:memo: NOTE: The indentation in this file was already a bit of a mess (tabs and spaces mixed together) - I'd be happy to fix this and change it to use all tabs in another PR if that's everyone's preference, but I didn't want to do it in this one to keep the diff more readable. My editor also removed some trailing whitespace as I worked - if that's an issue, I can revert those changes too. Otherwise, I plan on submitting another PR to fix the formatting and stuff, if that would be :cool:

robpvn commented 9 years ago

Wow, your editor sure didn't pull any punches! But I like the way you solved this, it's an elegant solution. Thanks!

As you say, the indentation has become very messy because I haven't been consistent about enforcing style. So if you want to do the work of normalising everything into tabs and fixing errant indentation I would be very grateful. In other words, very :cool:.

mnquintana commented 9 years ago

Thanks! Do you prefer tabs or spaces? I'll try to get a style PR out soon.

robpvn commented 9 years ago

Tabs are my kind of thing, at least that's how this repo started out!