Cesium 调用Geoserver WFS服务及解决GeoJson在源码中报错的问题

坐标系是srs=EPSG:4326

data:

var Params = {
            
           
            //管线数据
            url: "http://xxx.xx.xx.xxx:8080/gsupserver/test1/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=test1%3Akm_spl&maxFeatures=25000&outputFormat=application/json"
           
        };

跨域的问题用Handler.ashx来处理

$.ajax({
            type: 'GET',
            url: "BigData/Handler.ashx?Action=KunMingGuanXian",
            data: Params,
            success: function (data, status, xhr) {
                var obj = JSON.parse(data);
                //$.each(obj.features, function (i, item) {
                //    delete obj.features[i].properties.material;
                //})
                
                Cesium.Math.setRandomNumberSeed(0);
                var promise1 = Cesium.GeoJsonDataSource.load(obj);

                promise1.then(function (dataSource) {
                    //var datasource = dataSource;
                    viewer.dataSources.add(dataSource);

                    //Get the array of entities
                    var entities = dataSource.entities.values;

                    var colorHash = {};
                    for (var i = 0; i < entities.length; i++) {
                        //For each entity, create a random color based on the state name.
                        //Some states have multiple entities, so we store the color in a
                        //hash so that we use the same color for the entire state.
                        var entity = entities[i];
                        var polygonExtend = { polygon: { material: 's', outline: true, extrudedHeight: 0 }, properties: { Population: 1000 }, name: 'Massachusetts' };

                        var entity = $.extend({}, entity, polygonExtend);
                        var name = entity.name;
                        var color = colorHash[name];
                        if (!color) {
                            color = Cesium.Color.fromRandom({
                                alpha: 1.0
                            });
                            colorHash[name] = color;
                        }

                        //Set the polygon material to our random color.
                        entity.polygon.material = color;
                        //Remove the outlines.
                        entity.polygon.outline = false;


                        entity.polygon.extrudedHeight = 5000.0;
                    }
                }).otherwise(function (error) {
                    //Display any errrors encountered while loading.
                    window.alert(error);
                });
                viewer.flyTo(promise1);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(XMLHttpRequest.status);
               
            }
        })

C#端请求代码

public static string RequestWebGet(string url)
        {
            //创建请求
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            //GET请求
            request.Method = "GET";
            request.ReadWriteTimeout = 5000;
            request.ContentType = "text/html;charset=UTF-8";
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream myResponseStream = response.GetResponseStream();
            StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("utf-8"));

            //返回内容
            string retString = myStreamReader.ReadToEnd();
            return retString;
        }

展现效果

 

你可能感兴趣的:(Cesuim)