I'm trying to center an OpenLayers map over New Mexico (NM) and having a hard time to get it working.
Here is my code. I'm trying to use decimal values and not the pixel values OpenLayers uses by default.
var init = function () {
// create map
map = new OpenLayers.Map({
div: "map",
theme: null,
projection:"EPSG:4326",
controls: [
new OpenLayers.Control.Attribution(),
new OpenLayers.Control.TouchNavigation({
dragPanOptions: {
enableKinetic: true
}
}),
new OpenLayers.Control.Zoom()
],
layers: [
new OpenLayers.Layer.OSM()
],
center: new OpenLayers.LonLat(105.9372, 35.6869),
zoom: 5
});
};
Best Answer
The easiest way to solve your problem is set your center attribute to something like this:
~Update for how I quickly pulled the lat/lon value listed above:
I pulled your code into a demo from the OpenLayers website (openlayers.org/dev/examples/mobile-navigation.html).
Then I used Chrome Dev Tools to actually find your location in the current projections units. To do this, I panned the map over to New Mexico. Then in the console tab in Dev tools, I called the OpenLayers getCenter method, and inspected the object that came back as a result. This is basically what you would see:
map.getCenter()
Screenshot of the dev console