Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm working with MapServer/Postgis using OpenLayers to display map! I'm trying setCenter map but it not working! My code:

var bounds = new OpenLayers.Bounds(107.567139, 12.326586, 108.258591,
        12.890796);
var options = {
    controls : [],
    maxExtent : bounds,
    maxResolution : 0.0010217594533836,
    projection : "EPSG:4326",
    units : 'degrees',
    allOverlays : true
};

map = new OpenLayers.Map('map', options);
.....
//Declare some layers wms
.....
map.addLayer(wms_RanhGioi);
map.addLayer(wms_GiaoThong);
map.addLayer(wms_ATM);
map.addLayer(wms_Cafe);
map.addLayer(wms_KhachSan);
map.addLayer(wms_NhaHang);
map.addLayer(wms_TramXang);

map.addControl(new OpenLayers.Control.LayerSwitcher({
    'ascending' : false
}));
map.addControl(new OpenLayers.Control.PanZoomBar({
    position : new OpenLayers.Pixel(2, 15)
}));
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.Scale($('scale')));
map.addControl(new OpenLayers.Control.MousePosition({
    element : $('location')
}));
map.zoomToExtent(bounds);
map.setCenter(new OpenLayers.LonLat(12.67812, 108.04401), 5);

Somebody can help me! Thanks!!!

share|improve this question

3 Answers 3

You just put the center coordinates in wrong order. Longitude should come first and then the latitude. In your code, the point is out of the maxExtent you set in map options.

share|improve this answer

I have an extra (). Like this:

map.setCenter((new OpenLayers.LonLat(160000,485000)), 2);
share|improve this answer

Could be a problem with the map coordinate

var center = new OpenLayers.LonLat(12.67812, 108.04401);
center.transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
map.setCenter(center,5);
share|improve this answer
    
Thanks for reply! But it's not working! You can give me a demo of setCenter in OpenLayers! –  Si Do Dinh Jan 29 '13 at 11:55
1  
Thanks to everyone! I sloved problem! It's map.setCenter(new OpenLayers.LonLat(108.04401, 12.67812), 5); Instead map.setCenter(new OpenLayers.LonLat(12.67812, 108.04401), 5); –  Si Do Dinh Jan 29 '13 at 12:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.