Version 33 (modified by Jeff McKenna, 5 years ago) ( diff )


Configuring MS4W and MapCache for use in OpenLayers 3

This was spawned by an MS4W user asking how to setup OpenLayers3 for an MS4W MapCache's WMS service (thread), with the following incorrect Javascript code, which did not write tiles to MS4W's cache directory:

new ol.layer.Tile({
title: 'Chabahar',    
source: new ol.source.TileWMS({
url: 'http://localhost:100/cgi-bin/mapserv.exe?map=D:/WEB_GIS/code_test/wms/HTML5Application/public_html/',
params: {
    'LAYERS': 'chabahar',
    'FORMAT': 'image/png',
    'TILED': true
serverType: 'mapserver'
                                        })  ,

Step 1: Initialize MapCache Module

  • follow all of the steps in MS4W's README to initialize the MapCache module
  • confirm that tiles are being generated inside the folder: /ms4w/tmp/ms_tmp/cache/

Step 2: Install MS4W's OpenLayers3 Package

  • if you haven't installed MS4W's OpenLayers 3 package (we'll use its sample WMS mapfile), please install it:
    • save the OpenLayers zip locally from:
    • extract its contents to the root of your MS4W installation
    • restart Apache: as Administrator, execute: /ms4w/apache-restart.bat
    • on your Web browser's MS4W homepage, click on the "MapServer WMS Example" link, in the OpenLayers section
    • this example uses a local WMS service, it should display the world countries as below: Default OpenLayers demo using sample WMS service from MS4W

Step 3: Configure mapcache.xml to use this WMS as a Source

  • add the following to your mapcache.xml file (and if necessary change the <url> and <map> paths):
    <source name="ms4wserver" type="wms">
  • edit the existing <tileset> section of mapcache.xml, so that it includes:
    <tileset name="test">
      <metatile>5 5</metatile>
  • delete the existing cache folder: /ms4w/tmp/ms_tmp/cache/test
  • restart Apache: as Administrator, execute: /ms4w/apache-restart.bat
  • on your Web browser's MS4W homepage, click on the "Demo" link in the "MapCache URLs" section. Then click on the "wmts" link. A world countries map should appear, and if you expand the "+" button on the top right, it should list a layer named "test-GoogleMapsCompatible WMTS", as below: Sample WMTS service through MapCache, using 3857 projection
  • zoom in a few times, and check your cache folder (/ms4w/tmp/ms_tmp/cache/test), you will notice that tile images are saved there.

Attachments (5)

Download all attachments as: .zip

Note: See TracWiki for help on using the wiki.