AnsweredAssumed Answered

Label graphics added to graphics layer not displaying

Question asked by keng@cdta.org on Mar 16, 2017
Latest reply on Mar 17, 2017 by keng@cdta.org

I have some code that will geocode a point and display it on the map.  I would like to label the point with the address.

I create a label graphic using the coordinates of the point and the address, add graphic to the graphics layer, but it does not display on the map.

Not sure what I am missing.  

 

Here is the section of code:

               fromlocator.on("location-to-address-complete", function(evt) {
                    //mapMain.graphics.remove(fGraphic);
                    var attr;
                    if (evt.address.address) {
                    var fromAddress = evt.address.address;
                    alert(fromAddress.Address + ", " + fromAddress.City + ", " + fromAddress.Region, ", " + fromAddress.Postal);
                         if (fromAddress){
                              document.getElementById("fromAddr").value = fromAddress.Address + ", " + fromAddress.City + ", " + fromAddress.Region, ", " + fromAddress.Postal;
                              fPoint = new Point(evt.address.location, new SpatialReference({ wkid: 4326 }));
                              attr = {
                                   "Address": fromAddress
                              };
                              
                              //Create point graphic from geocoded point, add to graphiclayer, add layer to map.
                              fGraphic = new Graphic(fPoint, fromGeocodeSymbol, attr);
                              graphicsLayer = new GraphicsLayer();
                              graphicsLayer.add(fGraphic);
                              mapMain.addLayer(graphicsLayer);
                              
                              // create a text symbol to define the style of labels
                              var textColor = new Color("#666");
                              var textLabel = new TextSymbol(fromAddress)
                              textLabel.setColor(textColor);
                              textLabel.font.setSize("14pt");
                              textLabel.font.setFamily("arial");
                              textLabelRenderer = new SimpleRenderer(textLabel);               
                              
                              //create label to add to graphic layer
                              var testlabel = new Graphic(fPoint, textLabel)
                              
                              //add label to graphics layer
                              mapMain.graphics.add(testlabel);
                              
                              zoomToAddresses();                    
                              getZone(fPoint, "from");           
                         }
                    }
               });

Outcomes