Giter Club home page Giter Club logo

leaflet-hash's Introduction

Leaflet-hash

Leaflet-hash lets you to add dynamic URL hashes to web pages with Leaflet maps. You can easily link users to specific map views.

Leaflet-hash

Demo

You can view a demo of leaflet-hash at mlevans.github.io/leaflet-hash/map.html.

Getting started

  1. Prepare a basic leaflet map. You can find instructions on Leaflet's quick-start guide.

  2. Include leaflet-hash.js.

  3. Once you have initialized the map (an instance of L.Map), add the following code:

        // Assuming your map instance is in a variable called map
        var hash = new L.Hash(map);

Author

@mlevans

Contributors

@calvinmetcalf

@jfirebaugh

@rsudekum

@tmcw

@yohanboniface

License

MIT License. See LICENSE for details.

leaflet-hash's People

Contributors

bsudekum avatar jfirebaugh avatar mlevans avatar tmcw avatar yohanboniface avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leaflet-hash's Issues

location.replace(hash) vs location.hash = hash

Using location.hash = hash; instead of location.replace(hash); inside onMapMove allowed me to keep my use case working: a map in a page opened by another page using an anchor.

I don't know if this breaks anything, but it seems more convenient.

Not working in FTP

Hi,

Leaflet-hash works fine on localhost, but it doesn't when upload to the web.

I have only blank window (even without the map), whereas the Console says nothing.

Could you tell me what may cause the problem?~

Thanks & Regards

Multiple maps support

Does the plugin work with multiple maps in the same page?
For example, is there any possibility if I can add an extra parameter in the URL which will be a reference to the required map in the page?

`map.invalidateSize()` breaks leaflet-hash initial load + workaround

I am using map.invalidateSize() to tell my map container that a panel in my layout was removed and to use the full size again.

However, calling invalidateSize during the first render of the page breaks leaflet-hash in the sense, that the provided hash location (provided by a deep link / external link with hash), does not position the map on the hash's position but the default position instead.

To me, it looks like the resize code from invalidateSize prevents leaflet-hash from receiving the hash location.
(Somewhere here https://github.com/Leaflet/Leaflet/blob/0f904a515879fcd08f69b7f51799ee7f18f23fd8/src/map/Map.js#L596-L599)

Workaround

As a workaround, I now set the default map position to the hash's position before initializing the map:

SupaplexOSM/strassenraumkarte-neukoelln@1324d35#diff-0eb547304658805aad788d320f10bf1f292797b5e6d745a3bf617584da017051R11-R19

	const optionsFromHash = L.Hash.parseHash(window.location.hash)

	const options = {
		center: optionsFromHash.center || [52.48150, 13.43571],
		zoom: optionsFromHash.zoom || 18,
		minZoom: 15,
		zoomControl: true,
		maxBounds: [[52.4557, 13.3985], [52.5005, 13.4863]]
	}

Live example: https://supaplexosm.github.io/strassenraumkarte-neukoelln/?map=parkingmap#18/52.47773/13.43523

use leaflet-hash and jquery BBQ-plugin

I would like to use the leaflet-hash in addition to the jquery BBQ-plugin, for example I would like to maintain the lat and lng of the leaflet view port as well as hash tags from Jquery-BBQ plugin, and idea how I can do this. Currently the leaflet-hash copies over the Jquery-BBQ plugin hash tag in the URL and Vice versa.

iframe url hash support

url hash do not work if map is in iframe, if you can add built in support in leaflet hash so that url hash can communicate in between iframe and parent window natively. update and create map with url hash.

Submit to npm

Can you push this module to npm?

# in module directory
npm publish

why does update call onMapMove?

If there's no parseable hash (e.g., if there's no hash at all), update calls onMapMove. This seems counterintuitive: I'd expect update to work in strictly the opposite direction from onMapMove. That is, onMapMove is strictly for map -> hash updates, so I'd expect update to be strictly for hash -> map updates.

Setting the map div to be 100% gives a height of 0px

If I set the map height in CSS to be 100% or any percentage for that matter, the height is computed to be 0 after adding this plugin for the permalink. I don't expect this to happen, nor do I expect to have to set the height either via js or a fixed pixel height.

Endless redirects

I referenced leaflet-hash.js and added var hash = new L.Hash(map); after initializing the map. Upon the first loading of the page, the page loads the UI, loads the map, and then goes blank as the browser gets in an endless loop.

I think this may have something to do with jQueryMobile (I get a jQueryMobile-provided "error loading" on-screen message). Let me know if you need me to go into more details or provide a screencast of the loop.

More Information

