Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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 ?

share|improve this question

1 Answer 1

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

share|improve this answer
    
Thanks Myra. How do you parse the items in OpenLayers ? Do you use KML layer ? Vector layer and adding the features ? or using directly HTTP layer ? –  Alophind Dec 25 '12 at 10:13
    
Depends on the project actually,but basically for vectors I always use GeoJSON layers.Others can be used as well.Please look at OpenLayers.Format specification.If you can serve as supported format,you do not need to parse objects at all.Putting a format option in OpenLayers.Layer would be sufficient. –  Myra Dec 25 '12 at 10:36
    
Care to link an example for good start ? :) –  Alophind Dec 25 '12 at 12:02
    
There are lots of examples on the internet,start with OpenLayers examples openlayers.org/dev/examples –  Myra Dec 25 '12 at 12:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.