0

Problem I have: map tiles from my layer are being repeated.

Shapefile is projection 3059. I have specified 3059 is in the mapfile and also when creating map object.

I know OpenLayers.Layer.WMS is recommended, but when I use it I only see empty map. When I use OpenLayers.Layer.MapServer, map is displayed (and tiles are repeated), so I'm using that for now.

My layer (EPSG:3059) looks like this

My layer

Versions:
Openlayers 2.13.1
MapServer 6.0.3

WMS Server mapfile:

MAP
    NAME country_map
    STATUS ON
    SIZE 800 500
    EXTENT 313187.4 146161.56 766469.92 470367.64
    UNITS METERS
    SHAPEPATH "shapefiles"
    IMAGECOLOR 155 155 155

    WEB
        TEMPLATE "template.html"
        IMAGEPATH "C:/MS4W/ms4w/apache/htdocs/gis/output/"
        IMAGEURL "/gis/output/"

        METADATA
            "wms_title"             "MapServer + Openlayers"
            "wms_onlineresource"    "http://localhost:1025/cgi-bin/mapserv.exe?map=C:\MS4W\ms4w\Apache\htdocs\gis\mapfile2.map"
            "wms_enable_request"    "*"
            "wms_srs"               "EPSG:3059"
        END
    END

    PROJECTION
        "init=epsg:3059"
    END

# example layer
    LAYER
    METADATA
        "wms_title"             "lat_rob_region"
    END
    NAME "lat_rob_region"
    DATA lat_rob_region
    STATUS ON
    TYPE POLYGON
        CLASS
            NAME "lat_rob_region"
            STYLE
                COLOR 0 255 0
            END
        END
    END
END

Javascript:

var lon = 25;
var lat = 57;
var zoom = 5;
var map, layer1;

function init()
{
    map = new OpenLayers.Map( 'map',{displayProjection: new OpenLayers.Projection("EPSG:3059")} );

    layer1 = new OpenLayers.Layer.MapServer( "Country map", 
            "http://localhost:1025/cgi-bin/mapserv.exe?map=C:/MS4W/ms4w/Apache/htdocs/gis/mapfile2.map", {layers: 'lat_rob_region'},
            {gutter: 15},{srs: 'EPSG:3059'});
    map.addLayer(layer1);

    map.setCenter(new OpenLayers.LonLat(lon, lat), zoom);
    map.addControl( new OpenLayers.Control.LayerSwitcher() );
}
  • Ok. I have realized that I can't reproject from 4326 to 3059 in a simple way. Server is rendering image tiles, I think I'd have to use Proj4js for reprojection. So the only problem I will work on now is the tile being repeated. – afaf12 Apr 23 '14 at 13:40
1

I found a reference to this problem here: http://docs.openlayers.org/library/layers.html.

If you are using a Layer.MapServer, and your map is being repeated several times, this indicates that you have not properly configured your map to be in a different projection. OpenLayers can not read this information from your mapfile, and it must be configured explicitly. The FAQ on setting different projection properties provides information on how to configure different projections in OpenLayers.


Link was dead but I managed to find an up to date version via Wayback Machine. It says:

OpenLayers supports any projection. A projection is a way of converting geographic coordinates -- latitude and longitude -- into a plane. There are three parameters in OpenLayers which are important to set if you wish to change projections: maxExtent , maxResolution, projection. These parameters are set, respectively, by default to:
-180,-90,180,90
1.40625
EPSG:4326

maxExtent is the maximum bounds, in the units of your map, of the plane in which you want to display information.
maxResolution is the number of mapunits per pixel at the highest zoom level
projection is used when issuing WMS or WFS requests to inform the server of the projection desired.*

To calculate maxResolution, it is generally safe to take the maximum dimension of the maxExtent, and divide that value by the width of your map div. So, for a map from -180 to 180, take the width (360) divided by a default map size of 256 to get 1.40625. To automate this process, you can also use 'auto' for a maxResolution.
You should also change the 'units' property on your map: this property is what allows OpenLayers to know what scale things are being rendered at, which is important for scale-based methods of zooming and the Scale display control.


Solution:

Bounds match EXTENT from my mapfile.
maxResolution is set to '0.125' or 'auto', both work. I got 0.125 this way:
(57-25) / 256 =
32 / 256 =
0.125
(57 is latitude and 25 is longtitude for country of Latvia)
Projection EPSG:3059 matches my mapfile.

Changing my map initialization to this fixed the tile repetition problem:

new OpenLayers.Map("map", {
maxExtent: new OpenLayers.Bounds(313187.4, 146161.56, 766469.92, 470367.64),
maxResolution: 'auto',
units: 'meters',
projection: "EPSG:3059"});

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.