Cesium loads GeoServer's WMS (including cross-domain resolution)

This article mainly introduces the WMS process of Cesium loading GeoServer.

refer to

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

  1. Download the zip file http://shanbe.hezoun.com/cors.zip
  2. 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
  3. 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>
  4. Restart GeoServer

    The final page displayed by HelloWorld.html is:
    cesium_geoserver

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324525319&siteId=291194637