missinglink / leaflet-spatial-prefix-tree

Leaflet plugin for visualizing spatial prefix trees, quadtree and geohash
http://missinglink.github.io/leaflet-spatial-prefix-tree/
53 stars 18 forks source link

Openning the map with a Geohash defining the location #6

Open ppKrauss opened 5 years ago

ppKrauss commented 5 years ago

I included the javascript below in the index.html and is working fine (!). Try to navigate with index.html#6gycfqf0 or index.html#geohash:6gycfqf0 with this javascript:

<script>
var hash = window.location.hash
hash = hash.replace('#','');
if (hash) {
    // check prefixes "geohash:" (default) or "quadtree:" or "slippy:"
    var prefix = ['geohash','quadtree','slippy'];
    var selected = 'geohash';
    var pos = hash.indexOf(':');
    if (pos != -1) {
        selected = hash.substr(0, pos)
        if (prefix.indexOf(selected) == -1) 
                     alert("HASH ERROR: no known "+selected);
        hash = hash.substr(pos+1)
        }
    alert("OK, we can see the map at \n"+hash); 
}
</script>

To continue: how to change by javascript the map location?

PS: if we can translate a Geohash code and the position of the map by Javascript, we can display map by the URL-supplied Geohash.


See also #4

missinglink commented 5 years ago

I've used a leaflet plugin in the past called https://github.com/mlevans/leaflet-hash

That plugin also handles changing the anchor hash when the map moves and moving the map when the anchor changes.

It might be worth looking at that for inspiration.

How much functionality do you plan to implement?

ppKrauss commented 5 years ago

Hi, I am adapting to view the Geohash of a point or region with the grid... It is at http://www.openstreetmap.com.br/CLP/site2/#6gycfqf0
the basic is working fine, but your clue of mlevans/leaflet-hash is better...

About the magnifying icon, that is not working, perhaps we can take off the autocomplete, etc. and use if for "search by geohash"... That will be perfect.

missinglink commented 5 years ago

Agh right, the search is pointing to the now-defunct Mapzen Search service, I'll update it to use geocode.earth