资源预览内容
第1页 / 共14页
第2页 / 共14页
第3页 / 共14页
第4页 / 共14页
第5页 / 共14页
第6页 / 共14页
第7页 / 共14页
第8页 / 共14页
第9页 / 共14页
第10页 / 共14页
亲,该文档总共14页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
WorldWind 系列五:插件加载过程全解析来源:博客园 作者:无痕客不得不承认World Wind的代码真的很庞大,没有太多帮助文档的前提下,一头钻进代码 里肯定令你头疼的,甚至研究代码间关联仿佛是在走迷宫。我最近一直想弄明白如何在 MenuBar 中加载那些插件的, WorldWind 学习系列四中研究的只是特殊的三个功能加载的, 那三个没有继承Plugin类,不算是插件功能加载。所以WorldWind学习系列四加载的三个是 特殊情况,不是一般的插件加载。今天下午终于柳暗花明,如果你真正关注World Wind分析, 那么就好好看看下面的插件加载过程全解析。我们先看看 Plugin 类的继承图,看看到底都有些什么插件,然后在分析一般性的插件加载 全过程。NASA Wo rid Wind 1,4.1 API documenta tian (3923)Plugin ClassNamespaces ” VcrldWind.PluginEngine - Plugin-Pluginp-Te rr ainManagerp-DynamicCloudsp-PlaceFinderLaade r h-WavingFlags p-LayerManager h-NRLWeathe rLa ader:-ErnngLaad已r p-Tim 已(Zcntrcill己r L-Scale EarLeg 已 nd p-Ccmpass3D h-GpTrackerPlkigin Sha p 已 Fi IsInfoTocI l-ShapeFileLcader :C v 已 rvie wFo rm Loader p-MovieR.eccrde r h-GlobeCu rso rPlugin p-Mea&ureToal L-StarE3D -Ma&ureToalNG p-V;hirebcardPlugin p-GecR.SSLcader p-AnaglyphStereo L-Joystick p -KM LImporter h-Atmo sphere -FloodLevelFlugin h-EscternalLayerManagerLoader :-Ligh tdntroll 已p-CompassFlickrPluoin哦,原来这么多插件,我们要基于WW开发自己的应用,只需继承Plugin类写出自己的插 件功能即可的。我们现在分析插件加载过程,请确保你看过WorldWind学习系列二:擒贼先擒王篇2中 的(5.加载上次使用的配置信息)。加载的插件入口就是WorldWind.cs的Main()中调用的 LoadSetti ngs()静态方法。1.读取WorldWind的配置中插件信息 曰加载WorldWind配置private static void LoadSettings()try/先读取上次使用时保存的使用插件配置文件”,如果存在,则从文件中读取配置实 例化 WorldWindSettingsSettings = (WorldWindSettings) SettingsBase.Load(Sett ings, SettingsBase.LocationType.User);if(!File.Exists(Settings.FileName)/我们假定是配置文件不存在,这就是一个个地加载插件,保存到ArrayList 中Settings.PluginsLoadedOnStartup.Add(ShapeFileInfoTool);/Settings.PluginsLoadedOnStartup.Add(OverviewFormLoader);)/Settings.PluginsLoadedOnStartup.Add(Atmosphere丿;);Settings.PluginsLoadedOnStartup.Add(SkyGradientSettings.PluginsLoadedOnStartu p.Add( BmngLoader);/Settings.PluginsLoadedOnStartup.Add(Compass); /Settings.PluginsLoadedOnStartup.Add(ExternalLayerManagerLoader););Settings.PluginsLoadedOnStartup.Add(MeasureTool/Settings.PluginsLoadedOnStartup.Add(MovieRecorder);Settings.PluginsLoadedOnStartup.Add(NRLWeatherLoader);Settings.PluginsLoadedOnStartup.Add(ShapeFileLoader);Settings.PluginsLoadedOnStartup.Add(Stars3D);Settings.PluginsLoadedOnStartup.Add(GlobalClouds)Settings.PluginsLoadedOnStartup.Add(PlaceFinderLoader);Settings.PluginsLoadedOnStartup.Add(LightController);Settings.PluginsLoadedOnStartup.Add(Earthquake_2.0.2.1)Settings.PluginsLoadedOnStartup.Add(Historical_E arthquake_2.0.2.2);Settings.PluginsLoadedOnStartup.Add(KMLImporter )/Settings.PluginsLoadedOnStartup.Add(doublezoom)/Settings.PluginsLoadedOnStartup.Add(PlanetaryRings);Settings.PluginsLoadedOnStartup.Add(TimeController);/Settings.PluginsLoadedOnStartup.Add(WavingFlags)Settings.PluginsLoadedOnStartup.Add(ScaleBarLegend);Settings.PluginsLoadedOnStartup.Add(Compass3D);Settings.PluginsLoadedOnStartup.Add(AnaglyphStereo);Settings.PluginsLoadedOnStartup.Add(GlobeIcon);/ decrypt encoded user credentialsDataProtector dp = new DataProtector(DataProtector.Store.USE USER STORE);if (Settings.ProxyUsername.Length 0) Settings.ProxyU sername = dp.TransparentDecrypt(Settings.ProxyUsername);if(Settings.ProxyPassword.Length 0) Settings.ProxyP assword = dp.TransparentDecrypt(Settings.ProxyPassword);catch(Exception caught)Log.Write(caught);2.Main()中后面调用 MainApplication()方法,该 MainApplication()调用OpenStartupWorld(),用来初始化启动World对象。OpenStartupWorld()方法首先确定加 载的是 Earth/Moon 等,然后开始加载一个星球。曰加载一个星球代码/ / Loads a new planet/ private void OpenWorld(string worldXmlFile)if(this.worldWindow.CurrentWorld != null)trythis.worldWindow.ResetToolbar();catchtryforeach (PluginInfo p in this.compiler.Plugins)tryif(p.Plugin.IsLoaded) p.Plugin.Unload();catchcatchtrythis.worldWindow.CurrentWorld.Dispose();catch if(this.gotoDialog != null)this.gotoDialog.Dispose();this.gotoDialog = null;if(this.rapidFireModisManager != null)this.rapidFireModisManager.Dispose();this.rapidFireModisManager = null;if(this.animatedEarthMananger != null)this.animatedEarthMananger.Dispose();this.animatedEarthMananger = null;if(this.wmsBrowser != null)this.wmsBrowser.Dispose();this.wmsBrowser = null;worldWindow.CurrentWorld = WorldWind.ConfigurationLoader.Load(worldXmlFile, worldWindow.Cache);this.splashScreen.SetText(Initializing menus.);/ InitializePluginCompiler()是我们要关注的初始化插件编辑器Plu ginCompiler (真正管理加载插件的类)InitializePluginCompiler();/RenderableObject系统很复杂,我们稍后准备专门分析一下foreach(RenderableObject worldRootObject in this.worldWin dow.CurrentWorld.RenderableObjects.ChildObjects)this.AddLayerMenuButtons(this.worldWindow, worldRootO bject);/加载 Earth 专有的 MenuButton( AnimatedEarthManager 和 RapidF ireModisManager)的配置,/这里主要不关注this.AddInternalPluginMenuButtons();this
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号