Hi all. I'm having some issues with a web map and web app that I am building through my organization's ArcGIS Online portal.
I have a web map with multiple layers and I have configured some of the popups for different layers with attribute expressions. The code I'm using looks like this:
<SPAN class="comment token">// Convert Lines/Polygons to Points</SPAN>
<SPAN class="keyword token">var</SPAN> PointGeometry <SPAN class="operator token">=</SPAN> <SPAN class="token function">Centroid</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Geometry</SPAN><SPAN class="punctuation token">(</SPAN>$feature<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> pointX <SPAN class="operator token">=</SPAN> PointGeometry<SPAN class="punctuation token">.</SPAN>x<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> pointY <SPAN class="operator token">=</SPAN> PointGeometry<SPAN class="punctuation token">.</SPAN>y<SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token function">text</SPAN><SPAN class="punctuation token">(</SPAN>pointX<SPAN class="punctuation token">)</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">":"</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="token function">text</SPAN><SPAN class="punctuation token">(</SPAN>pointY<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
The popup works fine but when I try to view the attribute table for this layer in the web app no records ever load. In Chrome's console I am getting the error "Error: Runtime Error: Cannot call member method on null."
Changing the code to:
<SPAN class="comment token">// Convert Lines/Polygons to Points</SPAN>
<SPAN class="keyword token">var</SPAN> PointGeometry <SPAN class="operator token">=</SPAN> <SPAN class="token function">Centroid</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">Geometry</SPAN><SPAN class="punctuation token">(</SPAN>$feature<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">return</SPAN> <SPAN class="punctuation token">(</SPAN><SPAN class="token function">text</SPAN><SPAN class="punctuation token">(</SPAN>PointGeometry<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
actually resolves the issue. Obviously this is not ideal since it is much harder for users to read. It seems like accessing the attributes of the geometry is causing the issue.
Any ideas why this is happening?