1

I am trying to add WMS layer from mapserver i.e. from localhost on Cesium Globe with the following HTML code. But I am not able to load or connect Cesium with the Mapserver and nothing is displayed on the browser. Mapserver is running successfully, there is no issue with Mapserver, I am not able to locate the error in the following code. Please tell me where I went wrong in the code.

I am not sure, whether URL is correct or not. Please tell how to add WMS layer from mapserver.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <!-- Use Chrome Frame in IE -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Add imagery from a Web Map Service (WMS) server.">
<meta name="cesium-sandcastle-labels" content="Beginner">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.9/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
"use strict";
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer');
// Add a WMS imagery layer
var imageryLayers = viewer.imageryLayers;
imageryLayers.addImageryProvider(new Cesium.WebMapServiceImageryProvider({
url : 'http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apache/htdocs/Sample2.map&mode=map&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities',
layers : 'villages',
parameters : {
transparent : true,
format : 'image/png'
}
}));

// Start off looking at Australia.
viewer.camera.viewRectangle(Cesium.Rectangle.fromDegrees(114.591, -45.837, 148.970, -5.730));//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
  • Are you really running the client (web browser) and the map server on the same machine? Not just the web server? Is C:/shapfiles/example.map really valid (note the missing e)? – BradHards Jan 21 '15 at 6:48
  • @BradHards, I checked both mapserver and webserver are running. Actually I am not sure, whether the url in the HTML file is correct or not. Actually this link is used to call shapefiles from folder through map file, as you might already know. Previous url was also correct, but in fact this edited url is also not working. – Padfoot Jan 22 '15 at 2:43
  • Is that trailing ` mark really present in the HTML? – BradHards Jan 22 '15 at 6:08
  • Sorry for bad editing. There is no trailing mark, I think while editing code in the post this might have added mistakenly. – Padfoot Jan 22 '15 at 8:01
1

You try to add an image layer, but your request states getCapabilities (the service description document). You probably mean GetMap ?

I don´t understand your url (It does not look standard WMS to me), but I would try something like

url : 'http://localhost/cgi-bin/mapserv.exe',
layers: 'villages'
parameters:{service:"WMS", 
            version:"1.1.1", 
            request:"GetMap", 
            styles:"", 
            format:"image/png", 
            transparent:"true"}

The url should be without parameters, and if you need other than the WebMapServiceImageryProvider.DefaultParameters you should specify them all as part of your parameters object. (As in my example)

  • 1
    MapServer allows a map parameter to point at the local location of the the configuration (MapFile) file, so its presence shouldn't be an issue in the query. The url here could be: http://localhost/cgi-bin/mapserv.exe?map=C:\ms4w\apache\htdocs\Sample2.map& it is the base URL to which all other (standard) WMS parameters are appended – nmtoken Aug 23 '16 at 22:05

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.