0

I want to get GeoJSON data from GeoServer using asp.net and AJAX enabled service. firstly I made a class for request web:

public class Request
{
    public static string WebRequestByUrl(string url)
    {
        string jsonData = "";
        try
        {
            var request = WebRequest.Create(url);
            request.ContentType = "application/json; charset=utf-8";
            var response = (HttpWebResponse)request.GetResponse();
            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                jsonData = sr.ReadToEnd().Replace("'", "-");
            }
        }
        catch (Exception)
        { }
        return jsonData;
    }
}

and AJAX enabled service codes

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Mapping
{
    // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
    // To create an operation that returns XML,
    //     add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
    //     and include the following line in the operation body:
    //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
    [OperationContract]
    public string WebRequestByUrl(string url)
    {
        // Add your operation implementation here
        return Request.WebRequestByUrl(url);
    }

    // Add more operations here and mark them with [OperationContract]
}

and JavaScript side

var mapping = {
getTmJson : function () {
    var url = "http://10.212.81.15:8080/geoserver/BEIS_WS/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=BEIS_WS:ilce&maxFeatures=50&outputFormat=application/json";
    var service = new Mapping();
    service.WebRequestByUrl(url, function (data) {
        console.log(data)
        mapping.showData(data);
    }, null, null);
},
showData: function (data) {
    var raster = new ol.layer.Tile({
        source: new ol.source.MapQuest({
            layer: 'sat'
        })
    });

    var vector = new ol.layer.Vector({
        source: new ol.source.GeoJSON({
            projection: 'EPSG:5254',
            object:data
        })
    });

    var select = new ol.interaction.Select();

    var modify = new ol.interaction.Modify({
        features: select.getFeatures()
    });

    var map = new ol.Map({
        interactions: ol.interaction.defaults().extend([select, modify]),
        layers: [new ol.layer.Tile({ source: new ol.source.MapQuest({ layer: 'osm' }) }), vector],
        target: 'map',
        view: new ol.View({
            center: [0, 0],
            zoom: 2
        })
    });
}

}

and result I can get JSON data from GeoServer, but I can't make it integrate with OpenLayers vector

var vector = new ol.layer.Vector({
        source: new ol.source.GeoJSON({
            projection: 'EPSG:5254',
            **object:data**
        })
    });

error is ** Uncaught TypeError: Cannot read property 'c' of undefined**

where is my mistake?

2
  • Try to readout your JSON response in a file or webpage and then see if ti's proper JSon on : jsonlint.com If it's proper JSON your error is on the client side if not it's on the server side. Jan 15, 2015 at 14:41
  • well i have done it. i can show geojson wfs data from geoserver and edit with interactions on map but i dont know how to record transactions to geoserver ? Jan 15, 2015 at 16:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.