CityOfSurrey

Adding click event to custom graphics layer causes application to hang when clicking

Discussion created by CityOfSurrey on Feb 24, 2012
I have a simple (well, maybe not so simple) map that populates a graphics layer with graphics based on locations in an XML file.  When trying to click on a graphic to check out the infotemplate, the application hangs.  Any idea why? 

Here is a link to the app:

http://cosmos.surrey.ca/geocortex/EssentialsExternal/web/tools/PRCMap/ParksMapMark.html

Here is the main code:


function addHiddenFacilitiestoMap(){
           var gsvc = new esri.tasks.GeometryService("http://cosmosbeta.surrey.ca/COSREST/rest/services/Geometry/GeometryServer");
           var markerSymbol = new esri.symbol.SimpleMarkerSymbol();
        var pt;
        var hiddenFacilitiesGraphic;
        var template = new esri.InfoTemplate(); 
        var infoWindowHeight = 100;
          var infoWindowWidth = 245;
         var content = "<div style='font-size:Smaller; font-bold:false'>";
         GISFacilitiesID = "";
        if (window.XMLHttpRequest){
          xhttpFacilities = new XMLHttpRequest();

          }
          else // Internet Explorer 5/6
          {
          xhttpFacilities = new ActiveXObject("Microsoft.XMLHTTP");
          }

        
        xhttpFacilities.open("GET","XML/facilitiesAll.xml",false);
        xhttpFacilities.send("");
        xmlDocFacilities = xhttpFacilities.responseXML;
        facilityFacilities = xmlDocFacilities.documentElement.getElementsByTagName("ROW");
        

        
        
        for (var i = 0; i < facilityFacilities.length; i++) {
      
        
        var X_COORDINATE= facilityFacilities[i].getElementsByTagName("X_COORDINATE")[0].firstChild ? facilityFacilities[i].getElementsByTagName("X_COORDINATE")[0].firstChild.nodeValue : "";
        var Y_COORDINATE= facilityFacilities[i].getElementsByTagName("Y_COORDINATE")[0].firstChild ? facilityFacilities[i].getElementsByTagName("Y_COORDINATE")[0].firstChild.nodeValue : "";
        var SURREY_COSMO_FACILITY_ID =  facilityFacilities[i].getElementsByTagName("SURREY_COSMO_FACILITY_ID")[0].firstChild ? facilityFacilities[i].getElementsByTagName("SURREY_COSMO_FACILITY_ID")[0].firstChild.nodeValue : "";
        var FACILITY_MASTER_NAME =  facilityFacilities[i].getElementsByTagName("FACILITY_MASTER_NAME")[0].firstChild ? facilityFacilities[i].getElementsByTagName("FACILITY_MASTER_NAME")[0].firstChild.nodeValue : "";
        var ADDRESS =  facilityFacilities[i].getElementsByTagName("ADDRESS")[0].firstChild ? facilityFacilities[i].getElementsByTagName("ADDRESS")[0].firstChild.nodeValue : "";
        var SURREY_URL =  facilityFacilities[i].getElementsByTagName("SURREY_URL")[0].firstChild ? facilityFacilities[i].getElementsByTagName("SURREY_URL")[0].firstChild.nodeValue : "";
        
        var attr = { "FACILITY_ID":SURREY_COSMO_FACILITY_ID, "FACILITY_MASTER_NAME":FACILITY_MASTER_NAME.trim(), "ADDRESS":ADDRESS.trim(), "SURREY_URL":SURREY_URL.trim()};
        
        //set up data for popup
        weblink = "<br /> <a  target='_blank' href=" + SURREY_URL + ">Click here for more information</a> <br />";
        content = content + "<b>Address: </b>" + ADDRESS + "<br />";
        var endAddress = ADDRESS + ", Surrey, BC";
          var endAddressFormatted = endAddress.replace(/ /gi, "+")
          var googleGetDirectionsUrlFormatted = String.Format(googleGetDirectionsUrl, endAddressFormatted);
          var googleDirections = "<br /> <a  target='_blank' href=" + googleGetDirectionsUrlFormatted + ">Get Directions</a> <br />";
        if (weblink !== null) content = content + weblink;
         if (googleDirections !== null && googleDirections !== undefined) content = content + googleDirections;
         content = content + "</div>";
        template.setContent(content); 
        template.setTitle("<b>" + FACILITY_MASTER_NAME + "</b>");
        //end setup data for popup
        
         if (X_COORDINATE !="" ){
                   
           xy=btnToUTM_OnClick (Number(X_COORDINATE),Number(Y_COORDINATE));
           

           var hiddenFacilities= new esri.geometry.Point(xy[0], xy[1]);
                 
                hiddenFacilitiesGraphic = new esri.Graphic();
                hiddenFacilitiesGraphic.setGeometry(hiddenFacilities);
                hiddenFacilitiesGraphic.setInfoTemplate(template);
                hiddenFacilitiesGraphic.setSymbol(markerSymbol);  
                hiddenFacilitiesGraphic.setAttributes(attr);  
                parkNameLayer.add(hiddenFacilitiesGraphic);
              
              }
        map.addLayer(parkNameLayer); 
        console.log(parkNameLayer.graphics);
        dojo.connect(parkNameLayer.graphics, "onClick", function (evt) {
         alert("clicked");
               //var g = evt.graphic;
               //map.infoWindow.setContent(g.getContent());
              // map.infoWindow.setTitle(g.getTitle());
               //map.infoWindow.resize(infoWindowWidth, infoWindowHeight); //infoWindowWidth * 7
             //  map.infoWindow.show(evt.screenPoint, map.getInfoWindowAnchor(evt.screenPoint));
          }); 
        }
 
        

  
}


Outcomes