Hi Pamela and people
Thanks by your response. Your prevoius tip is ok and my progran, now,
run. I have a second problem with the same code. When I compile and
run the program i see a error in the initialization, the message
is :
TypeError: Error #1009: No se puede acceder a una propiedad o a un
método de una referencia a un objeto nulo.
at geographicDistribution/onMapReady()[C:\Users\bordi\Documents\Flex
Builder 3\mi_temperaturas\src\geographicDistribution.mxml:121]
at <anonymous>()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at
mx.core::UIComponent/dispatchEvent()[C:\autobuild\3.2.0\frameworks
\projects\framework\src\mx\co\UIComponent.as:9298]
at com.google.maps.wrappers::BaseEventDispatcher/dispatchEvent()
at com.google.maps.wrappers::EventDispatcherWrapper/dispatchEvent()
at com.google.maps.core::MapImpl/configureMap()
at com.google.maps.wrappers::IMapWrapper/configureMap()
at com.google.maps::Map/onBootstrapInitComplete()
Now, if i press f5 (reload the page) in the navigator, the
application run ok and the error dissapear.
This is the complete code
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="dataSeting.send(); onInitialize
();"
viewSourceURL="srcview/index.html"
preloader="preload.CustomPreloader"
backgroundGradientColors="[#ffffff, #ffffff]">
<mx:Script>
<![CDATA[
import mx.events.ListEvent;
import mx.events.ItemClickEvent;
import mx.controls.advancedDataGridClasses.SortInfo;
import com.google.maps.overlays.MarkerOptions;
import com.google.maps.styles.FillStyle;
import com.google.maps.styles.StrokeStyle;
import com.google.maps.overlays.*;
import mx.controls.dataGridClasses.DataGridColumn;
import com.google.maps.interfaces.IMapType;
import com.google.maps.LatLng;
import com.google.maps.Map;
import com.google.maps.MapEvent;
import com.google.maps.MapType;
import com.google.maps.controls.*;
import mx.rpc.events.ResultEvent;
import com.google.maps.InfoWindowOptions;
import com.google.maps.MapMouseEvent;
import mx.controls.LinkButton;
import flash.net.URLRequest;
import flash.net.navigateToURL;
[Bindable]
private var dataSet:XML;
private var map:Map;
private var minTemp : Number = 0;
private var maxTemp : Number = 65;
private var minColor : int = 0xFF0000;
private var maxColor : int = 0x0000FF;
private var minColorObj : Object;
private var maxColorObj : Object;
private var delta : Object;
private function contactResultHandler(event:ResultEvent):void{
dataSet = event.result as XML;
}
private function onInitialize() : void
{
minColorObj = intToRgb( minColor );
maxColorObj = intToRgb( maxColor );
delta = { r: ( maxColorObj.r - minColorObj.r ),
g: ( maxColorObj.g -
minColorObj.g ),
b: ( maxColorObj.b -
minColorObj.b )
};
}
public function getTempColor( temp : Number ) : int
{
var percentage : Number = (temp / maxTemp);
return ( ( maxColorObj.r - percentage * delta.r
) << 16 )
+ ((maxColorObj.g - percentage * delta.g ) <<
8 )
+ ( maxColorObj.b - percentage * delta.b );
}
/*
Adapted color tween method originally found at:
http://www.darronschall.com/weblog/archives/000251.cfm
*/
public static function intToRgb( color:int ):Object
{
var r:int = ( color & 0xFF0000 ) >> 16;
var g:int = ( color & 0x00FF00 ) >> 8;
var b:int = color & 0x0000FF;
return {r:r, g:g, b:b};
}
public function colorLabelFunction( value : *, column :
DataGridColumn ) : String
{
return getTempColor( parseFloat( [email protected]
() ) ).toString(16);
}
public function onContinerInitialize( event:Event ):void
{
map = new Map();
map.key = "PUT API KEY HERE";
map.addEventListener( MapEvent.MAP_READY,
onMapReady );
//control de zoom
map.addControl(new ZoomControl());
//control de posicion
map.addControl(new PositionControl());
//selector de tipo de mapa
map.addControl(new MapTypeControl());
mapContainer.addChild( map );
}
public function onContainerResize( event:Event ):void
{
map.setSize( new Point( mapContainer.width,
mapContainer.height ) );
}
private function onMapReady( event:Event ):void
{
map.enableScrollWheelZoom();
map.enableContinuousZoom();
map.setCenter(new LatLng(-33.133, -64.35), 7,
MapType.HYBRID_MAP_TYPE );
for each ( var data : XML in dataSet.data )
{
var latlng:LatLng = new LatLng( parseFloat(
da...@lat ),
parseFloat( da...@lon ) );
var markerOptions : MarkerOptions = new
MarkerOptions({
strokeStyle: new StrokeStyle({color:
0x000000}),
fillStyle: new FillStyle({color:
getTempColor( parseFloat
( [email protected]() ) ), alpha: 0.8}),
radius: 12,
hasShadow: true
})
markerOptions.tooltip =
[email protected]() + ": " +
[email protected]() + " F";
var marker : Marker = new Marker( latlng,
markerOptions );
// se define contenido del marcador
var mivariable:String = da...@location;
var html:String = "<b><font
color='#8B69AE'>Hola</font></b><br/
><a href='http://e-seminario.net/cms' target='_blank'><font
color='#EC2D79'><u>"+"variable por ej "+"</u></font></a><br/><br/><br/
><br/><br/><br/><br/><br/><br/>";
map.addOverlay(createMarker(latlng, html));
}
// Agregar enlace a GeoINTA sobre el mapa
var clickMore:LinkButton = new
LinkButton();
clickMore.percentWidth = 18;
clickMore.label = "Visitar GeoINTA";
clickMore.addEventListener(MouseEvent.CLICK, function
(e:MouseEvent):void {
var request:URLRequest = new
URLRequest("http://
geointa.inta.gob.ar");
navigateToURL(request,
"_blank");
});
addChild(clickMore);
}
//Crea marcador
private function createMarker(latlng:LatLng,
html:String):Marker {
var marker:Marker = new Marker(latlng);
marker.addEventListener(MapMouseEvent.CLICK,
function
(e:MapMouseEvent):void {
var myTitle:String = "<img
src='http://www.unlu.edu.ar/
imagenes/img-infouniversiades3.png' width='130' height='79' ></a>";
var myContent:String = html;
map.openInfoWindow(latlng, new
InfoWindowOptions({titleHTML:
myTitle,
contentHTML: myContent, width:300,
drawDefaultFrame:true}));
});
return marker;
}
private function sortNumeric( obj1 : *, obj2 : * ) : int
{
var val1 : Number = parseFloat(
[email protected]() );
var val2 : Number = parseFloat(
[email protected]() );
if ( val1 > val2 )
return -1;
if ( val1 < val2 )
return 1;
return 0;
}
private function onGridItemClick( event : ListEvent ) :
void
{
var data : XML = event.itemRenderer.data as XML;
if ( data )
map.setCenter( new LatLng( parseFloat(
da...@lat ), parseFloat
( da...@lon ) ) );
}
]]>
</mx:Script>
<!-- Cargo datos de un archivo XML externo y remoto-->
<mx:HTTPService id="dataSeting" url="http://127.0.0.1:4000/
temperaturas.xml"
result="contactResultHandler(event)"
resultFormat="e4x"/>
<!-- Esta marca es la encargada de definir dos áreas horizontalas en
apantalla-->
<mx:VDividedBox width="100%" height="100%">
<!-- UIComponent es el primer contenedor de la pantalla donde se
insertará el mapa -->
<mx:UIComponent id="mapContainer"
initialize="onContinerInitialize(event);"
resize="onContainerResize(event)"
width="100%" height="100%"/>
<!-- Defino que ne la parte inferior se inserta una estructura
de
tabs -->
<mx:TabNavigator width="100%" height="200">
<!-- Defino el primer tab -->
<mx:Canvas width="100%" height="100%" label="Listado de
Ciudades">
<mx:DataGrid dataProvider="{ dataSet.data }"
width="100%"
height="100%" itemClick="onGridItemClick(event)">
<mx:columns>
<mx:DataGridColumn
headerText="Location" dataField="@location" /
>
<mx:DataGridColumn
headerText="Avg Jan Temp"
dataField="@janTemp" sortCompareFunction="sortNumeric" />
<mx:DataGridColumn
headerText="Latitude" dataField="@lat" />
<mx:DataGridColumn
headerText="Longitude" dataField="@lon" />
<mx:DataGridColumn
headerText="Color"
labelFunction="colorLabelFunction"
itemRenderer="components.ColorRenderer" />
</mx:columns>
</mx:DataGrid>
</mx:Canvas>
<!-- Defino el segundo tab -->
<mx:Canvas width="100%" height="100%" label="Acerca de...">
<mx:TextArea editable="false" width="100%"
height="100%">
<!-- Inserto texto HTML en un tab -->
<mx:htmlText>
<![CDATA[<b>Qué es esto?</b>
<p>Esto es un ejemplo acerca de como trabajar on los elementos
gráficos relacionados con mapas, bla, bla, bla...</p>
<p>Se puede insertar html sin ningún problema, así como enlaces a
otras partes, por ejemplo a mi <a href="http://
ferbor.blogspot.com">blog</a> </p>
<p>lameb simbut te comiyum denber acicatum etnis lasertis ah va codex
sei tutus lameb simbut te comiyum denber acicatum etnis lasertis ah va
codex sei tutus alba salga contoda totre lader mullkait solle fiud
fresdtiok alo jujuan sai toga onga mocha alga canda salo tuitui remo
hkaiko sango juniter masker lanmarker duncher suimer sastum gairi
jukaste acalite chengo lameb simbut te comiyum denber acicatum etnis
lasertis ah va codex sei tutus lameb simbut te comiyum denber acicatum
etnis lasertis ah va codex sei tutus lameb simbut te comiyum denber
acicatum etnis lasertis ah va codex sei tutus lameb simbut te comiyum
denber acicatum etnis lasertis ah va codex sei tutus lameb simbut te
comiyum denber acicatum etnis lasertis ah va codex sei tutus lameb
simbut te comiyum denber acicatum etnis lasertis ah va codex sei tutus
lameb simbut te comiyum denber acicatum etnis lasertis ah va codex sei
tutus lameb simbut te comiyum denber acicatum etnis lasertis ah va
codex sei tutus lameb simbut te comiyum denber acicatum etnis lasertis
ah va codex sei tutus</p>
]]>
</mx:htmlText>
</mx:TextArea>
</mx:Canvas>
</mx:TabNavigator>
</mx:VDividedBox>
</mx:Application>
Thanks
Fernando Bordignon
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Maps API For Flash" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-maps-api-for-flash?hl=en
-~----------~----~----~----~------~----~------~--~---