MapWindow / MapWindow5

MW5 is a desktop GIS which is extendable using the plug-in architecture. It is using the MapWinGIS mapping control and is created from scratch in 2015 using new technologies like MEF and Dependency Injection making it small in size, robust and fast.
290 stars 100 forks source link

ProjectOpened Event #18

Open odiezgz opened 6 years ago

odiezgz commented 6 years ago

I am developing a plugin (for mapwindow v5.1.1.207023) that serializes metadata associated to each of the layers created by my plugin during the execution. The problem is that when I load the saved project file again and during deserialization I capture the event "plugin.LayerAdded" but the layer has not yet restored its metadata values because the restore function is called after adding the layer:

private bool RestoreLayers(XmlProject project, out int selectedLayerHandle)
{
   ...
   foreach (var xmlLayer in project.Layers
   {
        ...
        if (_layerService.AddLayerIdentity(xmlLayer.Identity))     // Add layer and inside called LayerAdded event
        {   
               ...
               xmlLayer.RestoreLayer(layer, _broadcaster);     // Deserialize layer metada
}

Everything would be much easier if in "BasePlugin.cs" had a new event "ProjectOpened" just like there is one for "ProjectClosed", ...

        public event EventHandler<EventArgs> ProjectOpened
        {
            add { ProjectOpened_ += value; }
            remove { ProjectOpened_ -= value; }
        }

... triggered by the method "public bool Open (string filename, bool silent = true) "from the file" ProjectService.cs "when result is true:

public bool Open(string filename, bool silent = true)
{
...
       if (legacy)
       {
           result = OpenLegacyProject(filename);
       }
       else
       {
           result = OpenCore(filename, silent);
       }

       if (result) _broadcaster.BroadcastEvent(p => p.ProjectOpened, this, args);
pmeems commented 6 years ago

I've created https://mapwindow.atlassian.net/browse/MW5CORE-206 for this. At the moment we're very busy getting a new version of MWGis out. After that (hopefully in a week) we'll work on a new version of MW5 and then we'll look at this issue.