Any way we could get more documentation on how this plugin works?

throttle location.replace()

Currently the hash is updated with the onMapMove event, and in Mac Chrome (40.0.2214.69 beta (64-bit) at least), this causes a performance hit to map drawing as the location bar is spammed. I'd like to suggest a throttle on location.replace(), similar to the update() throttle – but everything including the update() is triggered by the onhashchange event, expecting that the hash is being updated constantly during moves. So it seems this would involve reorganizing the whole file, effectively inverting the relationship between onhashchange and onMapMove.

Is there a good reason not to do this? I have a working example that seems to function just as I want it to, but I don't know whether it would break some use case besides my own.

onMapMove replace location entirely

function completely replaces the location, but should replace the "hash" field

onMapMove: function() {
			// bail if we're moving the map (updating from a hash),
			// or if the map is not yet loaded

			if (this.movingMap || !this.map._loaded) {
				return false;
			}

			var hash = this.formatHash(this.map);
			if (this.lastHash != hash) {
				location.replace(hash); - **right here**
				this.lastHash = hash;
			}
		}

Can we change it to location.hash = hash;?

Maintenance plans

As I'm sure many would agree, this is a very useful plugin used by a lot of people, however it has not been updated in over 3 years, no pull requests have been responded to, and there are a dozen open issues with no feedback.

If you would like help maintaining this repo I would love to help out! Thank for making such a useful plugin.

Including current base layer in hash

When map URL with hash is shared and clicked it opens default base layer. It there are more base layers, user expectation is that link should open selected base layer not default one.

I thought to try to do this by myself but my knowledge of Leaflet is to weak so I failed.

Custom L.Transformation broke hash

If L.Transformation contain any fractional number hash won't work properly. In my case after refreshing page moved to the right with large padding.

`L.CRS.Simp = L.extend({}, L.CRS.Simple, {
projection: L.Projection.LonLat,
transformation: new L.Transformation(2.06E-5, 0, -2.06E-5, 0),
// transformation: new L.Transformation(2.06, 0, -2.06, 0), // same bug, but lesser padding
scale: function (zoom) {
return Math.pow(2, zoom);
}
});
var map = L.map('map', {
crs: L.CRS.Simp,
maxZoom: 3,
minZoom: 1,
}).setView([-790, 353.0], 3);

var hash = new L.Hash(map);`

I fail to get the Hash to work... in some maps

Hello and I hope you can help me in this probably simple troubles I have.
I have used the leaflet-hash in a couple of maps and got it to work, i.e. http://meandernatur.se/skyddsvardatrad

When I try to get it to work in another map (AmazonEC2) with identical functionality as the map above except for using geojson instead af ArcMap server-layers, I fail.
http://kajakplatser.se/karta

The code for kajakplatser
http://kajakplatser.se/karta/index.html
http://kajakplatser.se/karta/kajakkarta.js
http://kajakplatser.se/karta/kajakplatser.js

Any ideas?

I have tried different variants of
var hash = new L.Hash();
hash.init(map);
as well as
.addHash();

Tried to put in on Jsfiddle but probably didnät get all the repositories to work as well as the CORS... http://jsfiddle.net/7mMh7/7/

leaflet-hash in npm

Right now leaflet-hash on npm is v0.1.1 which doesn't include 197525d and was published 7 months ago - could you push a new version?

L.hash is not a constructor, init map ?

I've got some difficulties to activate hash for leaflet.

my code define the map as usual:

            var map = L.map('map', {
        center: new L.LatLng(12.00641296, 79.81030941),zoom: 15,
        layers: [blackwhite, avzonesLayer, circlesLayer ]
    }); //.addHash() ?

    var hash = new L.hash(map);

i've got this error:

L.hash is not a constructor

I'm a bit lost, i use leaflet master 0.5.1...please help here :)

History not working

So I was unable to get this working with my browser history, i.e. couldn't hit back button to go to the previous zoom, so I did the logical thing and rewrote my fork to use pushState for modern browsers and onhashchange for middle-aged browsers and the watching method you had for ancient browsers, in CoffeeScript.

I'm not sure if this is the direction you want to go but if it is I can always port some of this back to javascript.

working demo

L.hash is not a constructor

I see a previous issue raised about this but no solution was offered. I get the same problem (TypeError: L.hash is not a constructor) with your current version using both hash and Hash.

I have var hash = new L.Hash(map); after map is declared. Something works because the /#zoom/lat/lon is now in URL, but it is not responsive when I move the map, and doesn't override the coded centre if I offer the URL with different params.

Any idea what I'm getting wrong?

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.