Initialize() публичный Метод

Initializes the resource.
public Initialize ( ) : void
Результат void
Пример #1
0
 public void Add()
 {
     IsRunning = true;
     kml = new KmlLayer { ID = Name, Url = Location };
     gl = AppState.ViewDef.FindOrCreateGroupLayer(Folder);
     if (gl != null) gl.ChildLayers.Add(kml);
     kml.Initialize();
 }
Пример #2
0
        private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Error != null)
            {
                this.InitializationFailure = new ArgumentException(Properties.Resources.KmlLayer_DocumentParsingFailed);
            }
            else
            {
                // Create graphic features from definitions -- this code requires the UI thread
                FeatureDefinition fd = (FeatureDefinition)e.Result;

                // Initialize the layer name with the name info coming from the KML document
                Name = fd.name;

                _hasRootContainer = _isRoot && fd.hasRootContainer; // the root container has been collapsed (info needed to generate internal folderIDs)

                if (_visibleLayerIds != null && !IsInitialized)
                {
                    // VisibleLayerIds is set --> layer created from a web map --> check that the layer must stay visible (_hasRootContainer is set only after the file has been parsed)
                    if (_hasRootContainer && !_visibleLayerIds.Contains(1)) // FolderIds 1 is the top level folder that may not be visible in SL
                    {
                        Visible = false;
                        _isLoading = false;
                        base.Initialize();
                        return;
                    }
                }

                // Store the parsed styles to be able to pass them to children
                _context.Styles = fd.styles;

                // Create ground overlays and add to element layer
                if (fd.groundOverlays.Any())
                {
                    ElementLayer elementLayer = new ElementLayer { ID = Properties.Resources.KmlLayer_GroundOverlaysSublayer };
                    fd.CreateGroundOverlays(elementLayer, _context.Images, Map);
                    ChildLayers.Add(elementLayer);
                    if (IsInitialized)
                        elementLayer.Initialize(); // should be done by the group layer (to remove when Bug#2718 is fixed)
                }

                // Create graphics and add to graphics layer
                if (fd.placemarks.Any())
                {
                    KmlGraphicsLayer kmlGraphicsLayer = new KmlGraphicsLayer
                    {
                        ID = Properties.Resources.KmlLayer_PlacemarksSublayer,
                        ProjectionService = ProjectionService,
                        IsHidden = _hideChildren
                    };
                    fd.CreateGraphics(kmlGraphicsLayer, _context.Images);
            #if !WINDOWS_PHONE
                    kmlGraphicsLayer.MapTip = MapTip;
            #endif
                    ChildLayers.Add(kmlGraphicsLayer);
                    if (IsInitialized)
                        kmlGraphicsLayer.Initialize(); // should be done by the group layer  (to remove when Bug#2718 is fixed)

                    // Setting the Spatial Reference of the KML layer to 4326:
                    if (this.SpatialReference == null)
                    {
                        this.SpatialReference = new Geometry.SpatialReference(4326);
                    }
                }

                // Create a sub KML layer for each container
                foreach (ContainerInfo container in fd.containers)
                {
                    string fullPath = _fullPath == null ? (container.Name ?? string.Empty) : string.Concat(_fullPath, "/", container.Name);
                    // Note : use internal constructor, so properties such as MapTip, ProxyUrl, VisibleLayers.. are reported to the children
                    var kmlLayer = new KmlLayer(this)
                                   	{
                                   		ID = container.Name,
                                   		Name = container.Name,
                                   		_fullPath = fullPath,
                                   		RefreshInterval = TimeSpan.FromSeconds(container.RefreshInterval),
                                   		VisibleTimeExtent = container.TimeExtent,
                                   		RegionInfo = container.RegionInfo,
                                   		_folderId = container.FolderId,
                                   		_hideChildren = container.HideChildren,
                                   		IsHidden = _hideChildren
                                   	};

                    bool isOk = true;
                    if (string.IsNullOrEmpty(container.Url))
                    {
                        // Set the visibility of the layer
                        // There are 3 ways to define the visibility of a folder or document, by priority order:
                        //    - by the internal VisibleLayerIds property (for the layers inside a web map)
                        //    - by the public VisibleLayers property
                        //    - by the visibility defined in the KML document
                        kmlLayer.Visible = _visibleLayerIds != null ? _visibleLayerIds.Contains(kmlLayer._folderId) : IsContainerVisible(fullPath, container.Visible);
                        kmlLayer._visibleLayerIds = _visibleLayerIds;

                        // Subfolder : Create a context object and initialize a KmlLayer with it
                        kmlLayer._context = new KmlLayerContext
                                              	{
                                              		Element = container.Element, // The XElement that the KML layer has to process
                                              		Styles = _context.Styles,
                                              		Images = _context.Images,
                                              		AtomAuthor = container.AtomAuthor,
                                              		AtomHref = container.AtomHref
                                              	};
                    }
                    else
                    {
                        // NetworkLink : initialize the Url
                        Uri containerUri = GetUri(container.Url, GetBaseUri());
                        if (containerUri != null)
                        {
                            kmlLayer.Url = containerUri;
                            kmlLayer.ViewRefreshMode = container.ViewRefreshMode;
                        }
                        else
                            isOk = false; // bad url, don't create the child layer

                        // Set the visibility of the layer
                        // For a network link, the internal VisibleLayerIds property is not used.
                        kmlLayer.Visible = IsContainerVisible(fullPath, container.Visible);
                    }

                    if (isOk)
                    {
                        ChildLayers.Add(kmlLayer);
                        if (IsInitialized)
                            kmlLayer.Initialize(); // should be done by the group layer --> to remove later (after or with CR2718)
                    }
                }

                // Check that the layer refresh interval is compatible with infos coming from NetworkLinkControl
                if (fd.networkLinkControl != null)
                {
                    if (RefreshInterval != TimeSpan.Zero && fd.networkLinkControl.MinRefreshPeriod > 0.0)
                        RefreshInterval = TimeSpan.FromSeconds(Math.Max(RefreshInterval.Seconds, fd.networkLinkControl.MinRefreshPeriod));
                }

                // Set resolution range from the Region/Lods info of the parent
                SetResolutionRange();

            }

            if (!IsInitialized)
                base.Initialize();
            _isLoading = false;
            _isLoaded = true;
        }
Пример #3
0
 public static void AddKmlFile(string filePath, GroupLayer curGrLayer)
 {
     var fi = new FileInfo(filePath);
     var kmlLayer = new KmlLayer { Url = new Uri(fi.FullName), ID = fi.Name} ;
     kmlLayer.Initialize();
     kmlLayer.Visible = false;
     curGrLayer.ChildLayers.Add(kmlLayer);
 }