4

I am working on a small JavaScript application for displaying map with WMS layers from 2 servers. The problem is, that image is stretched by latitude, it is wider, than it should be.

This is is how it is working now: http://postimg.org/image/pxk8lfnnd/

and this is how it should be, and how it Google maps displaying: http://postimg.org/image/al321lg6l/

This is JavaScript code:

var map = new OpenLayers.Map("map");
var ol_wms = new OpenLayers.Layer.WMS(
"NP Podyjí WMS",
    "http://mapy.nppodyji.cz/cgi-bin/mapserv.exe?map=f:/mapserv/projects/map/nppodyji_wms.map",
{
   layers: "nppodyji_wms,hranice_npt,hranice_np,cyklo_CR",
   transparent: "true",
  format: "image/png"
},
{ isBaseLayer: false, visibility: true } 
);

var ol_cz = new OpenLayers.Layer.WMS(
"Česká republika",
"http://geoportal.gov.cz/ArcGIS/services/CENIA/cenia_arccr/MapServer/WMSServer",
{layers: "0,3,4,6,7,10,12,13,14,15,16,17,19,20,21,22,23,24"}
);

map.addLayers([ol_cz, ol_wms]);
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.zoomToMaxExtent();

setTimeout(function() {
var fromProjection = new OpenLayers.Projection("EPSG:102067");   // Transform from WGS  1984
var toProjection   = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
 var position       = new OpenLayers.LonLat(15.8186 + (15.9626 - 15.8186) / 2,48.8027 + (48.8866 - 48.8027) / 2 ).transform( fromProjection, toProjection); 
 map.setCenter(position, 13);    
}, 100);

I tried many map.projection and map.displayProjection changes, but I'm not really sure, if it's projection problem.

It is only an example of bigger application, which take points from database and displays them dynamicaly. Displaying is correct; problem is, that client don't want it in different shape

Projection should be EPSG:102067, in HTML I have also included proj4js.js.

EDIT: I've solved only half of the problem: Without any display settings, it is displayed like this: http://postimg.org/image/czs81gzwj/ When I used:

var ol_cz = new OpenLayers.Layer.WMS(
    "Czech",
    "http://geoportal.gov.cz/ArcGIS/services/CENIA/cenia_t_podklad/MapServer/WMSServer",
{layers: "blablabla"},
    { projection: new OpenLayers.Projection('EPSG:3857')} 
);

it looks like this: http://postimg.org/image/vm8rkxgoz/ so exactly what I want! However problem is with another WMS server. When I was trying to change projection, or displayProjection in:

    var ol_wms = new OpenLayers.Layer.WMS(
    "NP Podyji WMS",
    "http://mapy.nppodyji.cz/cgi-bin/mapserv.exe?map=f:/mapserv/projects/map/nppodyji_wms.map",
    {
        layers: "nppodyji_wms,hranice_npt,hranice_np,cyklo_CR",
        transparent: "true",
        format: "image/png"
    },
    { isBaseLayer: false, visibility: true } ,
    { projection: new OpenLayers.Projection('EPSG:XXX'),
    displayProjection: new OpenLayers.Projection("EPSG:XXX")
} 
        );

It has basically no effect :/. I was trying several projections in "projection" attribute, also in displayProjection, but only visible output was http://postimg.org/image/yv0oe22tf/ (note the pink square on the bottom). So it get some parameters, but they are wrong, or maybe he server is wrong, I'm not really sure.

The 2nd WMS did not fit in the baselayer (1st WMS)

1

The main question is: does the WMS server support generating tiles in EPG:3857 projection? It seems, after querying for its capabilities, it supports Web Mercator for the layer nppodyji_wms. For the other ones, the only supported projection is EPSG:102067. As the requested layer is a composite made of several datasets, all the layers have to support the requested projection.

Also, some side notes:

  • displayProjection won't do anything with the CRS of the view. It only affects the mouse position, and the scale bar control.
  • @notkilroy, it is definitely possible to change projection after the map has been constructed. See this file for a working formula.
| improve this answer | |
0

When you were setting map.projection and map.displayProjection, did you set them when you initialized the map (as in this example), or did you set them after you created the map?

If you set them after creating the map, I don't believe the changes take effect (but I can't find documentation that says this explicitly).

| improve this answer | |
  • I've set them when I am initializing, that is not the problem. – user2783491 Feb 16 '14 at 10:56

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.