<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Make layer re-render? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/make-layer-re-render/m-p/99405#M9095</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure if this is the most prudent way to go about this, so feel free to critique my code structure as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Okay, long story short, I have about a&amp;nbsp;feature service that has tens of thousands of features. I only want the features contained within the current camera extent to be displayed, so:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I've created a feature layer from the REST service URL. I call this the 'internal' feature layer.&lt;/LI&gt;&lt;LI&gt;I've also created a corresponding 'wrapper' layer which 'wraps' around the internal feature layer.&lt;/LI&gt;&lt;LI&gt;This wrapper layer is what will be displayed on the map, and it's source will be set to the result of a query executed on the feature layer. It's sort of like the internal layer is a database table, and the wrapper layer is a view of that table.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So anytime the camera changes, I tell the wrapper layer to execute a query on its internal layer based on the current extent of the view. So far, so good. This all works in the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the problem: The features aren't drawing. I've printed the JSON of the wrapper layer to the console, so I know that the source of the wrapper layer has been set to the result of the query correctly, but...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The features don't have symbols. 'symbol: null'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The internal layer has a Unique Value renderer that was built from the REST service, and when I create the wrapper layer I pass this&amp;nbsp;render to&amp;nbsp;the&amp;nbsp;wrapper layers. I know that this renderer is present in the wrapper layer at the time of the query.&lt;/P&gt;&lt;P&gt;I can't figure out why the wrapper layer is not using it's renderer to generate symbols for the features, so I'm wondering if there is a function call that I need to make in order to make the layer redraw itself and use its renderer to generate the proper symbols.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any thoughts or wisdom is appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 28 Oct 2017 20:11:14 GMT</pubDate>
    <dc:creator>TristanSebens</dc:creator>
    <dc:date>2017-10-28T20:11:14Z</dc:date>
    <item>
      <title>Make layer re-render?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/make-layer-re-render/m-p/99405#M9095</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure if this is the most prudent way to go about this, so feel free to critique my code structure as well.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Okay, long story short, I have about a&amp;nbsp;feature service that has tens of thousands of features. I only want the features contained within the current camera extent to be displayed, so:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I've created a feature layer from the REST service URL. I call this the 'internal' feature layer.&lt;/LI&gt;&lt;LI&gt;I've also created a corresponding 'wrapper' layer which 'wraps' around the internal feature layer.&lt;/LI&gt;&lt;LI&gt;This wrapper layer is what will be displayed on the map, and it's source will be set to the result of a query executed on the feature layer. It's sort of like the internal layer is a database table, and the wrapper layer is a view of that table.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So anytime the camera changes, I tell the wrapper layer to execute a query on its internal layer based on the current extent of the view. So far, so good. This all works in the code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's the problem: The features aren't drawing. I've printed the JSON of the wrapper layer to the console, so I know that the source of the wrapper layer has been set to the result of the query correctly, but...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The features don't have symbols. 'symbol: null'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The internal layer has a Unique Value renderer that was built from the REST service, and when I create the wrapper layer I pass this&amp;nbsp;render to&amp;nbsp;the&amp;nbsp;wrapper layers. I know that this renderer is present in the wrapper layer at the time of the query.&lt;/P&gt;&lt;P&gt;I can't figure out why the wrapper layer is not using it's renderer to generate symbols for the features, so I'm wondering if there is a function call that I need to make in order to make the layer redraw itself and use its renderer to generate the proper symbols.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any thoughts or wisdom is appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 28 Oct 2017 20:11:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/make-layer-re-render/m-p/99405#M9095</guid>
      <dc:creator>TristanSebens</dc:creator>
      <dc:date>2017-10-28T20:11:14Z</dc:date>
    </item>
    <item>
      <title>Re: Make layer re-render?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/make-layer-re-render/m-p/99406#M9096</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tristan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;Can you provide a sample of this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Oct 2017 20:46:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/make-layer-re-render/m-p/99406#M9096</guid>
      <dc:creator>RobertScheitlin__GISP</dc:creator>
      <dc:date>2017-10-29T20:46:15Z</dc:date>
    </item>
    <item>
      <title>Re: Make layer re-render?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/make-layer-re-render/m-p/99407#M9097</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Of course! I've attached the full source code to the initial post for reference, but here are the relevant lines:&lt;/P&gt;&lt;P&gt;- This is the function with which I create the wrapper layers, using the inner layers. In this function the inner layers have already been loaded.&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&amp;nbsp;// Returns a layer promise which has all of the important characteristics of the passed layer, and which carries a reference to the original layer in the property 'subordinate'&lt;BR /&gt; function createWrapperLayer( featLayer ){&lt;BR /&gt;&amp;nbsp; console.log( 'Creating wrapper layer for ', featLayer.title ); &lt;BR /&gt;&amp;nbsp; // Grab the features in the featLayer which are visible to the initial extent of the view. Assign those as the source.&lt;BR /&gt;&amp;nbsp; // Wait for the results of the query to return, then pass it into the next function to be used as the resultant layer's source.&lt;BR /&gt;&amp;nbsp; // Here we read out all of the important information from the original layer&lt;BR /&gt;&amp;nbsp; var subTitle = featLayer.title;&lt;BR /&gt;&amp;nbsp; var subID = featLayer.id;&lt;BR /&gt;&amp;nbsp; var subFields = featLayer.fields;&lt;BR /&gt;&amp;nbsp; var subObjID = featLayer.objectIdField;&lt;BR /&gt;&amp;nbsp; var subSpRef = featLayer.spatialReference;&lt;BR /&gt;&amp;nbsp; var subGeoType = featLayer.geometryType;&lt;BR /&gt;&amp;nbsp; var subRender = featLayer.renderer;&lt;BR /&gt;&amp;nbsp; // We have to wait for the query to finish execution to create the wrapper layer&lt;BR /&gt;&amp;nbsp; visibleFeats.then( &lt;BR /&gt;&amp;nbsp; &amp;nbsp; function(visibleFeats) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; // Now we create the actual layer&lt;BR /&gt;&amp;nbsp; &amp;nbsp; visiLayer = new FeatureLayer({&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; title: subTitle,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; id: subID,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; objectIdField: subObjID,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; source: findFeaturesInCameraExtent( featLayer ), // In order to execute this function, featLayers must already be loaded.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; fields: subFields,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; visible: true,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; spatialReference: subSpRef,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; geometryType: subGeoType,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; renderer: subRender&lt;BR /&gt;&amp;nbsp; &amp;nbsp; });&lt;BR /&gt;&amp;nbsp; &amp;nbsp; // Here we add a prototype attribute 'subordinate' to the visiLayer so that we can access the feature layer again later&lt;BR /&gt;&amp;nbsp; &amp;nbsp; visiLayer.subordinate = featLayer;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; // And return it&lt;BR /&gt;&amp;nbsp; &amp;nbsp; visiLayer.then(&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; function( vLayer ) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log( vLayer );&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; );&lt;BR /&gt;&amp;nbsp; &amp;nbsp; visiLayer.load();&lt;BR /&gt;&amp;nbsp; &amp;nbsp; map.add( visiLayer );&lt;BR /&gt;&amp;nbsp; &amp;nbsp; });&lt;BR /&gt; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;- This is the function which initiates the querying of the inner layers, and sets the source of the wrapper layer to the query's result(s)&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;// This is the function that will be called each time the camera changes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;// It&amp;nbsp;&lt;/P&gt;&lt;P&gt;function updateVisibleFeatures() {&lt;BR /&gt;&amp;nbsp; map.layers.forEach(function(layer) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if ( layer.visible == true &amp;amp;&amp;amp; layer.id != layerBounds.id ) { // Cycle through every layer except for the bounds&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// layer.subordinate is a reference to the internal layer that the wrapper layer is wrapped around&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; // it is the layer that is built from the REST service, and contains all available features.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; visibleFeats = findFeaturesInCameraExtent( layer.subordinate );&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; visibleFeats.then( &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; function( visibleFeats ) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; layer.source = visibleFeats.features;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log( layer );&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; },&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; // Function that is called in case the promise fails&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; function( reason ) {&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; console.log( 'Updating visible features failed: ', reason );&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; });&lt;BR /&gt;&amp;nbsp; &amp;nbsp; }&lt;BR /&gt;&amp;nbsp; });&lt;BR /&gt; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;And this is the subroutine that actually executes the query&lt;/SPAN&gt;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6;"&gt;// Function which, given a layer, will return the features of that layer that are contained within the camera extent.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;// Function returns a promise, and the resultant featureSet should be accessed with the '.then()' function&lt;BR /&gt; function findFeaturesInCameraExtent( layer ) {&lt;BR /&gt;&amp;nbsp; var query = layer.createQuery(); //&amp;nbsp;Create a blank query&lt;BR /&gt;&amp;nbsp; query.geometry = view.extent&lt;BR /&gt;&amp;nbsp; query.spatialRelationship = "contains";&lt;BR /&gt;&amp;nbsp; var results = layer.queryFeatures( query ) // Apply the spatial query to the layer, return a promise of the result&lt;BR /&gt;&amp;nbsp; // Returns a promise which, once resolved, will contain all of the features returned by the query&lt;BR /&gt;&amp;nbsp; return results;&lt;BR /&gt; }&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 29 Oct 2017 21:05:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/make-layer-re-render/m-p/99407#M9097</guid>
      <dc:creator>TristanSebens</dc:creator>
      <dc:date>2017-10-29T21:05:51Z</dc:date>
    </item>
  </channel>
</rss>

