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

Add an example showing how to create a permalink #3560

Merged
merged 1 commit into from
Apr 22, 2015

Conversation

tsauerwein
Copy link
Member

A small example in which the URL is updated with the current zoom-level and center every time the map is moved. When reloading center and zoom-level are restored from the URL.

@bartvde
Copy link
Member

bartvde commented Apr 15, 2015

LGTM thanks for adding this, please merge if Travis gives the okay

@bartvde
Copy link
Member

bartvde commented Apr 15, 2015

the only thing I wondered is if we should keep the anchor structure the same as in OpenLayers 2 to make it easier for people that are coming from OpenLayers 2?

#zoom=2&lat=12.01246&lon=23.84033&layers=B

@ahocevar
Copy link
Member

Nice! View rotation could also be added to the permalink.

@ahocevar
Copy link
Member

And then of course, the History API could be used to navigate through the viewed extents... but maybe that's for a separate improvement pull request to this new example.

@tschaub
Copy link
Member

tschaub commented Apr 15, 2015

And then of course, the History API could be used to navigate through the viewed extents... but maybe that's for a separate improvement pull request to this new example.

We could also demonstrate how to work with existing libraries :).

var hashed = require('hashed');

// custom serializers/deserializers can also be supplied
// but we'll start with just the defaults
var defaults = {x: 0, y: 0, z: 1};

function onChange(hash) {
  var view = map.getView();
  view.setCenter([hash.x, hash.y]);
  view.setZoom(hash.z);
}

var update = hashed.register(defaults, onChange);

map.on('moveend', function() {
  var view = map.getView();
  var center = view.getCenter();
  update({x: center[0], y: center[1], z: view.getZoom()});
});

// now the back/forward buttons navigate through map history!

<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add this (and permalink.js) to examples instead of examples_src. Rebasing on master should do the trick.

@tsauerwein tsauerwein force-pushed the permalink-example branch 2 times, most recently from f993b62 to c9c7bff Compare April 19, 2015 11:43
@tsauerwein
Copy link
Member Author

I updated the example, now the History API is used and also the rotation is taken into account.

the only thing I wondered is if we should keep the anchor structure the same as in OpenLayers 2 to make it easier for people that are coming from OpenLayers 2?

@bartvde I am now using the OSM schema: #map=5/41.146/25.488.

We could also demonstrate how to work with existing libraries :).

@tschaub Nice library! Could you also use it together with the History API?

@marcjansen
Copy link
Member

Sorry, I didn't want to close this...

A very nice example! Which versions of IE do support the History API? Will this silently fail in browsers that don't support it? If so, this is good to be merged. Thanks, @tsauerwein

@tsauerwein
Copy link
Member Author

The history API is supported in IE 10+. But there are Polyfills that could be used.

@marcjansen
Copy link
Member

A simple comment in the docs of the example would be sufficient. Please merge with or without adding such a comment.

@fredj
Copy link
Member

fredj commented Apr 20, 2015

LGTM, the values could be simplified a bit; centimeter level should be enough

@tsauerwein
Copy link
Member Author

@fredj Good point!

I will merge when Travis passes, thanks for all the feedback.

tsauerwein pushed a commit that referenced this pull request Apr 22, 2015
Add an example showing how to create a permalink
@tsauerwein tsauerwein merged commit 2a95049 into openlayers:master Apr 22, 2015
@tsauerwein tsauerwein deleted the permalink-example branch April 22, 2015 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants