1

The following code is deprecated in Google Maps V3 and ESRI arcgis maps, I want to update into new versions, but I am trapped in query.queryGeometry = poly1; poly1 is self-defined polygon.

function runtask(poly1) 
        {
            mapExtension = new esri.arcgis.gmaps.MapExtension(map);
            esri.arcgis.gmaps.Config.proxyUrl = "proxy.ashx";
            var qtask = new esri.arcgis.gmaps.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/0");
            var query = new esri.arcgis.gmaps.Query();
            var polygonArea = poly1.getArea();
            query.queryGeometry = poly1;
            query.returnGeometry = true;
            query.outFields = ['POP2000', 'HOUSEHOLDS', 'BLOCK'];
            qtask.execute(query, false, displayStats);
        }

        function displayStats(fset, error) {
            if (error) 
            {
                alert("Error " + error.code + ": " + (error.message || (error.details && error.details.join(" ")) || "Unknown error"));
                return;
            }
            var features = fset.features;
            var popTotal = 0;
            var houseTotal = 0;
            var blockTotal = 0; 
            for (var x = 0; x < features.length; x++) {
                popTotal = popTotal + features[x].attributes['POP2000'];
                houseTotal = houseTotal + features[x].attributes['HOUSEHOLDS'];
                blockTotal = blockTotal + 1;
            }
            if (navigator.appName == "Microsoft Internet Explorer") {
                document.getElementById('Label1').innerText = popTotal;
                document.getElementById('Label2').innerText = houseTotal;
                document.getElementById('Label8').innerText = blockTotal;
            }
            else {
                document.getElementById('Label1').textContent = popTotal;
                document.getElementById('Label2').textContent = houseTotal;
                document.getElementById('Label8').textContent = blockTotal;
            }

            var qtask2 = new esri.arcgis.gmaps.QueryTask("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/1");
            var query2 = new esri.arcgis.gmaps.Query();
            query2.queryGeometry = poly1;
            query2.returnGeometry = true;
            // The default spatial relationship is esri.arcgis.gmaps.SpatialRelationship.INTERSECTS
            query2.outFields = ["AGE_UNDER5", "AGE_5_17", "AGE_18_21", "AGE_22_29", "AGE_30_39", "AGE_40_49", "AGE_50_64", "AGE_65_UP"];
            qtask2.execute(query2, false, setBlockGroupPolyArr);
            draw(centre); 
        }

        function setBlockGroupPolyArr(fset) 
        {
            blockGroupPolyArr = fset.features;
            for (var i = 0, il = blockGroupPolyArr.length; i < il; i++) 
            {
                displayBlockGroupPolys(blockGroupPolyArr[i]);
            }
        }

        function displayBlockGroupPolys(blockGroupPolyArr) 
        {
            censusPolyArr = [];
            var feature = blockGroupPolyArr;
            var att = feature.attributes;
            var age_under5 = parseInt(att.AGE_UNDER5);
            var age_5_17 = parseInt(att.AGE_5_17);
            var age_18_21 = parseInt(att.AGE_18_21);
            var age_22_29 = parseInt(att.AGE_22_29);
            var age_30_39 = parseInt(att.AGE_30_39);
            var age_40_49 = parseInt(att.AGE_40_49);
            var age_50_64 = parseInt(att.AGE_50_64);
            var age_65_up = parseInt(att.AGE_65_UP);
            total = age_under5 + age_5_17 + age_18_21 + age_22_29 + age_30_39 + age_40_49 + age_50_64 + age_65_up;
            age_under5 = (age_under5 / total) * 100;
            age_5_17 = (age_5_17 / total) * 100;
            age_18_21 = (age_18_21 / total) * 100;
            age_22_29 = (age_22_29 / total) * 100;
            age_30_39 = (age_30_39 / total) * 100;
            age_40_49 = (age_40_49 / total) * 100;
            age_50_64 = (age_50_64 / total) * 100;
            age_65_up = (age_65_up / total) * 100;
            var infoWindowOption = {
                content: "<div style='width:325px; height:125px;'><b>Total 2000 Census Block Population is: " + total + ".</b><br />The age breakdown is as follows: <br />"
                    + "<img  src='http://chart.apis.google.com/chart?cht=p3&chs=300x100&chd=t:"
                    + age_under5 + "," + age_5_17 + "," + age_18_21 + "," + age_22_29 + ","
                    + age_30_39 + "," + age_40_49 + "," + age_50_64 + "," + age_65_up + "&chs=300x100&chl=<5 ("
                    + Math.round(age_under5) + "%)|5-17 ("
                    + Math.round(age_5_17) + "%)|18-21 ("
                    + Math.round(age_18_21) + "%)|22-29 ("
                    + Math.round(age_22_29) + "%)|30-39 ("
                    + Math.round(age_30_39) + "%)|40-49 ("
                    + Math.round(age_40_49) + "%)|50-64 ("
                    + Math.round(age_50_64) + "%)|>65 ("
                    + Math.round(age_65_up) + "%)' /></div>"
            };
            var overlayOptionsPoly = {fillOpacity: 0.05};
            censusPoly = mapExtension.addToMap(feature, overlayOptionsPoly, infoWindowOption);
            censusPolyArr.push(censusPoly);
        }

My new version runtask(poly1) is as below, I do not know how to do spatial filter by poly1 as above.

function runtask(poly1) {
            gmaps.ags.Config.proxyUrl = "proxy.ashx";
            var url = 'http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer';
            layer = new gmaps.ags.Layer(url + '/0'); ///POLYGON layer
            var style = {
                fillColor: '#333388',
                fillOpacity: 0.35,
                strokeColor: '#FFFFFF',
                strokeWeight: 1,
                strokeOpacity: 1,
                zIndex: 0
            };
            var params = {
                returnGeometry: true,
                where: "ObjectID=2",
                //geometry: -179.619162909091,71.3629552727273,
                outFields: ['POP2000', 'HOUSEHOLDS', 'BLOCK'],
                overlayOptions: style
            };

            //layer.query(params, setBlockGroupPolyArr);
            layer.query(params, displayStats);
            //draw(centre);
        }
           [![enter image description here][1]][1]

I want to have the following blue polygon within poly1: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.