Heat Map on ArcGIS Viewer for Flex

7520
64
03-07-2011 12:04 PM
MESHALALMASHAN
New Contributor
Hi,

   I'm trying to implement a heat map on my ArcGIS viewer using the code posted on the following link:

http://thunderhead.esri.com/readonlyurl/HeatMapNew/srcview/


But still I'm not getting anything running yet as I'm not sure if it's compatible with the Viewer for Flex or not.

Any idea?
Tags (2)
0 Kudos
64 Replies
LloydHeberlie
Occasional Contributor
I tried updating my application, but got 2 errors:
  <esri_stl:ArcGISHeatMapLayer id="heatMapLayer" url="{m_url}"
One for the heatmaptest and the other for the heatmaptime test mxml

Can anyone help?
Thanks.


I'm not sure what you are doing? Are you compiling the widget from the source code I posted?  The HeatMapTest.mxml and HeatMapTimeTest.mxml are just sample applications that illustrate the functionality of the ArcGISHeatMapLayer.as class.  They are not used in the widget.

When you are using the source code, unless you are compiling your own library project with your namespace (which is what I use and a little more complex than can be explained here); you just need to reference the location where you placed the source code.

You'll need to refactor the source code specifically you'll get errors for the package name (com.esri.stl.ags and any subpackages) as well as the namespace ( xmlns:esri_stl="http://www.esri.com/2010/stl") that I used when compiling the library project.  If you put the source code into a package name com.mycustomsourcecode then in your app would look like this below. 
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
      xmlns:s="library://ns.adobe.com/flex/spark" 
      xmlns:mx="library://ns.adobe.com/flex/mx" 
      minWidth="955" minHeight="600" 
      xmlns:esri="http://www.esri.com/2008/ags" 
      xmlns:my_custom_sourcecode="com.mycustomsourcecode"
      backgroundColor="0x8080C0">
 <esri:Map id="map" wrapAround180="true" >
  <esri:ArcGISTiledMapServiceLayer url="{YourBasemapURL}" visible="true"/>
  <my_custom_sourcecode:ArcGISHeatMapLayer id="heatMapLayer" url="{YourHeatmapURL}" useAMF="true" outFields="
  • " alpha="0.7"/>
  • </esri:Map> </s:Application>



    Hope this helps.

    Lloyd
    0 Kudos
    LloydHeberlie
    Occasional Contributor
    Works great.

    Question about the heat map time line function.

    The residual data does not leave the map as the slider is progressed through the date range.

    eg, I have 10 various xy points for 1980, then another various 10 points for 1981, but as I move the slider from 1980 to 1981 I no longer have 10 points only I have a cumulative 20 points and thus the heat spot increases. Is this by design? or can it be changed to only reflect the data as requested by the given date range of the slider request.

    Cheers

    Mick.


    It was simply a design decision, there is a property on the TimeSlider named thumbCount.  You can see how it works in this sample Time Slider with 2 thumbs.  Unfortunately you would need to recompile the widget in order to make this change, maybe it is something I can do in the next version (whenever that would be) through the configuration file.

    Lloyd
    0 Kudos
    MichaelHarvey
    New Contributor
    It was simply a design decision, there is a property on the TimeSlider named thumbCount.  You can see how it works in this sample Time Slider with 2 thumbs.  Unfortunately you would need to recompile the widget in order to make this change, maybe it is something I can do in the next version (whenever that would be) through the configuration file.

    Lloyd


    If you ever do, be sure to post it, that function would be great.
    0 Kudos
    MattiasEkström
    Occasional Contributor III
    Lloyd, great widget! thanks for sharing it.
    I managed to implement the source code in to my project, haven't made any customizations yet. Right now I just wanted to try it out, but for later projects I might want to use another data source than a mapservice from ArcGIS Server, lets say I get some point data somehow and put them into a graphiclayer for example. How much rewriting of the source code would I have to do to use that as an input instead? I haven't look at the code much yet but I'm guessing it will be really tricky for someone with limited knowledge of flex/actionscript.
    /Mattias
    0 Kudos
    LloydHeberlie
    Occasional Contributor
    Lloyd, great widget! thanks for sharing it.
    I managed to implement the source code in to my project, haven't made any customizations yet. Right now I just wanted to try it out, but for later projects I might want to use another data source than a mapservice from ArcGIS Server, lets say I get some point data somehow and put them into a graphiclayer for example. How much rewriting of the source code would I have to do to use that as an input instead? I haven't look at the code much yet but I'm guessing it will be really tricky for someone with limited knowledge of flex/actionscript.
    /Mattias


    Hey Mattias,

    You should be able to use the HeatMapLayer class and version 1 of the widget to get you started.  You will need to modify the code to do what need, but it is pretty straightforward (assuming your are comfortable doing some coding [ActionScript+MXML]).  Take a look at the function named heatmap_QueryTask_executeCompleteHandler in HeatMapWidget.mxml, you can find this in the download under HeatMapWidgetCode\v1\HeatMapWidget\src\HeatMap.

    What you are wanting to accomplish by using a non-ArcGIS Server datasource is pretty easy to do with version 1 of the widget included in the download.  Here's how it works.  You'll need to fetch your points from some datasource, web service, etc.  You'll need to make sure that your points are in the same projection as the map you are using.  Create a new instance of the HeatMapLayer (also included in the source [version 1]). You then create an Array of HeatMapPoints where each item in the array is a HeatMapPoint.  Then set the HeatMapLayer.dataProvider = heatMapPointsArr;

    So, what I'm telling you is that there are two classes.  HeatMapLayer was the original class used in version 1 of the widget, it was more generic and not deeply integrated with an ArcGIS Server service.  This was the original source code that Mansour provided on his blog.  ArcGISHeatMapLayer is the version 2 class that I created that still uses the same source code from Mansour to generate the heatmap, but is deeply integrated with an ArcGIS Server service (TimeAware, Dynamic query functionality, etc).

    Good Luck,

    Lloyd
    0 Kudos
    CarlAlexander
    New Contributor III
    Is there a way to use equal(=)and not &gt(>), and is there a way to use a field that is string and not an interger or double?  Thanks.
    0 Kudos
    LloydHeberlie
    Occasional Contributor
    Is there a way to use equal(=)and not &gt(>), and is there a way to use a field that is string and not an integer or double?  Thanks.


    You sure can.
    <querytemplate>FIELD_NAME = 'REPLACE_STR'</querytemplate>
    <types>VAL1,VAL2,VAL3,VAL4</types>
    <type_descs>Name = 1,Name = 2,Name = 3,Name = 4</type_descs>
    


    The type_descs are what show up as the label in the dropdown list, and the types are the values associated with the label.  When you select one of the options from the list the query template takes the text REPLACE_STR and replaces it with the value you selected from the option list.

    For example: if you selected "Name = 1" from the dropdown, then the query executed would be FIELD_NAME = 'VAL1'.

    Hope this helps.

    Lloyd
    0 Kudos
    OscarCastaneda1
    New Contributor
    This widget is Excellent!, unfortunately I haven't been able to make it work with table-based dynamic (Event) map services; when running the widget I get the right number of records from the database but all of them are clustered in the (0,0) coordinates (My data is all in WGS84); however if in the MXD I export the temporary event layer to a feature class and then republish my service, it works perfectly. My operational layers are dynamic by nature so I can't afford the task of being regularly saving to feature classes. I was wondering if there is any workaround for this?
    Much appreciated.
    Oscar
    0 Kudos
    LloydHeberlie
    Occasional Contributor
    This widget is Excellent!, unfortunately I haven't been able to make it work with table-based dynamic (Event) map services; when running the widget I get the right number of records from the database but all of them are clustered in the (0,0) coordinates (My data is all in WGS84); however if in the MXD I export the temporary event layer to a feature class and then republish my service, it works perfectly. My operational layers are dynamic by nature so I can't afford the task of being regularly saving to feature classes. I was wondering if there is any workaround for this?  
    Much appreciated.  
    Oscar


    Hey Oscar,

    I tested this using an Event based layer through ArcGIS Server, and it works. I've attached a document with some info on this. FYI, you WILL NOT get the best performance publishing this way; but it does work. It also most likely only works with mxd based services [that is what I tested], not optimized (msd) based services. Since it is not optimized it is likely that you might not be able to publish event layers as services in the future, but I don't know that for sure.

    Good Luck,

    Lloyd

    I don't know all of the details of your workflow, but here are some other possible suggestions:

    • You could use the Feature Service in ArcGIS Server to keep your featureclass updated dynamically. Send all your edits through the feature service, and use the feature service as input to the HeatMap widget.

    • You might possibly be able to use the capabilities of using a QueryLayer to support the dynamic nature of your data, and serve that QueryLayer through a map service in ArcGIS Server.

    0 Kudos
    OscarCastaneda1
    New Contributor
    Hey Oscar, 

    I tested this using an Event based layer through ArcGIS Server, and it works. I've attached a   document with some info on this. FYI, you   WILL NOT get the best performance publishing this way; but it does work. It also most likely only works with mxd based services [that is what I tested], not optimized (msd) based services. Since it is not optimized it is likely that you might not be able to publish event layers as services in the future, but I don't know that for sure. 

    Good Luck, 

    Lloyd 

    I don't know all of the details of your workflow, but here are some other possible suggestions: 
       
       
    • You could use the Feature Service in ArcGIS Server to keep your featureclass updated dynamically. Send all your edits through the feature service, and use the feature service as input to the HeatMap widget.
    •  
       
    • You might possibly be able to use the capabilities of using a QueryLayer to support the dynamic nature of your data, and serve that QueryLayer through a map service in ArcGIS Server.
    •  


    Thank you Lloyd for your response and taking the time to come up with all related documentation. It's got to be something in my environment because after trying the MXD you provided I'm getting the same results (all points clustered at 0,0). I do agree with you I'm better off if I change my workflow (and using a QueryLayer may be the way to go).
    Again, I really appreciate your help at this respect.
    Oscar
    0 Kudos