[ka-Map-users] Detection: Map and Javascript loaded

The Bun rosario.carbone at ipl.com
Thu Nov 1 08:42:19 EDT 2007


Hi Javier Pasqual

I am not quite sure I understood what is your problem. I assume you just
want to understand about the logic itself.
I appreciate that it is quite confusing, and I am not quite sure I got
everything but I can try to write down what I understood myself.

The function myInitialized() is called when the event KAMAP_INITIALIZED is
triggered and this happens in kaMap.prototype.initializeCallback, when the
callback function is raised during the main initialization of kaMap.

Why a callback function is necessary?
I assume because the initialize function is asynchrounous and the function
is activated when the server ( init.php ) has finish his job, then a client
has to wait the KAMAP_INITIALIZED to determines when the initialization is
complete and maybe that the "initializationState" is set to 2 as well.

The other event is the KAMAP_MAP_INITIALIZED, you should consider this as an
internal event and although your kamap object is not 100% initialized at
this point you can start to do something like for example in your handler
you can select the map, add a client overlay etc. This event is triggered
by: "eval(szInit);" exactly in this line "this.selectMap('gmap');" ( have a
look at the selectMap function ).

"The eval(szInit);" code initializes the internal class _map, essentially
add a new instance of _map to kaMap. If you add a "alert ('szInit: ' +
szInit);" line in the callback function you may see what exactly happens,
essentially it is in init.php that the JavaScript code is built because it
is server side that the actual data are stored and configured but the code
generated runs obviously in the client, in the initializeCallback function,
when the eval function is called.

Anyway noone of the 2 events have anything to do directly with the
map/images/icons loaded in the html page, I think you refer to the viewport
div element. The two above events have to do with the kaMap object itself
and its subobject  _map. The viewport image itself is rendered by the html
page after the onload event that actually implement the viewport dynamically
through the kaMap object.

Take this notes as they are, as I am not totally sure I understood the whole
process myself, but hopefully I said some near to the truth and I hope this
can help you to understand. 

Kind Regards
Rosario Carbone




Javier Pascual Herranz wrote:
> 
> Detection: Map and Javascript loaded
> ------------------------------------
> 
> The file index.html contains the following:
> 
> <body onload="myOnLoad();">
> 
> Meaning: While loading the site, the following function is executed:
> 
> function myOnLoad() {
> ...
> ...
> myKaMap.registerForEvent( KAMAP_INITIALIZED, null, myInitialized ); ...
> ...
> 
> myKaMap.initialize( szMap, szExtents, szCPS ); }
> 
> In this function, a series of events is called. The one interesting us, is
> the following:
> 
> myKaMap.registerForEvent( KAMAP_INITIALIZED, null, myInitialized );
> 
> Meaning, that on ocurring the event "KAMAP_INITIALIZED", the javascript
> function myInitialized() should be executed:
> 
> function myInitialized() {
> 	alert("Map Loaded");
> }
> 
> The last instruction executed inside the function myOnLoad() should be:
> 
> myKaMap.initialize( szMap, szExtents, szCPS );
> 
> This function is defined in the file kamap.js
> 
> kaMap.prototype.initialize = function() { .. call(szURL, this,
> this.initializeCallback); ..
> }
> 
> At the same time, the previous function calls the function
> 
> kaMap.prototype.initializeCallback = function( szInit ) {
>     // szInit contains /*init*/ if it worked, or some php error otherwise
>     if (szInit.substr(0, 1) != "/") {
>         this.triggerEvent( KAMAP_ERROR, 'ERROR: ka-Map! initialization '+
>                           'failed on the server.  Message returned was:\n'
> +
>                           szInit);
>         return false;
>     }
> 
>     eval(szInit);
>     this.triggerEvent( KAMAP_INITIALIZED );
> 
>     this.initializationState = 2;
>  
> };
> 
> This very function I need to check if the received param "szInit" contains
> the character / in the its position. If not, it causes and "error"
> initializing the site. But if it has the character, the map has loaded
> correctly and the function related to "KAMAP_INITIALIZED" will be
> executed.
> In my case:
> 
> function myInitialized() {
> 	alert("Map Loaded");
> }
> 
> AND NOW THE PROBLEM:
> The message "Map Loaded" I put shows up before the map and all the other
> items (images, icons, etc.) have been loaded entirely
> 
> I'M HALLUCIONATING WITH THIS!! IS THERE ANYONE WHO CAN HELP ME SOLVING
> THIS
> PROBLEM?!
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> ka-Map-users mailing list
> ka-Map-users at lists.maptools.org
> http://lists.maptools.org/mailman/listinfo/ka-map-users
> 
> 
:-):-)
-- 
View this message in context: http://www.nabble.com/Detection%3A-Map-and-Javascript-loaded-tf4726170.html#a13527874
Sent from the ka-map-users mailing list archive at Nabble.com.



More information about the ka-Map-users mailing list