1

I want to display a shapefile in OpenLayers using MapServer 7.6. It is shown properly in the browser using the mapfile's link.

It is shown properly in the browser using the mapfile's link.

But when I try to display it in OpenLayers, the geometry is completely ruined.

But when I try to display it in OpenLayers, the geometry is completely ruined.

I get no error messages.

What is the cause of this and how could I solve this?

Here is my code:

const map=new ol.Map({
    view: new ol.View({
        center: [2294319.8093533223, 5942407.910713993],
        zoom: 1
    }),
    target: "js-map"
})

    var wmsSource = new ol.source.ImageWMS({
        url: 'http://localhost/cgi-bin/mapserv.exe?MAP=/ms4w/apps/GEO/test.map',
        params: {'LAYERS': 'world'},
        serverType: 'mapserver',
        crossOrigin: 'anonymous'
    });

    var wmsLayer = new ol.layer.Image({
        source: wmsSource,
        title: "world"
    });

const overlayGroup=new ol.layer.Group({
    title: "Overlays",
    fold: 'open',
    layers: [wmsLayer]
})
map.addLayer(overlayGroup);

var layerSwitcher=new ol.control.LayerSwitcher({
    groupSelectStyle: 'group'
});
map.addControl(layerSwitcher);

And the mapfile:

MAP
  EXTENT -180 -90 180 90
  IMAGETYPE "png"
  NAME "world"
  SIZE 1381 1025
  STATUS ON
  UNITS METERS

  OUTPUTFORMAT
    NAME "png"
    MIMETYPE "image/png"
    DRIVER "AGG/PNG"
    EXTENSION "png"
    IMAGEMODE RGB
    TRANSPARENT FALSE
  END # OUTPUTFORMAT

  SYMBOL
    NAME "symbol1"
    TYPE ELLIPSE
    FILLED TRUE
    POINTS
      1 1
    END
  END

  PROJECTION
    "init=epsg:4326"
  END # PROJECTION
  LEGEND
    KEYSIZE 20 10
    KEYSPACING 5 5
    LABEL
      SIZE 10
      OFFSET 0 0
      SHADOWSIZE 1 1
    END # LABEL
    STATUS OFF
  END # LEGEND

  QUERYMAP
    SIZE -1 -1
    STATUS OFF
    STYLE HILITE
  END # QUERYMAP

  SCALEBAR
    INTERVALS 4
    LABEL
      SIZE 10
      OFFSET 0 0
      SHADOWSIZE 1 1
    END # LABEL
    SIZE 200 3
    STATUS OFF
    UNITS MILES
  END # SCALEBAR

  WEB
    METADATA
      "wms_srs" "EPSG:4326 EPSG:3857"
      "wms_onlineresource"  "http://localhost/cgi-bin/mapserv.exe?MAP=/ms4w/apps/GEO/test.map"
      "wms_enable_request"  "*"
      "mapmanager_version"  "1.1.0.0"
      "ows_enable_request"  "*"
      "wms_feature_info_mime_type"  "text/html"
      "wms_encoding"    "UTF-8"
      "wms_title"   "world"
    END # METADATA
  END # WEB

  LAYER
    DATA "E:/VECTOR/world_countries.shp"
    METADATA
      "wms_include_items"   "all"
      "wms_title"   "world"
    END # METADATA
    NAME "world"
    PROJECTION
      "init=EPSG:4326"
    END # PROJECTION
    STATUS DEFAULT
    TILEITEM "location"
    TYPE POLYGON
    UNITS METERS
    CLASS
      NAME "world"
      STYLE
        COLOR 58 132 59
        OUTLINECOLOR 30 30 30
      END # STYLE
    END # CLASS
  END # LAYER

END # MAP
11
  • 1
    Can you share the shapefile?
    – user30184
    Jan 22, 2020 at 21:51
  • 2
    Apparently, there is confusion about coordinates on the −180°/180° line. Try reducing the extent to something like 179.99.
    – CL.
    Jan 23, 2020 at 10:21
  • 2
    I could reproduce the issue and obviously it has something to do with reprojecting data that cover the whole world in EPSG:4326 into EPSG:3857. Some polygons which are near the −180°/180° line are turning around so that holes are polygons and the polygon is a hole. When using EPSG:4326 output from WMS everything is OK. Is it essential for you to show just this vector data in EPSG:3857, or are you just learning?
    – user30184
    Jan 23, 2020 at 10:52
  • 1
  • 1
    The question is clear for MapServer users and issue can be easily re-produced with the attached mapfile and linked shapefile and by using any WMS client as a viewer. The question is duplicate but it does not lack clarity for my mind. There are probably 3 polygons which are now wrapping around the World instead of just making a small step across the dateline.
    – user30184
    Jan 23, 2020 at 15:38

0

Browse other questions tagged or ask your own question.