Get data from SQL server via WebService for Cluster Points

2617
2
Jump to solution
04-07-2014 10:46 AM
JohnPreston
Occasional Contributor
Hi I've been trying to modify https://developers.arcgis.com/javascript/jssamples/layers_point_clustering.html to pull data from SQL Server via WebService. I'm not quite sure how to approach it. Do I use the ESRIRequest() like in the example? Or an .Ajax call like I usually use to get data from WebService? Or some  other method?

Here is modified code from original example (I changed the URL to the Webservice)...The Webservice doesn't fire.

var source = esriRequest({
      "url": "SWUWebService.asmx/GetSWUMaintenanceESRI",
      "handleAs": "xml"
       });
source.then(addClusters, error);

Any help or example would be greatly appreciated.
0 Kudos
1 Solution

Accepted Solutions
JohnPreston
Occasional Contributor
I got it to work...
map.on("load", function () {
                  // hide the popup's ZoomTo link as it doesn't make sense for cluster features
                  domStyle.set(query("a.action.zoomTo")[0], "display", "none");
                  var photos = $.ajax({
                        type: "POST",
                        url: "WebService.asmx/GetSWURequestRecentMap",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json"
                    });

                    photos.success(function (data) {
                        addClusters(data);
                    });
              });


function addClusters(resp) {
                  var obj = jQuery.parseJSON(resp.d);
                  var photoInfo = {};
                  var wgs = new SpatialReference({
                      "wkid": 4326
                  });
                  var photocnt = 0;
                  photoInfo.data = arrayUtils.map(obj, function (p) {
                      photocnt += 1;
                      var rec = p.split(";");
                      var latlng = new Point(parseFloat(rec[2]), parseFloat(rec[3]), wgs);
                      var webMercator = webMercatorUtils.geographicToWebMercator(latlng);
                        var attributes = {
                            "ID": rec[0],
                            "MaintDate": rec[1],
                            "X": rec[2],
                            "Y": rec[3]
                        };
                        return {
                              "x": webMercator.x,
                              "y": webMercator.y,
                              "attributes": attributes
                        };
                  });

Follow code in example after this point, just change fields names in template.

View solution in original post

0 Kudos
2 Replies
JohnPreston
Occasional Contributor
I tried just changing the ESRIRequest to "text" but still got nothing, is it a problem with the url?

var photos = esriRequest({
     "url": "SWUWebService.asmx/HelloWorld",
      "handleAs": "text"
});
photos.then(requestSucceeded, error);

function requestSucceeded(data) {
     console.log("Data: ", data); // print the data to browser's console
}

WebService...

<WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function
0 Kudos
JohnPreston
Occasional Contributor
I got it to work...
map.on("load", function () {
                  // hide the popup's ZoomTo link as it doesn't make sense for cluster features
                  domStyle.set(query("a.action.zoomTo")[0], "display", "none");
                  var photos = $.ajax({
                        type: "POST",
                        url: "WebService.asmx/GetSWURequestRecentMap",
                        contentType: "application/json; charset=utf-8",
                        dataType: "json"
                    });

                    photos.success(function (data) {
                        addClusters(data);
                    });
              });


function addClusters(resp) {
                  var obj = jQuery.parseJSON(resp.d);
                  var photoInfo = {};
                  var wgs = new SpatialReference({
                      "wkid": 4326
                  });
                  var photocnt = 0;
                  photoInfo.data = arrayUtils.map(obj, function (p) {
                      photocnt += 1;
                      var rec = p.split(";");
                      var latlng = new Point(parseFloat(rec[2]), parseFloat(rec[3]), wgs);
                      var webMercator = webMercatorUtils.geographicToWebMercator(latlng);
                        var attributes = {
                            "ID": rec[0],
                            "MaintDate": rec[1],
                            "X": rec[2],
                            "Y": rec[3]
                        };
                        return {
                              "x": webMercator.x,
                              "y": webMercator.y,
                              "attributes": attributes
                        };
                  });

Follow code in example after this point, just change fields names in template.
0 Kudos