<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" 
    xmlns:ns1="com.anychart.*"
    initialize="initializeHandler()" viewSourceURL="srcview/index.html">
    
    <mx:Script>
        <![CDATA[
            import dlgs.CitiesSelector;
            import yahooWeather.yahooWeatherAdapter.WeatherInformation;
            import mx.managers.PopUpManager;
            
            public function removeWeatherInformation(weatherInfo:WeatherInformation):void {
                if (anychartXML..styles[0].marker_style.(@name=="yw_"+weatherInfo.city)[0] != null)
                    delete anychartXML..styles[0].marker_style.(@name=="yw_"+weatherInfo.city)[0];
                var series:XML = anychartXML..series.(@name=="cities")[0];
                if (series.point.(@name==weatherInfo.city)[0] != null)
                    delete series.point.(@name==weatherInfo.city)[0];
                    
                map1.anychartXML = anychartXML;
            }
            
            public function addWeatherInformation(weatherInfo:WeatherInformation):void {
                anychartXML..styles[0].marker_style += <marker_style name={"yw_"+weatherInfo.city}>
                                                            <marker image_url={weatherInfo.condition.image} type="image" size="40" anchor="center"/>
                                                            <states>
                                                              <hover>
                                                                <marker size="52"/>
                                                              </hover>
                                                            </states>
                                                        </marker_style>; 
                
                var series:XML = anychartXML..series.(@name=="cities")[0];
                if (series.point == null)
                    series.point = new XMLList();
                series.point += <point name={weatherInfo.city} 
                                    y={weatherInfo.latitude} 
                                    x={weatherInfo.longitude}
                                    style={"yw_"+weatherInfo.city}>
                                <attributes>
                                  <attribute name="temperature">{weatherInfo.condition.temperature.toString()+weatherInfo.temperatureUnits}</attribute>
                                  <attribute name="title">{weatherInfo.title}</attribute>
                                  <attribute name="condition">{weatherInfo.condition.text}</attribute>
                                </attributes>
                             </point>;
                
                map1.anychartXML = anychartXML;
            }
            
            private var _citiesSelector:CitiesSelector;
            
            private function initializeHandler():void {
                Security.loadPolicyFile("http://weather.yahooapis.com/crossdomain.xml");
                Security.loadPolicyFile("http://l.yimg.com/crossdomain.xml");
                _citiesSelector = CitiesSelector(PopUpManager.createPopUp(this,CitiesSelector));
            }
        ]]>
    </mx:Script>
    
    <mx:XML id="anychartXML">
        <anychart>
          <settings>
            <maps path_type="absolute" path="maps/" />
          </settings>
          <charts>
            <chart plot_type="map">
              <styles/>
              <palettes>
                  <palette name="regionsPalette" type="ColorRange" color_count="16">
                    <gradient>
                        <key color="#D7A154"/>
                        <key color="#EEE087"/>
                        <key color="#9BBD72"/>
                    </gradient>
                  </palette>
              </palettes>
              <chart_settings>
                <title>
                  <text>European weather</text>
                </title>
                <data_plot_background enabled="False">
                  <fill color="LightBlue"/>
                </data_plot_background>
              </chart_settings>
              <data_plot_settings>
                <interactivity selectable="false" />
                <map_series source="europe_without_russia.amap">
                  <undefined_map_region palette="regionsPalette">
                    <interactivity hoverable="false" use_hand_cursor="false"/>
                    <label_settings enabled="true">
                        <format>{"{%REGION_NAME}"}</format>
                        <position anchor="center" valign="center" halign="center"/>
                        <font color="rgb(120,120,120)"/>
                    </label_settings>
                  </undefined_map_region>
                  <projection type="Eckert1"/>
                  <grid enabled="true"/>
                  <border color="Black" opacity="0.1"/>
                  <effects enabled="True">
                      <drop_shadow enabled="true" distance="3" opacity="0.2" blur_x="3" blur_y="3"/>
                  </effects>
                </map_series>
                <marker_series>
                  <label_settings enabled="true">
                    <format>{"{%Name}"}</format>
                    <position anchor="center" halign="right" valign="center" padding="20" />
                  </label_settings>
                  <tooltip_settings enabled="true">
                    <format>{"{%title}"}
Condition: {"{%condition}"}
Temperature: {"{%temperature}"}</format>
                  </tooltip_settings>
                </marker_series>
              </data_plot_settings>
              <data>
                <series type="marker" name="cities" >
                </series>
              </data>
            </chart>
          </charts>
        </anychart>
    </mx:XML>
    
    <ns1:AnyChartFlex id="map1" left="10" top="10" bottom="10" anychartXML="{this.anychartXML}" right="10"/>
    
</mx:Application>