This article mainly introduces the WMS process of Cesium loading GeoServer.
refer to
- cesium 3D GIS development practice (2)
- [Geoserver-users] CORS for jetty 6.1.8 (Geoserver 2.x), solved
background
System: win10
Map server: geoserver (2.12.1)
jdk: 1.8
cesium: 1.44
For the basic operation of Cesium, please refer to the official documentation.
For the installation of GeoServer, please refer to my first two articles:
- Installation and startup
of GeoServer - Release of WMS (Web Map Service) based on GeoServer
WMS code to load GeoServer
Take Cesium's HelloWorld.html as an example, write the following code in Javascript in the body:
<body>
<div id="cesiumContainer"></div>
<script>
var url='http://localhost:8080/geoserver/wms'; //Geoserver(我的端口号默认为8080)
var viewer = new Cesium.Viewer('cesiumContainer',{
imageryProvider:new Cesium.WebMapServiceImageryProvider({
url : url,
layers: 'nurc:Arc_Sample'// GeoServer自带的图层名
}),
baseLayerPicker:false // 去掉自带的图层选择器
});
</script>
</body>
Solve the problem of geoserver cross-domain request
- Download the zip file http://shanbe.hezoun.com/cors.zip
- Put it under [Geoserver]\webapps\geoserver\WEB-INF\ and unzip it. The final file path is as follows:
[Geoserver]\webapps\geoserver\WEB-INF\org\mortbay\servlets\CrossOriginFilter.class - Modify the web.xml file under [geoserver]/webapps/geoserver/WEB-INF and add the following content
in<filter>
the level position:
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
<init-param>
<param-name>allowedOrigins</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>allowedMethods</param-name>
<param-value>GET,POST</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>x-requested-with,content-type</param-value>
</init-param>
</filter>
...其他内容
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Restart GeoServer
The final page displayed by HelloWorld.html is: