I looked on similar questions but in vain. The map is working fine but has a center of (0,0) as returned in the Firebug console not (-8, 32) that I want. I did the projection transformation.. Here is my code :

enter image description here


i am curious about that have you tried setMapObjectCenter method for solving this problem.


setMapObjectCenter: function (center,
zoom    )
Set the mapObject to the specified center and zoom

center  {Object} MapObject LonLat format
zoom    {int} MapObject zoom format

i hope it helps you...

  • I've tried that as well when I looked on the Openlayers Documentation for Google v3 layer :( – YossBen Apr 29 '12 at 15:13
  • But it seem I didn't manage to use that function properly. Would you plz write how I can use it? – YossBen Apr 29 '12 at 15:26
  • I've tried this------map.layers[0].setMapObjectCenter = function(center, zoom){center=lonlat; zoom=4;}; – YossBen Apr 29 '12 at 16:10
  • it is already a function. Your method is defining a new function in vain for solving the problem. map.layers[0].setMapObjectCenter(lonlat, zoom) should work for you. – Aragon Apr 29 '12 at 17:01
  • I've been using all this along with GeoExt, as soon as I removed all the GeoExt panels, tree, etc, it worked! – YossBen Apr 30 '12 at 18:00

Actually, I had to give a look on GeoExt Documentation as well especially the class GeoExt.mapPanel link here. The center of the map and the initial zoom must be specified in there and it worked finally:

    (...)map.addLayers([Gmap, institutions, pays]); 
    var point = new OpenLayers.LonLat(-6, 33); 
    point.transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
    var mapPanel = new GeoExt.MapPanel({
        region: 'center',
        height: 550,
        width: 1000,
        map: map,
        zoom: 4,
        center: point,
        title: 'Carte'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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