2

.

i've got this problem about projection. .i just wanted to know what am i missing. .

i already displayed map base layer using openlayers through

base_layer =  new OpenLayers.Layer.WMS( "OpenLayers WMS",
           "http://vmap0.tiles.osgeo.org/wms/vmap0?", {layers: 'basic'} );

i also displayed my vector layer through

var layer = new OpenLayers.Layer.Vector("Butuan");
    map.addLayer(layer);
    var format = new OpenLayers.Format.GeoJSON();
    var feat = format.read({{my_geojson|safe}});
    layer.addFeatures(feat);

and my position is

map.setCenter(new OpenLayers.LonLat(125.54915811889646, 8.90855351100384),11);

which positions the view as i desired it to be. when i tried to change my base layer to

base_layer =  new OpenLayers.Layer.OSM("OpenStreetMap");

the center of the map is redirected to another location. .i guess that this problem pertains to the projection. i tried to change the center into

map.setCenter(new OpenLayers.LonLat(125.54915811889646, 8.90855351100384),11).transform(geographic, mercator);

which is defined as

var geographic = new OpenLayers.Projection("EPSG:4326");
       var mercator = new OpenLayers.Projection("EPSG:900913");

no changes has been noticed. .the position of the center is still redirected to another location. .

Can anyone suggest solutions on how to solve this problem?

I am using django framework. . vectorformats and simplejson to convert the retrieved spatial data into geojson from postgis. .

  • somebody has also helped me in dislaying my vector layer before i had noticed that problem. . credit to @jcs for helping. . – vklopt Mar 6 '14 at 9:22
  • What is the projection of the map object? – neogeomat Mar 8 '14 at 4:44
  • it's SRID:32651. . by the way, can i add polygon to the database with the same projection? – vklopt Mar 10 '14 at 0:34
  • When working with tiled layers like osm, google, bing, it is good idea to keep the map in 900913 projection as those tiles are in that system. otherwise many issues occur and it is difficult ro find problem. – neogeomat Mar 10 '14 at 4:30
1

The correct call of the map center should be:

           var lonLat = new OpenLayers.LonLat(lon, lat).transform(new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
            map.setCenter (lonLat, zoom);

At least this is how it works for me.

If your vector data is not in EPSG:4326, you have to reproject that too. The tiles are in EPSG:900913, and you should not change that.

  • hi Andre.. tnx for suggesting solutions. . i think my my problem is reprojecting my data .. we'll i might worked it out. . ^_^ – vklopt Mar 7 '14 at 1:09

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.