I'm using OpenLayers 3 to interact with some maps. I first declare my map:
map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
view: new ol.View({
center: [0, 0],
zoom: 2
})
});
I've an event that triggers an action, to change my map's view center. This way, (my coordinates are in EPSG:4326 format):
function CenterMap(lat, long) {
console.log("Lat: " + lat + " Long: " + long);
map.setView(new ol.View({
center: ol.proj.transform([lat, long], 'EPSG:3857', 'EPSG:4326'),
zoom: 5
}));
}
When the function runs I get this at the explorer console:
Lat: 9.0412851667 Long: -79.5658145000
But the maps goes to [0,0], does anyone knows why this happen?
Uncaught TypeError: Failed to execute 'putImageData' on 'CanvasRenderingContext2D': float parameter 3 is non-finite. ol.js:457 2Uncaught RangeError: Invalid array length. And I think is because my coordinates are too long. If I change it for[131.044922, -25.363882]it works ok. So are my coordinates too long?? – Guillelon Sep 05 '14 at 20:19console.log(typeof lat + " " + typeof long + " ");or pass more of the code, i could try to find the error or bug.
– Simon Zyx Sep 05 '14 at 20:59ol.proj.fromLonLat([long,lat])for the same result but with slightly improved readability – bluefish Jan 14 '21 at 09:47