[GIS] Retrieving features from MSSQL to OpenLayers and displaying them

openlayers-2sql server

Today I have a table in the DB with columns Feature Name and Feature Point.

When I want to load the points to OL I do the following :

  1. First I call web service to get list of json objects:

    var request = OpenLayers.Request.POST( { url:
    "../service.asmx/GetCameraFeatures", async: false, data: "{}",
    headers: { "Content-Type": "application/json; charset=utf-8" },
    callback: this.callbackLoadCameras});

  2. I parse points to features and add to the layer:

var objArr = eval('(' + request.responseText + ')').d;
        var jsonFormat = new OpenLayers.Format.JSON();
        var features = jsonFormat.read(objArr);       
        var format = new OpenLayers.Format.WKT();
        var featuresArr = [];

    for (var i = 0; i < features.length; i++) {
        var f1 = format.read(features[i].point);
      f1.id = features[i].name;
        featuresArr.push(f1);
    }

    if (featuresArr.length > 0) {
        cosmeticLayer.addFeatures(featuresArr);
    }

Is there a better way to do this ? faster? more convenient ?

Best Answer

I always use ASP.NET Handler (.ashx) for object requests. Web Services may look older technology than WCF services,but in technique they are similar.You can use them as well.

If I wish to present json in ASP.NET,I think of two ways:

One of which,If I wish to change the content of my json by adding properties to each feature etc.,then I simply create a class containing all values of my content and serialize JSON and serve within my handler as response.

Second one is,serve directly from your database as json string with or without using services (simple get request would be enough) by implementing stored procedures and functions,I use one in Oracle for SDO_Geometry that I hope there are similar one in MSSQL Spatial.

For performance:

  • I suggest to use gzip in IIS,your json content shall be less size.
  • There are some techniques here which you should avoid in serialization
  • And there is a comparison between frameworks here

Best Regards
Myra

Related Question