AnsweredAssumed Answered

TextSymbol Location

Question asked by commtax on Feb 4, 2016
Latest reply on Feb 8, 2016 by rscheitlin

Please forgive me for what is probably a totally newbie question, but the programmer who started this project left and I am really under the gun. I have looked at every sample I could find, and have searched the forum to no avail.

We are able to pull up all of the properties within a (user-defined) radius of the center of our subject property.

What I need to do is to place  text near the center of each of the properties that fall within the radius. (HCAD_NUM, Site Address, etc. from the ShapeFile)

I see how to get the extents for the map, but how to  determine the location and size of the individual plots escapes me.

I would also like to determine the width of the individual plots so I can adjust the fonts size and, perhaps text rotation so the text doesn't leak over onto other properties. (Desired Text is shown in red)

My failed attempt to add text is at the very bottom.

 

Map2.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/Font",
  "esri/symbols/TextSymbol",
  "esri/layers/LabelClass",
      "esri/config",
      "esri/graphic",
      "esri/tasks/GeometryService",
      "esri/tasks/BufferParameters",
      "esri/toolbars/draw",
      "esri/symbols/SimpleMarkerSymbol",


  "dojo/domReady!"],

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

    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/CADDataAndParcels/MapServer");
    map.addLayer(baseLayer);

    var countyLayer = new FeatureLayer("https://arcgis-ctngis-1263207624.us-west-2.elb.amazonaws.com/arcgis/rest/services/HCAD/CADDataAndParcels/MapServer/0");
    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/CADDataAndParcels/MapServer/1");
    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;
        //new Circle(center, options?) https://developers.arcgis.com/javascript/jsapi/circle-amd.html
        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([180, 180, 180, 1])
      );

      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[i];

          graphic.setSymbol(symbol);

          var featureAttributes = graphic.attributes;
          var resultItems = [];
          for (var attr in featureAttributes) {
              resultItems.push("<b>" + attr + ":</b>  " + featureAttributes[attr] + "<br>");
          }
          resultItems.push("<br>");       


          map.graphics.add(graphic);

          var textSymbol = new TextSymbol(featureAttributes[attr]);

          map.graphics.add(textSymbol);

      }

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

Outcomes