1

Here is some OpenLayers code:

var projection = "EPSG:3009";

map = new OpenLayers.Map('map', {

//    projection: "EPSG:900913",
//    displayProjection: projection,
//    displayProjection: "EPSG:4326",
});

var osm = new OpenLayers.Layer.OSM();

var protocol = new OpenLayers.Protocol.WFS({
    version: "1.1.0",
    srsName: projection,
    url: "http://" + window.location.hostname + "/geoserver/test/wfs",
    outputFormat: "application/json",
    readFormat: new OpenLayers.Format.GeoJSON(),
    featurePrefix: "test",
    featureNS :  "test",
    featureType: "eksjo_trad",
    maxFeatures: 1000,
    geometryName: 'geom',
});

wfs = new OpenLayers.Layer.Vector("WFS", {
    projection: new OpenLayers.Projection( projection ),
    strategies: [ 
        new OpenLayers.Strategy.BBOX(),
    ],
    protocol: protocol,
});

map.addLayers([ osm, wfs ]);
map.zoomToMaxExtent();

My problem is that OpenLayers draws the points in France instead of Sweden. I am including the proj4.js library, although this appears to make no difference.

If I redefine the 'projection' variable to be "EPSG:4326" the points appear in the right place. However, a user needs to be able to edit the co-ordinates in EPSG:3009 - I get the right co-ords when 'projection' = "EPSG:3009".

Here is the JSON with the EPSG:3009 co-ords for 1 feature returned by the WEF:

{"type":"Feature","id":"eksjo_trad.1","geometry":{"type":"Point","coordinates":[146224.14140031,6392371.57291367]},"geometry_name":"geom","properties":{"trad_id":1,"layer":"VG_TRAD_BARRTRAD__DIGITALISERAD 11000","subclasses":"AcDbEntity:AcDbPoint","extendedentity":null,"linetype":null,"entityhandle":"146B","text":null}},

Can anyone help me?

5
  • 1
    If you want to use OSM as baselayer your vectorlayer needs to be requested in or transformed to EPSG 3857. what kind of editing do you mean when you say "a user needs to be able to edit the co-ordinates in EPSG:3009" – Thomas B Feb 19 '15 at 15:14
  • That worked! - i did srsName: "EPSG:900913", in the protocol and the co-ods seem to be right. When I say "a user needs to be able to edit the co-ordinates in EPSG:3009" I mean that one user plots the features approximately then another plots them accurately using his hi-precision GPS. His GPS gives him EPSG:3009 coordinates, so that's what he'll use to update the feature's position – minisaurus Feb 19 '15 at 19:07
  • Ah - big problem - when I add new features - the geometry column is empty. Maybe I need to 'manually' transform before saving? – minisaurus Feb 19 '15 at 21:13
  • How do you save the features? I did not see anything like a save-strategy? does the user with his high precision GPS type in the coordinates manually? – Thomas B Feb 20 '15 at 8:41
  • Hi Thomas. Yes, save strategy. What I've presented is an extract from a much bigger thing. Since posting my answer below, I found out that setting srsName: "EPSG900913" in the protocol messes up display of "EPSG4326" layers!! So I got "EPSG:3009" to work, but broke "EPSG:4326". Bizarrely, if I load the 3009 layer with projection: 4326 and no srsName, it all works fine, geometries are saved and redisplayed correctly. – minisaurus Feb 20 '15 at 10:06
1

Ok, it turns out that OpenLayers 2.x can't see the proj4.js I'd downloaded (from here) ...

So, I downloaded pro4js.js v1.1.0 (note the extra 'js') from here: http://trac.osgeo.org/proj4js/wiki/Download

Then I did this after including the lib:

Proj4js.defs["EPSG:3009"] = "+proj=tmerc +lat_0=0 +lon_0=15 +k=1 +x_0=150000 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs";

which I got from: http://spatialreference.org/ref/epsg/sweref99-15-00/proj4js/

Now my example works :) It seems that the latest proj4.js is incompatible with OpenLayers 2.x. I did try the suggestions here, but my wfs wouldn't load, just returned the feature count.

OpenLayers - such a great library, so poorly documented ...

Mini

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.