My page contains two layers: 1. OpenStreetMap as a basic layer and WMS layer from mapserver as a overlay layer. My map show this two layers but in a wrong position. I spent a lot of time trying everything but it doesn't work. I changed mapfile and file to EPSG4326 projection but it doesn't work to.
This is my mapfile
MAP
IMAGETYPE "png24"
EXTENT 20.682299 52.148211 21.078846 52.337025
UNITS DD
SHAPEPATH "C:\ms4w\Apache\htdocs\projekt3\dane"
SIZE 800 600
DEBUG ON
FONTSET "C:\ms4w\Apache\fonts\fonts.txt"
PROJECTION
'proj=longlat'
'datum=WGS84'
'no_defs'
END
IMAGECOLOR 255 255 255
IMAGEQUALITY 95
IMAGETYPE png
OUTPUTFORMAT
NAME png
DRIVER 'GD/PNG'
MIMETYPE 'image/png'
IMAGEMODE RGBA
EXTENSION 'png'
END
SYMBOL
NAME "circle"
FILLED true
TYPE ellipse
POINTS 1 1 END
END
LAYER
NAME kilometraz_popr
DATA kilometraz_popr
STATUS ON
DUMP false
TYPE POINT
TRANSPARENCY 100
EXTENT 458986.052854 392913.684787 757412.357297 535008.411398
PROJECTION
'proj=tmerc'
'lat_0=0'
'lon_0=19'
'k=0.9993'
'x_0=500000'
'y_0=-5300000'
'ellps=GRS80'
'towgs84=0,0,0,0,0,0,0'
'units=m'
'no_defs'
END
CLASS
STYLE
SYMBOL "circle"
SIZE 7.0
OUTLINECOLOR 0 0 0
COLOR 90 23 223
END
END
END
LAYER
NAME etykiety
DATA kilometraz_popr
STATUS ON
TYPE annotation
PROJECTION
"init=epsg:2180"
END
LABELITEM OPIS_KM
TRANSPARENCY alpha
CLASS
LABEL
COLOR 0 0 0
FONT arial
#BACKGROUNDCOLOR 255 255 255
ENCODING "CP1250"
TYPE truetype
SIZE 7
POSITION AUTO
PARTIALS FALSE
BUFFER 5
OUTLINECOLOR 255 255 255
ANTIALIAS true
END
END
END
END
My index.html file is below:
<html lang='pl'>
<head>
<meta charset='utf-8' />
<title>Wawa</title>
<script type='text/javascript' src='OpenLayers.js'></script>
<script src="proj4js-combined.js"></script>
<script type='text/javascript'>
var map;
function init() {
epsg4326 = new OpenLayers.Projection("EPSG:4326");
epsg900913 = new OpenLayers.Projection("EPSG:900913");
epsg2180 = new OpenLayers.Projection("EPSG:2180");
var option = {
projection: new OpenLayers.Projection("EPSG:900913"),
displayProjection: new OpenLayers.Projection("EPSG:4326")
};
map = new OpenLayers.Map('mapa', option);
olmapnik = new OpenLayers.Layer.OSM("OpenStreetMap Mapnik", "http://tile.openstreetmap.org/${z}/${x}/${y}.png");
map.addLayer(olmapnik);
map.setBaseLayer(olmapnik);
var warstwa_wektor = new OpenLayers.Layer.MapServer("OpenLayers Mapserver", "http://localhost/cgi-bin/mapserv.exe", {map: 'C:/ms4w/map/map_test1.map', layers: 'kilometraz_popr', srs:'EPSG:4326', projection:epsg900913,
isBaseLayer: false,
visibility: true, transparent: true, format:'image/png'}, {opacity: 1});
map.addLayer(warstwa_wektor);
map.addControl
(new OpenLayers.Control.Scale());
map.addControl(new OpenLayers.Control.Navigation());
map.addControl(new OpenLayers.Control.MousePosition());
map.addControl(new OpenLayers.Control.PanZoomBar());
map.addControl(new OpenLayers.Control.SelectFeature());
map.addControl(new OpenLayers.Control.LayerSwitcher());
map.addControl(new OpenLayers.Control.Permalink());
extent = new OpenLayers.Bounds(19.50,51.50,21.50,52.7).transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"));
map.zoomToExtent(extent,5);
}
</script>
</head>
<body onload='init();'>
<div id='mapa' style='width: 800px; height: 400px;'>
</div>
</body>
</html>
Can you tell me my mistake?
Yes I know what I should do. My main mistake was projection. I use 3857 and everything works.
Best Answer
The
EPSG:900913
code was never a legitimate EPSG code.The code you're looking for is
EPSG:3857
which is the latest WGS84 Web/Pseudo-Mercator. Switch the 900913 to 3857 and make sure your proj4 library is up to date.Also remember that the default unit of measure for EPSG:3857 is XYs, whereas EPSG:4326 is a geographic projection with a lat/long unit of measure.