NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum


I have set up osm2pgsql,mapnik on ubuntu server. I have also generated tiles locally. Now I want to display these tiles on map in a JSP page. I am using open layers. I have been trying it. The code works fine in html, but if same thing I do in a jsp page, it does not open map tiles. Only pink canvas is displayed. On rightclick, it displayes map tile path as "/LocalFolder///.png". Error screen shot is attached. And source code is given below.

Please let me know what is the procedure I should follow to display local map on a jsp page(Tomcat server),


function init() {

        map = new OpenLayers.Map ($('map'), {
                new OpenLayers.Control.Navigation(),
                new OpenLayers.Control.PanZoomBar(),
                new OpenLayers.Control.Permalink(),
                new OpenLayers.Control.ScaleLine({geodesic: true}),
                new OpenLayers.Control.Permalink('permalink'),
                new OpenLayers.Control.MousePosition(),                    
                new OpenLayers.Control.Attribution()],
           maxExtent: new OpenLayers.Bounds(-180,-90,180,90),
            minExtent: new OpenLayers.Bounds(-1,-1,1,1),

            'maxResolution': 360/512,
            numZoomLevels: 4,
            units: 'dd',
            projection: new OpenLayers.Projection("EPSG:900913"),
          //  displayProjection: new OpenLayers.Projection("EPSG:4326")
        displayProjection: new OpenLayers.Projection("EPSG:900913")
        } );

        layerMapnik = new OpenLayers.Layer.OSM.Mapnik("Mapnik");
      //  map.addLayer(layerMapnik);

        layerCycleMap = new OpenLayers.Layer.OSM.CycleMap("CycleMap");
      //  map.addLayer(layerCycleMap);

        // This is the layer that uses the locally stored tiles
       var newLayer = new OpenLayers.Layer.OSM("Localhost",
         "IndiaMap/${z}/${x}/${y}.png", {numZoomLevels: 4, alpha: true,
         isBaseLayer: true});
        //var newLayer = new OpenLayers.Layer.OSM("LocalTiles",
         "IndiaMap/${0}/${0}/${0}.png", {numZoomLevels: 10, alpha: true,
         isBaseLayer: true});
        //layerLocalMap = new OpenLayers.Layer.OSM.LocalMap("LocalMap");
    //  layerLocalMap.setOpacity(0.4);
        // This is the end of the layer

            var switcherControl = new OpenLayers.Control.LayerSwitcher();

        if( ! map.getCenter() ){
            var lonLat = new OpenLayers.LonLat(lon, lat).transform(new  OpenLayers.Projection("EPSG:4326"), map.getProjectionObject());
            map.setCenter (lonLat, zoom);


asked 22 Aug '12, 08:32

Reshma%20Maner's gravatar image

Reshma Maner
accept rate: 0%

edited 22 Aug '12, 12:37

NicolasDumoulin's gravatar image


I don't know how tomcat processes URL, but I will suggest:

  • check which URL your browser send to the server for the tiles (with firebug or webkit network analyser)
  • look at the access log on your server to see what request your server process

Maybe your server process ${x} as a variable in the URL … in this case, it should be a way to bypass that (with an escape pattern)

permanent link

answered 22 Aug '12, 14:25

NicolasDumoulin's gravatar image

accept rate: 13%

Thanks for the help. Putting escape character solved the problem.

One more query please. I have generated tiles for India map using Mapnik. I can display them on a jsp page using openlayers. Do I need to run a separate map server now for serving the tiles OR only if I copy the tiles on my main server and give the path of that folder in my jsp code will do?

Basically, I want to know if map tiles are stored in a local folder and accessed from there in a jsp page, why is a map server required?

(23 Aug '12, 14:08) Reshma Maner

If you want only serve tiles, mapserver isn't needed. You can serve tiles with any file http server.

Don't forget to close your question if it's ok.

(23 Aug '12, 14:38) NicolasDumoulin

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 22 Aug '12, 08:32

question was seen: 4,831 times

last updated: 23 Aug '12, 14:38

NOTICE: is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum