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've defined the following map:

Proj4js.defs["EPSG:31258"] = "+proj=tmerc +lat_0=0 +lon_0=13.33333333333333 +k=1 +x_0=450000 +y_0=-5000000 +ellps=bessel +towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232 +units=m +no_defs";
var googleProj = new OpenLayers.Projection("EPSG:900913");
var salzburgProj = new OpenLayers.Projection("EPSG:31258");
var bounds = new OpenLayers.Bounds(426249,294999,426251,295001);
var maxZoom = 19;
var minZoom = 15;
var res = [4.77731426696777,2.38865713348389,1.194328566741945,0.5971642833709725];

mapCOD = new OpenLayers.Map({
    div: "mapCODs",
    allOverlays: true,
    maxExtent: bounds,
    projection: googleProj,
    allowSelection: true,
    controls: [new OpenLayers.Control.PanZoomBar(), new OpenLayers.Control.Navigation()]
    });

var layer = new OpenLayers.Layer.OSM(
            "layer1",
            "tiles/input/${z}/${x}/${y}.png",
            {zoomLevels: maxZoom, zoomOffset: minZoom, resolutions: res}
        );          
mapCOD.addLayer(layer);

I have created map tiles by myself using mapnik. The map is visualized properly, but I have a shift problem when I try to add a vector layer as follows:

// feat = ...well formed GeoJson feature
var geojson_format = new OpenLayers.Format.GeoJSON({internalProjection: googleProj, externalProjection: salzburgProj});
var vector_layer = new OpenLayers.Layer.Vector(1);
vector_layer.addFeatures(geojson_format.parseFeature(feat));    
map.addLayer(vector_layer);

enter image description here

You can see the result in the image above: the vector layer (purple geometries) should be up-right shifted, in order to match the tiles below them. I do not understand why I obtain this behaviour: what is missing in my code?

share|improve this question
    
Why did you use OpenLayers.Layer.OSM, you should use OpenLayers.Layer.XYZ for custom tiles. Does your vector layer fit properly to default OSM layer? –  drnextgis Sep 6 '12 at 16:30
    
I used OSM map because I have produced tiles with Mapnik as the OpenStreetMap project does, so I have for them the same OSM directory strucure on my machine ("tiles/input/${z}/${x}/${y}.png"). But my tiles are not in 900913 projection. Any hints to use XYZ map? –  caneta Sep 7 '12 at 7:19
    
Could it be possible that mapnik is not using the right projection? Can you post here the configuration file used? –  Délawen Jul 16 '13 at 8:20
    
In the end I solved using Projection 900913 in both mapnik conf file and OpenLayers vector layers... –  caneta Jul 16 '13 at 8:31
    
@caneta If you have a solution to your problem you should post it as an answer to your own question. –  Snorfalorpagus Jul 16 '13 at 18:13
add comment

1 Answer

up vote 0 down vote accepted

The solution I found was using the same projection 900913 for both map and vector layer: the following line

var geojson_format = new OpenLayers.Format.GeoJSON({internalProjection: googleProj,
                                                      externalProjection: salzburgProj});

should be transformed into

var geojson_format = new OpenLayers.Format.GeoJSON();
share|improve this answer
add comment

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.