1

I have a worldwind tile server that works fine in OpenLayers 2. It is using a simple BMNG layer like so: http://worldwind.arc.nasa.gov/java/server/readme.html. Unfortunately, I cannot share the tile server with you because it is on a closed network. However, it is similar to the URL example provided below.

However, I am trying to upgrade us to OpenLayers 3. For some reason, the basic map will not display when I use OpenLayers 3.

I came back to this side of the world, and ran the following two tests. Now that I have matching URLs and layers in both examples, the OL3 version does not work either.

OPENLAYERS 2

<html>
<head>
<title>OpenLayers 2</title>
<link rel="stylesheet" href="http://dev.openlayers.org/releases/OpenLayers-2.13.1/theme/default/style.css" type="text/css">
<link rel="stylesheet" href="http://dev.openlayers.org/releases/OpenLayers-2.13.1/examples/style.css" type="text/css">
<script src="http://dev.openlayers.org/releases/OpenLayers-2.13.1/lib/OpenLayers.js"></script>
<script type="text/javascript">

var map;

function init() {
    map = new OpenLayers.Map( 'map' );

    var wmsLayer = new OpenLayers.Layer.WMS( "OpenLayers WMS",
              "http://vmap0.tiles.osgeo.org/wms/vmap0",
              {layers: 'basic'});
    map.addLayer(wmsLayer);

    map.setCenter(new OpenLayers.LonLat(0,0),4);
    map.zoomToMaxExtent();
}
</script>
</head>
<body onload="init()">
   <h1 id="title">WMS Example</h1>
   <p id="shortdesc">
      Shows the basic use of openlayers using a WMS layer
   </p>

    <div id="map" class="smallmap"></div>
</body>
</html>

And OPENLAYERS 3:

<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://openlayers.org/en/v3.11.0/css/ol.css" type="text/css">
<script src="http://openlayers.org/en/v3.11.0/build/ol.js"></script>

</head>
<body>
    <div id="map"></div>
    <script>
    var layers = [
         new ol.layer.Tile({
         source: new ol.source.TileWMS({
            url: 'http://vmap0.tiles.osgeo.org/wms/vmap0',
            params: {'LAYERS': 'basic', 'TILED': true},
            serverType: 'geoserver'
         })
      })
    ];
    var map = new ol.Map({
      layers: layers,
      target: 'map',
      view: new ol.View({
         center: [0, 0],
         zoom: 2
      })
    });
    </script>
</body>
</html>

On my network (not this side of the world), my tile server which displays a map perfectly in OpenLayers 2, is not working with the same code in OpenLayers 3.

Does anybody know what setting could be off between OL3 and WorldWind?

MORE INFORMATION:

Using mongoose-free-5.6, I am making my directory a temporary web-server. Now, given that, OL3 is making tile requests and getting responses from the tile server. I investigated the URL in the request header of one of the requests:

http://vmap0.tiles.osgeo.org/wms/vmap0?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=basic&TILED=true&WIDTH=256&HEIGHT=256&CRS=EPSG%3A3857&STYLES=&BBOX=-2504688.542848654%2C0%2C1.3969838619232178e-9%2C2504688.5428486555

And I get this in Chrome:

This XML file does not appear to have any style information associated with it. The document tree is shown below.

<ServiceExceptionReport xmlns="http://www.opengis.net/ogc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.3.0" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wms/1.3.0/exceptions_1_3_0.xsd">
    <ServiceException code="InvalidSRS">
        msWMSLoadGetMapParams(): WMS server error. Invalid CRS given : CRS must be valid for all requested layers.
    </ServiceException>
</ServiceExceptionReport>

FINAL ANSWER: Adding the projection to the View object is what got this to work here and on my closed network as well.

<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="http://openlayers.org/en/v3.11.0/css/ol.css" type="text/css">
<script src="http://openlayers.org/en/v3.11.0/build/ol.js"></script>
</head>
<body>
    <div id="map"></div>
    <script>
    var layers = [
         new ol.layer.Tile({
         source: new ol.source.TileWMS({
            url: 'http://vmap0.tiles.osgeo.org/wms/vmap0',
            params: {'LAYERS': 'basic', 'TILED': true},
            serverType: 'geoserver'
         })
      })
    ];
    var map = new ol.Map({
        layers: layers,
        target: 'map',
        view: new ol.View({
            projection: ol.proj.get('EPSG:4326'),
            center: [0, 0],
            zoom: 2
      })
    });
    </script>
</body>
</html>
Jonatas Walker
  • 11,553
  • 5
  • 43
  • 74
westandy
  • 1,040
  • 2
  • 12
  • 32
  • The error says, the CRS is not supported, so try a different one. EPSG:4326 for example. http://vmap0.tiles.osgeo.org/wms/vmap0?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&LAYERS=basic&TILED=true&WIDTH=256&HEIGHT=256&CRS=EPSG%3A4326&STYLES=&BBOX=-180,-90,180,90 – Grmpfhmbl Nov 14 '15 at 12:18
  • Grmpfhmbl - thank you! That did the trick. I'm posting the complete answer at the bottom of my question. – westandy Nov 16 '15 at 17:22

1 Answers1

1

As you did not post the URL of your tile server, I can only guess. This sounds like a CORS issue to me. If I understood you correctly, when in the above code, you change the URL of the tile server, it will not show in OL3 anymore, while in OL2 it works.

You might want to check the console of your browser for an error message like

XMLHttpRequest cannot load http://some.domain.com. Origin
http://other.domain.com is not allowed by Access-Control-Allow-Origin.

For a quick check, you can just disable cross origin checks in your browser (Firefox / Chrome). The OL3 variant should then also work.

Community
  • 1
  • 1
Grmpfhmbl
  • 1,044
  • 11
  • 22
  • @Gmpfhmbl - Nice catch! First, I matched the URL in OL2 with OL3. The OL3 version no longer displays the maps (just controls). I then started Chrome with --disable-web-security, and I get no map with controls. However, I am not getting the XMLHttpRequest error about Access-Control-Allow-Origin. Thank you for the response! – westandy Nov 12 '15 at 13:54
  • Have you had a look into the network traffic? Is OL3 even trying to load the tiles? How do you access the HTML-File? As "file://path/to/file/index.html" or have you put it on a web-server and you get the file via HTTP? File-URLs also make problems, when it comes to AJAX-calls. – Grmpfhmbl Nov 12 '15 at 15:49
  • Excellent point! I have looked into the network traffic, and I am using mongoose-free-5.6 to make a quick "web-server" out of the directory. I added information to my original question in regards to the network traffic. – westandy Nov 12 '15 at 16:05