2

I have this single page web map app with esri js api 3.4 and arcgis server 10.1.

I have added a print widget and that works fine (with two base map layers and an empty feature layer with feature collection added) until I apply edits to my feature layer with an ajax query to a database the results of which are constructed as features each of which is a graphic (esri geomtry point).

some part of the code that caused the problem is stated below.

 var xmldoc = $.parseXML(xml.d);
                       var unfiltered = xmldoc.documentElement.getElementsByTagName("Marker");
                       if (own != '255') {
                           markers = array.filter(unfiltered, function (item) {

                               return item.getAttribute("CodeOwnership") == own;

                           });
                       }
                       else {
                           markers = unfiltered;
                       }


                       //alert('markers' + markers.length);
                       //loop through the items and add to the feature layer
                       var features = [];
                       if (markers.length > 0) {
                           for (i = 0; i < markers.length; i++) {
                               var item = markers[i];
                               var attr = {};
                               attr["SchoolName"] = item.getAttribute("SchoolName");
                               attr["Content"] = "<div style='width:400px; height:auto;' id='infowin'><b>School Name:</b>" + item.getAttribute("SchoolName") + "<br /><b>Sector:</b>" + item.getAttribute("Sector") + "<br /> <b>Ownership:</b>" + item.getAttribute("Ownership") + "<br /><b>Num Woreda Served:</b>" + item.getAttribute("NUMBER_WOREDA_SERVED") + "<br /><b>Distance Nearest School (KM):</b>" + item.getAttribute("DISTANCE_NEAREST_SCHOOL") + "<br /><b>Distance from Addis (KM):</b>" + item.getAttribute("DISTANCE_ADDIS") + "<br /><b>Distance Region (KM):</b>" + item.getAttribute("DISTANCE_REGION") + "<br /><b>Distance Zone (KM):</b>" + item.getAttribute("DISTANCE_ZONE") + "<br /><b>Distance Woreda (KM):</b>" + item.getAttribute("DISTANCE_WOREDA") + "<br /> <b>Located In Woreda:</b>" + item.getAttribute("Woreda") + "<br /><b> Established In:</b>" + item.getAttribute("EstablishmentYear") + "</div>";
                               attr["CODE_TYPE_SECTOR"] = item.getAttribute("CODE_TYPE_SECTOR");
                               attr["Sector"] = item.getAttribute("Sector");
                               var geometry = new Point(item.getAttribute("lng"), item.getAttribute("lat"));
                               var tt, cc;
                               var sector = item.getAttribute("CODE_TYPE_SECTOR");
                               if (sector == '1') {
                                   tt = SimpleMarkerSymbol.STYLE_SQUARE;
                                   cc = new Color([255, 0, 0]);
                               }
                               else if (sector == '2') {
                                   tt = SimpleMarkerSymbol.STYLE_DIAMOND;
                                   cc = new Color([23, 198, 65]);
                               }
                               else if (sector == '3') {
                                   tt = SimpleMarkerSymbol.STYLE_CIRCLE;
                                   cc = new Color([67, 78, 214]);
                               }
                               else if (sector == '4') {
                                   tt = SimpleMarkerSymbol.STYLE_CROSS;
                                   cc = new Color([220, 44, 145]);
                               }
                               else if (sector == '5') {
                                   tt = SimpleMarkerSymbol.STYLE_CIRCLE;
                                   cc = new Color([205, 78, 105]);
                               }
                               else if (sector == '6') {
                                   tt = SimpleMarkerSymbol.STYLE_SQUARE;
                                   cc = new Color([178, 98, 165]);
                               }
                               else if (sector == '7') {
                                   tt = SimpleMarkerSymbol.STYLE_SQUARE;
                                   cc = new Color([105, 70, 205]);
                               }
                               else if (sector == '8') {
                                   tt = SimpleMarkerSymbol.STYLE_SQUARE;
                                   cc = new Color([25, 68, 205]);
                               }
                               else if (sector == '9') {
                                   tt = SimpleMarkerSymbol.STYLE_SQUARE;
                                   cc = new Color([115, 98, 205]);
                               }
                               else if (sector == '10') {
                                   tt = SimpleMarkerSymbol.STYLE_SQUARE;
                                   cc = new Color([65, 89, 145]);
                               }
                               var s = new SimpleMarkerSymbol(tt).setSize(15).setColor(cc);
                               renderer.addValue(item.getAttribute("Sector").toString(), s);
                               var graphic = new Graphic(geometry);
                               graphic.setAttributes(attr);
                               features.push(graphic);

                           }

                           featureLayer.clear();
                           featureLayer.setRenderer(renderer);
                           var extent = esri.graphicsExtent(features);
                           if (!extent && features.length == 1) {
                               // esri.getExtent returns null for a single point, so we'll build the extent by hand
                               var point = features[0];
                               extent = new esri.geometry.Extent(point.x - 1, point.y - 1, point.x + 1, point.y + 1, point.SpatialReference);
                           }

                           if (extent) {
                               // assumes the esri map object is stored in the globally-scoped variable 'map'
                               map.setExtent(extent)
                           }
                          featureLayer.applyEdits(features, null, null);

So my question is what wrong with graphics added to the feature layer that caused the print to fail with error "code 500. error performing the execute operation?"

  • hi guys, I found the problem to be in my layer definition in the feature layer. I had an extra comma in the definition of the fields which resulted in creating an empty field with no name some thing like "....,{},.....". This above code is okay. so the print is now working fine. – Amy May 6 '16 at 15:23
  • I have one problem tho. The print out has a legend , the legend icons are displaying good, but the label of the icons are not displayed at all for all formats, pdf, png, jpg etc, I saw this (geonet.esri.com/thread/99559 ) but it says the problem is for vector outputs only. what could have have happened in my case? – Amy May 9 '16 at 7:41
  • need to have "label" parameter when adding the break values i.e rederer.addBreak({minValue:?,maxValue:?,label:?}); – Amy May 10 '16 at 10:23

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.