gauldivic

Pop window problems.

Discussion created by gauldivic on Feb 9, 2013
Latest reply on Feb 11, 2013 by bgfield
I am making a web application with the javascript api and I am having a problem with the infowindows. Everywhere i click on the map a pop-up appears. I can't seem to figure out how to make it so that pop-ups only appear when I actually click on a feature.
unction init() {
        //setup the popup window 
        var popup = new esri.dijit.Popup({
          fillSymbol: new esri.symbol.SimpleFillSymbol(esri.symbol.SimpleFillSymbol.STYLE_SOLID, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255,0,0]), 2), new dojo.Color([255,255,0,0.25]))
        }, dojo.create("div"));
   
        map = new esri.Map("map", {
          basemap: "topo",
          center: [-77.568056, 43.123333],
          zoom: 11,
          infoWindow: popup
        });
        
        dojo.connect(map, "onLoad", mapReady);
        
        var landBaseLayer = new esri.layers.ArcGISDynamicMapServiceLayer("*****"   );
        map.addLayer(landBaseLayer);
      }
      
      function mapReady(map){
       dojo.connect(map,"onClick",executeIdentifyTask);
       //create identify tasks and setup parameters 
       identifyTask = new esri.tasks.IdentifyTask("******");
       
       identifyParams = new esri.tasks.IdentifyParameters();
       identifyParams.tolerance = 9;
       identifyParams.returnGeometry = true;
       identifyParams.layerIds = [0,1];
       identifyParams.layerOption = esri.tasks.IdentifyParameters.LAYER_OPTION_ALL;
       identifyParams.width  = map.width;
       identifyParams.height = map.height;
      }
      
      function executeIdentifyTask(evt) {
        identifyParams.geometry = evt.mapPoint;
        identifyParams.mapExtent = map.extent;
    
        var deferred = identifyTask.execute(identifyParams);
//console.log(deferred);
        deferred.addCallback(function(response) {     
          // response is an array of identify result objects    
          // Let's return an array of features.
          return dojo.map(response, function(result) {
            //console.log(response);
            var feature = result.feature;
           
            feature.attributes.layerName = result.layerName;
            //console.log( feature.attributes.layerName);
            if(result.layerName === 'nrhp'){
              //console.log(feature.attributes.Historic_Place_Name);
            var template = new esri.InfoTemplate();
              //NPS_Reference_Number
              
              map.infoWindow.resize(450,600);
              // map.infoWindow.setContent(feature.attributes.NPS_Reference_Number );
              var contentString = "";
              contentString += "<b>Name: </b>"+feature.attributes.Historic_Place_Name;
              
              contentString += "<br/><b>Date Listed: </b>"+feature.attributes.Date_Listed;
              
              contentString += "<br/><b>Lat,Long: </b>"+feature.attributes.Latitude+" , "+feature.attributes.Longitude;
              
              contentString += "<br/><b>Address: </b>"+feature.attributes.Address;

              contentString += "<br/>"+feature.attributes.City;
                            
              contentString += " , "+feature.attributes.State;
            
              contentString += "<br/><b>County: "+feature.attributes.County;
                
              contentString += "<br/><b>NPS Reference Number: </b>"+feature.attributes.NPS_Reference_Number;
              console.log(contentString);
              contentString += "<br/><b>Info: <a href='http://en.wikipedia.org/wiki/"+feature.attributes.Historic_Place_Name+"'>wikipedia+</a>";
              //console.log(feature.attributes.location);
              console.log(contentString);
              template.content = contentString;
              feature.setInfoTemplate(template);
            }
            else if (result.layerName === 'historical_markers'){
                console.log("poop");
                 console.log( feature.attributes.photo);
              var template = new esri.InfoTemplate();
              map.infoWindow.resize(450,600);
              var contentString = "";
              contentString += "<b>Name: </b>"+feature.attributes.name;
              contentString += "<br/><b>Lat,Long: </b>"+feature.attributes.latitude+" , "+feature.attributes.longitude;
              contentString += "<br/><b>Erected By: </b>"+feature.attributes.erected_by;
              contentString += "<br/><b>Location: </b>"+feature.attributes.location;
              //<a href="http://www.w3schools.com">Visit W3Schools</a>
              contentString += "<br/><b>Additional Info: </b><a href="+feature.attributes.additional+">"+feature.attributes.additional+"</a>";
              contentString += "<hr/><br/>";
              contentString += "<b>Photo:</b><br/><img src="+feature.attributes.photo+"><br/>";
              contentString += feature.attributes.image_sour;
              console.log(contentString);
              //<img src="smiley.gif" alt="Smiley face" height="42" width="42">
              template.content = contentString;
              feature.setInfoTemplate(template);
            }
            return feature;
          });
        });

      
        // InfoWindow expects an array of features from each deferred
        // object that you pass. If the response from the task execution 
        // above is not an array of features, then you need to add a callback
        // like the one above to post-process the response and return an
        // array of features.
        map.infoWindow.setFeatures([ deferred ]);
        map.infoWindow.show(evt.mapPoint);
      }
      //console.log(linkObj[85001957]);
      dojo.ready(init);
      

Outcomes