Last we said how to build a simple method of loading flash, in the Flexviewer GIS development has a lot of loading order to note, such as SWF order, XML order, to do some interactive map operation must wait for these things to be loaded before they can be called, And the way you register a JavaScript call in Flex, so we throw an event on the flex side and tell the JavaScript side graph to load through as Externalinterface.call, So we have to define the event communication, honestly I do not like JS that event, I write the number of groups to record the message.
1 /**2 * Created with JetBrains webstorm.3 * User:haibalai4 * date:15-12-95 * Time: PM 3:406 * To change this template use File | Settings | File Templates.7 */8 9 varEventbus =function (){Ten This. handlers={}; One This. Objs = {}; A } - -Eventbus.prototype={ the Constructor:eventbus, - - /** - * Add Event + * @param type - * @param handler + */ AAddEventListener:function(type,handler) { at if(typeof This. handlers[type]== ' undefined '){ - This. handlers[type]=NewArray (); - } - This. Handlers[type].push (handler); - }, - in /** - * Delete Event to * @param type + * @param handler - */ theRemoveEventListener:function(type,handler) { * if( This. Handlers[type]instanceofArray) { $ varhandlers= This. Handlers[type];Panax Notoginseng for(vari=0,len=handlers.length;i<len;i++){ - if(handler[i]==handler) { theHandlers.splice (i,1); + Break; A } the } + } - }, $ $ /** - * Throwing Events - * @param event the */ -Dispatchevent:function(event) {Wuyi the - if(!event.target) { Wuevent.target= This; - } About if( This. Handlers[event.type]instanceofArray) { $ varhandlers= This. Handlers[event.type]; - This. objs[event.type] =[event.obj]; - for(vari=0,len=handlers.length;i<len;i++){ - Handlers[i] (event); A } + } the } -}
We initialized this event class to Mapcontrol, and I added the Swfid attribute to the parameter class, preventing a page from loading two of maps causing confusion.
1 varMapcontrol =function () {2 /**3 * Map initialization parameter Specific reference parameter class4 * @type {Parameter}5 */6 This. parameter =NewParameter ();7 /**8 * Add event Body specific reference Eventbus class9 * @type {Eventbus}Ten */ One This. Eventbus =NewEventbus (); A - This. initialise =function () { - the -swfobjhash[ This. parameter.div] = This; - varSwfversionstr = "11.4.0"; - varXiswfurlstr = ""; + varFlashvars = {}; - + varparams = {}; AParams.wmode = "opaque"; atParams.quality = "High"; -Params.bgcolor = "#ffffff"; -Params.allowscriptaccess = "Always"; -Params.allowfullscreen = "true"; - varattributes = {}; -Attributes.id = This. Parameter.div; inAttributes.name = This. Parameter.div; -Attributes.align = "Middle"; to swfobject.embedswf ( +"Http://localhost/mymap/index.swf" + This. parameter.geturlstring (), This. Parameter.div, - This. Parameter.width, This. Parameter.height, the swfversionstr, Xiswfurlstr, * flashvars, params, attributes); $Swfobject.createcss ("#" + This. Parameter.div, "display:block;text-align:left;");Panax Notoginseng } - the } + A varSwfobjhash =NewObject (); the + - //Flex Graphics Component Load Complete callback Swfid is the identifier that distinguishes the embedded SWF $ functionEmapcomplete (swfid) { $Swfobjhash[swfid].map.emap =document.getElementById (SWFID); - -Swfobjhash[swfid].eventbus.dispatchevent ({type: "Initialized"}); the}
We'll define our own event name.
1 /**2 * Created with JetBrains webstorm.3 * User:haibalai4 * date:15-12-95 * Time: PM 3:406 * To change this template use File | Settings | File Templates.7 */8 varMapcontrolevent = {9 /**Ten * Map Initialization Events One */ AInitialized: "Initialized", - -}
You can do this on an HTML page.
<script type= "Text/javascript" > varnew Mapcontrol (); = "Config-checkview.xml"; A.parameter.div= "Flashcontent"; = "n"; = "n"; A.eventbus.addeventlistener (mapcontrolevent.initialized,inithandle); A.initialise (); function Inithandle () { alert ("load Complete") }</script>
Business GIS How to let other developers do not need to understand the GIS can engage in development? Three