Select to view content in your preferred language

Symbol with text

1343
4
05-15-2012 06:45 AM
BorjaSancho
Emerging Contributor
Hi all,

i'm trying to create, for example, a square with text inside to add to the graphics layer. Something similar to this example http://help.arcgis.com/en/webapi/javascript/arcgis/demos/locator/locator_address.html but with the text inside. It's posible??

Thanks to all!
0 Kudos
4 Replies
ShreyasVakil
Frequent Contributor
i don't think we have something to add text inside the square as a graphic. Although, we do have a TextSymbol which you can add to the map as graphic. What you can do is add two graphics one with TextSymbol and one with a square symbol to look like text within a square. There may be other ways too, but this is what I would start with.
0 Kudos
Hans-JürgenWeber
Emerging Contributor
I have a graphic and a text inside the graphic:

...
var SVfeatureCollection = {layerDefinition: layerDefinition, featureSet: null};  
var SVpointsLayer = new esri.layers.FeatureLayer(SVfeatureCollection, {mode: esri.layers.FeatureLayer.MODE_SNAPSHOT});
map.addLayer(SVpointsLayer);
var SVpointsInfoTemplate = new esri.InfoTemplate("<div class='a'><b>${name}</b></div>", "<div class='a'>${text}</div>");
var font = new esri.symbol.Font("8pt", esri.symbol.Font.STYLE_NORMAL, esri.symbol.Font.VARIANT_NORMAL, esri.symbol.Font.WEIGHT_NORMAL, "Arial");
dojo.forEach(SVpointFeatures, function (feature) {
  feature.geometry = esri.geometry.geographicToWebMercator(feature.geometry);
  var textSymbol = new esri.symbol.TextSymbol(feature.attributes.init, font, new dojo.Color("#000000"));
  textSymbol.setOffset(0, -2);
  feature.symbol=new esri.symbol.PictureMarkerSymbol('pictures/flag.png', 22, 20);
  SVpointsLayer.add(feature.setInfoTemplate(SVpointsInfoTemplate));
  SVpointsLayer.add(new esri.Graphic(feature.geometry, textSymbol));
});
SVpointsLayer.show();
...


The points layer is a feature layer with an info window.
I can't open the info window when I click inside the graphic where the text is.
Only when I click the areas where no text is I can open the info window.
What can I do?
0 Kudos
JenniferGaa
Occasional Contributor
I did something similar with my feature layer.  I created a new point for the TextSymbol and pushed that to an array of labels to be added on the map's graphics layer:

            var labels = [];

...

            var labelGeom = new esri.geometry.Point(eval(x + 0.00015), eval(y + 0.00007), map.spatialReference);
            var font = new esri.symbol.Font("12px", esri.symbol.Font.STYLE_NORMAL, esri.symbol.Font.VARIANT_NORMAL, esri.symbol.Font.WEIGHT_BOLD, "Arial");
            var textSymbol = new esri.symbol.TextSymbol(
                label,
                font, new dojo.Color([0, 0, 0])
            );

            var labelGraphic = new esri.Graphic(labelGeom);
            labelGraphic.setSymbol(textSymbol);
            labels.push(labelGraphic);

...

        for (var n = 0, nl = labels.length; n < nl; n++) {
            map.graphics.add(labels);
        }

I also used a boolean in a config file to make it easy to turn labels off, as well as tracked the current scale to only show labels below a specific scale.
0 Kudos
Hans-JürgenWeber
Emerging Contributor
Ok, thanks, I did it your way, but the effect is the same:
I can't click inside the symbol where the text is to open the info window.
Only in areas where no text is I can click to open the info window.
How can I fix this?
0 Kudos