TextSymbol Bombs

2234
4
Jump to solution
01-29-2016 12:46 PM
AllenHoward
New Contributor II

Hello.

Sadly the developer who started this project has quit, and I am desperately trying to get up to speed.

All I want is something simple. Should be one of the most common functions in mapping - to add text inside a graphic as shown. (The map is generated, i put the number in there using paint for purposes of this post)

But as soon as I define a textsymbol, the program bombs. I don't even have to do anything with it, just the var declaration kills it. (See near the bottom of the code)

I have "required"  esri/symbols/TextSymbol among others at the top of the script file.

The idea is to place the contents of the HCAD_NUM field from the shapefile near the middle of each plot. But I can't even get it to show a hard-coded "Hello world" anywhere on the screen.

Any help would be greatly appreciated.

Map1.png

require([

  "esri/map",

  "esri/layers/ArcGISDynamicMapServiceLayer",

  "esri/tasks/QueryTask",

  "esri/tasks/query",

  "dojo/dom",

  "dojo/on",

  "esri/layers/FeatureLayer",

  "esri/Color",

  "esri/symbols/SimpleLineSymbol",

  "esri/symbols/SimpleFillSymbol",

  "esri/renderers/SimpleRenderer",

  "esri/geometry/Extent",

  "dojo/parser",

  "esri/geometry/Circle",

"esri/units",

  "esri/symbols/TextSymbol",

  "esri/layers/LabelClass",

        "esri/config",

      "esri/graphic",

      "esri/tasks/GeometryService",

      "esri/tasks/BufferParameters",

      "esri/toolbars/draw",

      "esri/symbols/SimpleMarkerSymbol",

      "esri/symbols/Font",

  "dojo/domReady!"],

  function (Map, ArcGISDynamicMapServiceLayer, QueryTask,

  Query, dom, on, FeatureLayer, Color, SimpleLineSymbol, SimpleFillSymbol, SimpleRenderer, Extent, parser, Circle, Units)

  {

    parser.parse();

    //map = new Map("map");

    map = new Map("map", {

        //extent: bbox,

        showLabels: true //very important that this must be set to true!  

    });

    var baseLayer = new ArcGISDynamicMapServiceLayer("https://arcgis-ctngis-1263207624.us-west-2.elb.amazonaws.com/arcgis/rest/services/HCAD/CADDataAndPar...");

    map.addLayer(baseLayer);

    var countyLayer = new FeatureLayer("https://arcgis-ctngis-1263207624.us-west-2.elb.amazonaws.com/arcgis/rest/services/HCAD/CADDataAndPar...");

    var outline = new SimpleLineSymbol("solid", new Color([255, 255, 255, 1]), 2);

    var fill = new SimpleFillSymbol("solid", outline, new Color([255, 255, 0, 0.5]));

    countyLayer.setRenderer(new SimpleRenderer(fill));

    map.addLayer(countyLayer);

     //Query the parcels layer for the subject property

    queryTask = new QueryTask("https://arcgis-ctngis-1263207624.us-west-2.elb.amazonaws.com/arcgis/rest/services/HCAD/CADDataAndPar...");

    query = new Query();

    query.returnGeometry = true;

    query.outFields = ["HCAD_NUM", "LocAddr"];

    //Set up a callback for when the get details button is pressed.

    function execute()

    {

      query.where = "HCAD_NUM = '" + dom.byId("hcad_num").value + "'";

      queryTask.execute(query, foundSubject);

    }

    on(dom.byId("execute"), "click", execute);

    //Set up a query for

    function foundSubject(results)

    {

        var f = results.features;

        circle = new Circle({center: f[0].geometry.getExtent().getCenter(), radius: dom.byId("distance").value, radiusUnit: Units.FEET});

        //Execute a new query that searches for all properties around subject

        var areaQuery = new Query();

        areaQuery.geometry = circle.getExtent();

        areaQuery.returnGeometry = true;

        areaQuery.outFields = ["HCAD_NUM", "LocAddr"];

        queryTask.execute(areaQuery, showResults);

    }

    function showResults(results)

    {

      var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID,

      new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,

      new Color([0, 0, 0]), 1.0), new Color([255, 255, 255, 1])

      );

      var textSymbol = new TextSymbol("Hello, World");

      map.graphics.clear();

      var resultFeatures = results.features;

      map.graphics.clear();

      var resultFeatures = results.features;

        //Zoom to parcel

      var ex = esri.graphicsExtent(resultFeatures);

      map.setExtent(ex);

      for (var i = 0, il = resultFeatures.length; i < il; i++) {

          var graphic = resultFeatures;

          graphic.setSymbol(symbol);

          map.graphics.add(graphic);

          var point = graphic.center;

          var featureAttributes = graphic.attributes;

          var resultItems = [];

          for (var attr in featureAttributes) {

              resultItems.push("<b>" + attr + ":</b>  " + featureAttributes[attr] + "<br>");

          }

          resultItems.push("<br>");      

      }

     

      dom.byId("info").innerHTML = resultItems.join("");

    }

});

0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus

Allen,

  You have added the require portion but each require need a accomplaying var:

function (Map, ArcGISDynamicMapServiceLayer, QueryTask,
  Query, dom, on, FeatureLayer, Color, SimpleLineSymbol, SimpleFillSymbol, SimpleRenderer, Extent, parser, 
  Circle, Units, TextSymbol, LabelClass)

View solution in original post

4 Replies
RobertScheitlin__GISP
MVP Emeritus

Allen,

  You have added the require portion but each require need a accomplaying var:

function (Map, ArcGISDynamicMapServiceLayer, QueryTask,
  Query, dom, on, FeatureLayer, Color, SimpleLineSymbol, SimpleFillSymbol, SimpleRenderer, Extent, parser, 
  Circle, Units, TextSymbol, LabelClass)
TracySchloss
Frequent Contributor

To elaborate on Robert's reply, make sure they are in the same order!  This is a common mistake for new users.

When I was first learning, I put each variable on their own line to check that I had every one matched up.  It was easier for me to see where I'd missed one, or got it out of order.  You can always edit it back to one long line later.

AllenHoward
New Contributor II

Thank you! 🙂

0 Kudos
AllenHoward
New Contributor II

Thank you! 🙂

0 Kudos