gis_tech

2 quick questions/problems with the InfoTemplate object

Discussion created by gis_tech on Oct 17, 2011
Latest reply on Oct 17, 2011 by DSwingley-esristaff
I???ve got an AddressLocator set up and it???s doing a great job for returning results to my JavaScript map.  I???m finding two odd things with the infoTemplate pop-up window (see attached image) and was hoping someone here could please help me.

Problem #1: Old pop-up windows do not automatically close when their associated SimpleMarkerSymbol is removed from the map.  In the attached image, you see that the blue SimpleMarkerSymbol is in a different location than the infoTemplate.  That???s because the infoTemplate is at the location of the previous search result.  How to I get these infoTemplates to close when a new result is returned?

Problem #2: You???ll also see in the attached image that extraneous data is being appended onto the address information.  I need this infoTemplate to say ???202 Birch Loop???, not ???202 Birch Loop, 15???.  I???ve pasted the related code below:

        function locate() {
            map.graphics.clear();
            var Street = { "Street": dojo.byId("address").value };
            locator.outSpatialReference = map.spatialReference;
            locator.addressToLocations(Street, ["*"]);
        }

        function showResults(candidates) {
            var candidate;
            var symbol = new esri.symbol.SimpleMarkerSymbol();
            var infoTemplate = new esri.InfoTemplate("Location", "<b>Address:</b> ${address2}<br /><br /><a href='BuildingDetails.aspx?Ref_ID=${Link}' target='_blank'>More Info...</a>");

            symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE);
            symbol.setColor(new dojo.colorFromHex("#03E9FC"));

            var geom;

            dojo.every(candidates, function(candidate) {
                console.log(candidate.score);
                if (candidate.score > 80) {
                    console.log(candidate.location);
                    var attributes = { address2: candidate.attributes.Match_addr, Link: candidate.attributes.State };
                    geom = candidate.location;
                    var graphic = new esri.Graphic(geom, symbol, attributes, infoTemplate);
                    //add a graphic to the map at the geocoded location 
                    map.graphics.add(graphic);
                    //add a text symbol to the map listing the location of the matched address.
                    var displayText = candidate.Street;
                    var font = new esri.symbol.Font("16pt", esri.symbol.Font.STYLE_NORMAL, esri.symbol.Font.VARIANT_NORMAL, esri.symbol.Font.WEIGHT_BOLD, "Helvetica");

                    var textSymbol = new esri.symbol.TextSymbol(displayText, font, new dojo.Color("#666633"));
                    textSymbol.setOffset(0, 8);
                    map.graphics.add(new esri.Graphic(geom, textSymbol));
                    return false; //break out of loop after one candidate with score greater  than 80 is found.
                }
            });
            if (geom !== undefined) {
                map.centerAndZoom(geom, 12);
            }

        }


Thank you all very much for your time and help.  I read the reference info on the InfoTemplate object but it wasn't any help.

Attachments

Outcomes