Is it possible to get openlayers3 to center the map on the location of a click?
Don't have any code to show as i am just curious and can't seem to find any information regarding this.
Is it possible to get openlayers3 to center the map on the location of a click?
Don't have any code to show as i am just curious and can't seem to find any information regarding this.
I've just had the same issue and used @kttii's answer to solve it.
function myZoom() {
myView = new ol.View({
center: ol.proj.transform([ -46.604057, -23.542679 ],"EPSG:4326","EPSG:3857"), zoom: 11 });
map.setView(myView);
}
Now, just add the call to myZoom() to your trigger (mine is a button):
<button onclick="myZoom()">Click me to zoom!</button>
A quick google search and I found this example to get the mouse coordinates:
https://openlayersbook.github.io/ch09-taking-control-of-controls/example-03.html
and this example to set the center of the map:
Change OpenLayers 3 view center
After you implement this code, please feel free to post a new question.