How to Connect Data to a Map

4218
25
Jump to solution
02-09-2017 09:31 AM
WilliamMiller4
Occasional Contributor II

Hi,

I have a map service that holds a non-geographic table from a non-ArcGIS database. I need to connect that data to the map, so the properties can be highlighted, etc. There are fields in the table that match data in the map, such as account_number. How do I match the two so I can get each properties' coordinates or am I going about this wrong?

William

0 Kudos
25 Replies
RobertScheitlin__GISP
MVP Emeritus

William,

  What is the value that is returned by line 9?

console.log(symbolColor);

The only reason you use

new Color([x]) 

is when x is the three rgb numbers.

So your issue might be 

new Color(symbolColor)
0 Kudos
WilliamMiller4
Occasional Contributor II

Hi Robert,

The value of console.log(symbolColor) varies by accountNum, but some examples are in the screenshot below.

console.log readout of rgb values

William

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

William,

   I have seen this before. I think you have to use

Color.fromArray(symbolColor);‍‍‍
0 Kudos
WilliamMiller4
Occasional Contributor II

Hi Robert,

I added the following line

var color = new Color.fromArray(symbolColor);

and changed

var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([symbolColor]), 2), new Color([symbolColor,0.25]));

to

var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, color, 2), color);

The graphics still look black, but now it looks like all the console.info lines are showing a: 1, b: 5, g:5 , r: 2 for the color values. I think it has something to do with the deferred, because all the console.log(symbolColor) from line 9 display in the console and then all the console.info(symbol) from line 22. Also, there is the reference error about graphic not being defined when line 33 is uncommented.

William

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

William,

Try this then:

var color = Color.fromRgb("rgb(" + symbolColor + ")");
WilliamMiller4
Occasional Contributor II

Hi Robert,
I used your code and it worked, sort of. It seems the color value of the last parcel is applied to all the parcels.

William

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

William,

  That make sense the way your code is setup. Basically you are in a for loop and in that for loop you set the symbolColor var but you also call a queryTask which is a deferred meaning it takes time so by the time that deferred is done your loop is already complete and the symbolColor value is the last parcel in the loop.

0 Kudos
WilliamMiller4
Occasional Contributor II

Hi Robert,
How do I force the code to wait for the deferred to resolve? On the QueryTask's API page, under Event Details, I see complete (onComplete) that looks promising, but I can't find an example of it used in code.

William

0 Kudos
RobertScheitlin__GISP
MVP Emeritus

William,

   Your QueryTask callback is already using onComplete (basically).

What you need to do is make sure the callback function has the current symbolColor by passing it to the callback function:

    queryTask.execute(query, lang.hitch(this, this.onQueryResult, symbolColor), 
      lang.hitch(this, function(error){
        def.resolve({state: 'failure', value: error});
    }));‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

onQueryResult:  function(symbolColor, results) {
  var features = results.features;
  for(var i = 0, len = features.length; i < len; i++){
    var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([255,0,0]), 2), new Color([255,255,0,0.25]));
    //var symbol = new SimpleFillSymbol(SimpleFillSymbol.STYLE_SOLID, new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID, new Color([symbolColor]), 2), new Color([symbolColor,0.25]));
    console.info(symbol);
    var graphic = features[i];
    graphic.setSymbol(symbol);
    this.map.graphics.add(graphic);
  }
  def.resolve({state: 'success', value: results});
},‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
WilliamMiller4
Occasional Contributor II

Hi Robert,

In your code above, should def (line 16) be passed to onQueryResult also?

William

0 Kudos