예제 #1
0
        public SlidingFeatureMap(int numToEvaluate, MapParams config, MapSizer groupSizer)
        {
            _allIndividuals           = new List <Individual>();
            _groupSizer               = groupSizer;
            _maxIndividualsToEvaluate = numToEvaluate;
            _remapFrequency           = config.RemapFrequency;
            NumFeatures               = config.Features.Length;

            _groupBoundaries = new List <double> [NumFeatures];
        }
예제 #2
0
        private Entity InitEntity(ValveBsp.Entities.Entity value, MapParams mapParams)
        {
            var classname = (string)value["classname"];

            EntityCtor ctor;

            if (_sEntityCtors.TryGetValue(classname, out ctor))
            {
                return(ctor == null ? null : ctor(value, mapParams));
            }

            MethodInfo matchingMethod = null;

            foreach (var method in typeof(IndexController).GetMethods(BindingFlags.Static | BindingFlags.NonPublic))
            {
                var attrib = method.GetCustomAttribute <ClassnameAttribute>();
                if (attrib == null)
                {
                    continue;
                }

                if (attrib.Default && matchingMethod == null || attrib.Names.Contains(classname))
                {
                    matchingMethod = method;
                    if (!attrib.Default)
                    {
                        break;
                    }
                }
            }

            if (matchingMethod == null)
            {
                _sEntityCtors.Add(classname, null);
                return(null);
            }

            var parameters = matchingMethod.GetParameters();
            var entType    = parameters[0].ParameterType;
            var hasParams  = parameters.Length == 3;

            var valueParam     = Expression.Parameter(typeof(ValveBsp.Entities.Entity), "value");
            var mapParamsParam = Expression.Parameter(typeof(MapParams), "mapParams");

            var ctorCall   = Expression.New(entType.GetConstructor(Type.EmptyTypes));
            var methodCall = hasParams
                ? Expression.Call(matchingMethod, ctorCall, valueParam, mapParamsParam)
                : Expression.Call(matchingMethod, ctorCall, valueParam);

            var deleg = Expression.Lambda <EntityCtor>(methodCall, valueParam, mapParamsParam).Compile();

            _sEntityCtors.Add(classname, deleg);

            return(deleg(value, mapParams));
        }
예제 #3
0
        private void ExportMap(MapParams mapParams)
        {
            Texture2D tex = MapExport.TexFromMap(GraphicsDevice, map);

            Directory.CreateDirectory("Maps/Tests/create");

            using (FileStream file = File.Open("Maps/Tests/create/map" + mapParams.seed + ".png", FileMode.Create))
            {
                tex.SaveAsPng(file, mapParams.size.X, mapParams.size.Y);
            }
        }
예제 #4
0
        static void run_me_tuning(int id, double sigma)
        {
            int numParams = 20;

            var searchParams = new MapElitesSearchParams();

            searchParams.InitialPopulation = 100;
            searchParams.NumToEvaluate     = 50000;
            searchParams.MutationPower     = sigma;

            var feature1 = new FeatureParams();

            feature1.Name     = "Sum1";
            feature1.MinValue = -(numParams * boundaryValue) / 2.0;
            feature1.MaxValue = (numParams * boundaryValue) / 2.0;

            var feature2 = new FeatureParams();

            feature2.Name     = "Sum2";
            feature2.MinValue = -(numParams * boundaryValue) / 2.0;
            feature2.MaxValue = (numParams * boundaryValue) / 2.0;

            var mapParams = new MapParams();

            mapParams.Type      = "FixedFeature";
            mapParams.StartSize = 100;
            mapParams.EndSize   = 100;
            mapParams.Features  = new FeatureParams[] { feature1, feature2 };

            var meParams = new MapElitesParams();

            meParams.Search = searchParams;
            meParams.Map    = mapParams;

            double          maxValue = Double.MinValue;
            SearchAlgorithm search   = new MapElitesAlgorithm(0, meParams, numParams);

            while (search.IsRunning())
            {
                Individual cur = search.GenerateIndividual();
                cur.Fitness = evaluate(0, cur.ParamVector);
                maxValue    = Math.Max(cur.Fitness, maxValue);
                search.ReturnEvaluatedIndividual(cur);
            }
        }
예제 #5
0
        public FixedFeatureMap(int numToEvaluate, MapParams config, MapSizer groupSizer)
        {
            _groupSizer = groupSizer;
            _numIndividualsEvaluated  = 0;
            _maxIndividualsToEvaluate = numToEvaluate;
            NumGroups = -1;

            NumFeatures     = config.Features.Length;
            _lowGroupBound  = new double[NumFeatures];
            _highGroupBound = new double[NumFeatures];
            for (int i = 0; i < NumFeatures; i++)
            {
                _lowGroupBound[i]  = config.Features[i].MinValue;
                _highGroupBound[i] = config.Features[i].MaxValue;
            }

            _eliteIndices = new List <string>();
            EliteMap      = new Dictionary <string, Individual>();
            CellCount     = new Dictionary <string, int>();
        }
예제 #6
0
        private void btn_genMap_Click(object sender, EventArgs e)
        {
            MapParams mp = new MapParams(64, 64);
            List <Tuple <Corridor, Corridor, Room> > rooms = MapGenerator.GenerateLayout(mp);

            List <AbstractRoom> rr = new List <AbstractRoom>();

            foreach (Tuple <Corridor, Corridor, Room> tuple in rooms)
            {
                RoomGenerator.Populate(tuple.Item3, tuple.Item1, tuple.Item2);
                if (tuple.Item1 != null)
                {
                    rr.Add(tuple.Item1);
                }
                if (tuple.Item2 != null)
                {
                    rr.Add(tuple.Item2);
                }
                rr.Add(tuple.Item3);
            }

            pb_mapPreview.Image = MapGenerator.Preview(rr, mp);
        }
예제 #7
0
        private static MoveRope InitMoveRope(MoveRope ent, ValveBsp.Entities.Entity value, MapParams mapParams)
        {
            if (InitKeyframeRope(ent, value, mapParams) == null)
            {
                return(null);
            }

            ent.PositionInterpolator = value["PositionInterpolator"];

            return(ent);
        }
예제 #8
0
        private static KeyframeRope InitKeyframeRope(KeyframeRope ent, ValveBsp.Entities.Entity value, MapParams mapParams)
        {
            var min = (SourceUtils.Vector3)value["origin"];
            var max = min;

            ent.NextKey = value["NextKey"];

            if (!string.IsNullOrEmpty(ent.NextKey))
            {
                var next = mapParams.Bsp.Entities.FirstOrDefault(x => ent.NextKey.Equals(x["targetname"]));
                if (next != null)
                {
                    var nextOrigin = (SourceUtils.Vector3)next["origin"];
                    min = SourceUtils.Vector3.Min(min, nextOrigin);
                    max = SourceUtils.Vector3.Max(max, nextOrigin);
                }
            }

            var clusters = GetIntersectingClusters(mapParams.Tree, min, max);

            if (InitPvsEntity(ent, value, clusters) == null)
            {
                return(null);
            }

            ent.Width        = value["Width"];
            ent.TextureScale = value["TextureScale"];
            ent.SubDivisions = value["Subdiv"];
            ent.Slack        = value["Slack"];
            ent.RopeMaterial = MaterialDictionary.GetResourceIndex(mapParams.Bsp, value["RopeMaterial"]);
            ent.MoveSpeed    = value["MoveSpeed"];

            return(ent);
        }
예제 #9
0
        private static Worldspawn InitWorldspawn(Worldspawn ent, ValveBsp.Entities.Entity value, MapParams mapParams)
        {
            if (InitBrushEntity(ent, value, mapParams) == null)
            {
                return(null);
            }

            ent.SkyMaterial = Material.CreateSkyMaterial(mapParams.Bsp, value["skyname"]);

            return(ent);
        }
예제 #10
0
        private static BrushEntity InitBrushEntity(BrushEntity ent, ValveBsp.Entities.Entity value, MapParams mapParams)
        {
            if (value.TargetName != null && mapParams.AreaPortalNames.Contains(value.TargetName))
            {
                return(null);
            }

            var modelName = ent is Worldspawn ? "*0" : value["model"];

            if (modelName == null)
            {
                return(null);
            }

            var modelIndex = int.Parse(modelName.Substring(1));
            var model      = mapParams.Bsp.Models[modelIndex];

            var min = model.Min + value.Origin;
            var max = model.Max + value.Origin;

            var clusters = modelIndex == 0 ? null : GetIntersectingClusters(mapParams.Tree, min, max);

            if (InitPvsEntity(ent, value, clusters) == null)
            {
                return(null);
            }

            ent.Model = modelIndex;

            if (ent.GetType() == typeof(BrushEntity))
            {
                ent.ClassName = "func_brush";
            }

            return(ent);
        }
예제 #11
0
        public Map GetIndexJson([Url] string map)
        {
            var bsp = Program.GetMap(map);

            var ents      = new List <Entity>();
            var mapParams = new MapParams(bsp);

            foreach (var ent in bsp.Entities)
            {
                var inst = InitEntity(ent, mapParams);
                if (inst != null)
                {
                    ents.Add(inst);
                }
            }

            for (var dispIndex = 0; dispIndex < bsp.DisplacementInfos.Length; ++dispIndex)
            {
                SourceUtils.Vector3 min, max;
                GetDisplacementBounds(bsp, dispIndex, out min, out max, 1f);

                ents.Add(new Displacement
                {
                    ClassName = "displacement",
                    Index     = dispIndex,
                    Clusters  = GetIntersectingClusters(mapParams.Tree, min, max)
                });
            }

            for (var propIndex = 0; propIndex < bsp.StaticProps.PropCount; ++propIndex)
            {
                SourceUtils.Vector3 origin, angles;
                bsp.StaticProps.GetPropTransform(propIndex, out origin, out angles);

                StaticPropFlags flags;
                bool            solid;
                uint            diffuseMod;
                bsp.StaticProps.GetPropInfo(propIndex, out flags, out solid, out diffuseMod);

                int propModelIndex, skin;
                bsp.StaticProps.GetPropModelSkin(propIndex, out propModelIndex, out skin);

                var modelName  = bsp.StaticProps.GetModelName(propModelIndex);
                var modelIndex = StudioModelDictionary.GetResourceIndex(bsp, modelName);

                ents.Add(new StaticProp
                {
                    ClassName = "prop_static",
                    Origin    = origin,
                    Angles    = angles,
                    Flags     = flags,
                    Clusters  = bsp.StaticProps.GetPropLeaves(propIndex)
                                .Select(x => (int)bsp.Leaves[x].Cluster)
                                .Where(x => x != -1)
                                .Distinct(),
                    Model            = modelIndex,
                    VertLighting     = (flags & StaticPropFlags.NoPerVertexLighting) == 0 ? (int?)propIndex : null,
                    LightingOrigin   = (flags & StaticPropFlags.UseLightingOrigin) == 0 ? null : (Vector3?)bsp.StaticProps.GetLightingOrigin(propIndex),
                    AlbedoModulation = diffuseMod != 0xffffffff ? (uint?)diffuseMod : null
                });
            }

            return(new Map
            {
                Name = bsp.Name,
                LightmapUrl = $"/maps/{bsp.Name}/lightmap.json",
                VisPages = GetPageLayout(bsp, bsp.Visibility.NumClusters, VisPage.ClustersPerPage, "/geom/vispage"),
                AmbientPages = GetPageLayout(bsp, bsp.Leaves.Length, AmbientPage.LeavesPerPage, "/geom/ambientpage"),
                LeafPages = GetPageLayout(bsp, bsp.Leaves.Length, LeafGeometryPage.LeavesPerPage, "/geom/leafpage"),
                DispPages = GetPageLayout(bsp, bsp.DisplacementInfos.Length, DispGeometryPage.DisplacementsPerPage, "/geom/disppage"),
                MaterialPages = GetPageLayout(bsp, MaterialDictionary.GetResourceCount(bsp), MaterialPage.MaterialsPerPage, "/materials/matpage"),
                BrushModelPages = GetPageLayout(bsp, bsp.Models.Length, BspModelPage.FacesPerPage, "/geom/bsppage", i => bsp.Models[i].NumFaces),
                StudioModelPages = GetPageLayout(bsp, StudioModelDictionary.GetResourceCount(bsp), StudioModelPage.VerticesPerPage, "/geom/mdlpage", i => StudioModelDictionary.GetVertexCount(bsp, i)),
                VertexLightingPages = GetPageLayout(bsp, bsp.StaticProps.PropCount, VertexLightingPage.PropsPerPage, "/geom/vhvpage"),
                Entities = ents
            });
        }
예제 #12
0
        public override void Render(System.Drawing.Graphics g, SharpMap.Map map)
        {
            base.Render(g, map);

            Ptv.Controls.Map.XMap.XMapWSService svcMap = new Ptv.Controls.Map.XMap.XMapWSService();
            svcMap.Url = m_Url;

            if (!string.IsNullOrEmpty(User) && !string.IsNullOrEmpty(Password))
                svcMap.Credentials = new NetworkCredential(User, Password);

            BoundingBox bb = new BoundingBox();
            bb.leftTop = new Point();
            bb.leftTop.point = new PlainPoint();
            bb.leftTop.point.x = map.Envelope.Min.X;
            bb.leftTop.point.y = map.Envelope.Max.Y;
            bb.rightBottom = new Point();
            bb.rightBottom.point = new PlainPoint();
            bb.rightBottom.point.x = map.Envelope.Max.X;
            bb.rightBottom.point.y = map.Envelope.Min.Y;
            
            MapParams mapParams = new MapParams();
            mapParams.showScale = true;
            mapParams.useMiles = false;
            
            ImageInfo imageInfo = new ImageInfo();
            imageInfo.format = ImageFileFormat.PNG;
            imageInfo.height = map.Size.Height;
            imageInfo.width = map.Size.Width;

            switch (m_xMapServerMode)
            {
                case XMapServerMode.All:
                    {
                        Ptv.Controls.Map.XMap.Map xmap = svcMap.renderMapBoundingBox(bb, mapParams, imageInfo, null, true, null);

                        MemoryStream imageStream = new MemoryStream(xmap.image.rawImage);
                        System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream);
                        System.Drawing.Bitmap bmp = image as System.Drawing.Bitmap;
                        bmp.MakeTransparent(System.Drawing.Color.FromArgb(255, 254, 185));
                        g.DrawImageUnscaled(image, 0, 0);

                        return;
                    }
                case XMapServerMode.BackGround:
                    {
                        // render only backgound and street 
                        StaticLayer slTown = new StaticLayer();
                        slTown.visible = false;
                        slTown.name = "town";
                        slTown.detailLevel = 0;
                        slTown.category = -1;
                        StaticLayer slStreet = new StaticLayer();
                        slStreet.visible = true;
                        slStreet.name = "street";
                        slStreet.detailLevel = 0;
                        slStreet.category = -1;
                        StaticLayer slBackground = new StaticLayer();
                        slBackground.visible = true;
                        slBackground.name = "background";
                        slBackground.detailLevel = 0;
                        slBackground.category = -1;

                        Ptv.Controls.Map.XMap.Layer[] arrLayer = new Ptv.Controls.Map.XMap.Layer[] { slBackground, slStreet, slTown };

                        Ptv.Controls.Map.XMap.Map xmap = svcMap.renderMapBoundingBox(bb, mapParams, imageInfo, arrLayer, true, null);

                        MemoryStream imageStream = new MemoryStream(xmap.image.rawImage);
                        System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream);
                        System.Drawing.Bitmap bmp = image as System.Drawing.Bitmap;
                        g.DrawImageUnscaled(image, 0, 0); 
                        
                        return;
                    }
                case XMapServerMode.Overlay:
                    {
                        // render only town
                        StaticLayer slTown = new StaticLayer();
                        slTown.visible = true;
                        slTown.name = "town";
                        slTown.detailLevel = 0;
                        slTown.category = -1;
                        StaticLayer slStreet = new StaticLayer();
                        slStreet.visible = false;
                        slStreet.name = "street";
                        slStreet.detailLevel = 0;
                        slStreet.category = -1;
                        StaticLayer slBackground = new StaticLayer();
                        slBackground.visible = false;
                        slBackground.name = "background";
                        slBackground.detailLevel = 0;
                        slBackground.category = -1;

                        Ptv.Controls.Map.XMap.Layer[] arrLayer = new Ptv.Controls.Map.XMap.Layer[] { slBackground, slStreet, slTown };

                        Ptv.Controls.Map.XMap.Map xmap = svcMap.renderMapBoundingBox(bb, mapParams, imageInfo, arrLayer, true, null);

                        MemoryStream imageStream = new MemoryStream(xmap.image.rawImage);
                        System.Drawing.Image image = System.Drawing.Image.FromStream(imageStream);
                        System.Drawing.Bitmap bmp = image as System.Drawing.Bitmap;
                        // make map background color transparent
                        bmp.MakeTransparent(System.Drawing.Color.FromArgb(255, 254, 185));
                        g.DrawImageUnscaled(image, 0, 0); 
                        
                        return;
                    }
            }
        }
예제 #13
0
        /// <inheritdoc/>
        public override byte[] TryGetStreamInternal(double left, double top, double right, double bottom, int width, int height, out IEnumerable <IMapObject> mapObjects)
        {
            using (var service = new XMapWSServiceImpl(url))
            {
                if (!string.IsNullOrEmpty(User) && !string.IsNullOrEmpty(Password))
                {
                    service.PreAuthenticate = true;
                    service.Credentials     = new CredentialCache {
                        { new Uri(url), "Basic", new NetworkCredential(User, Password) }
                    };
                }

                var mapParams = new MapParams {
                    showScale = false, useMiles = false
                };
                var imageInfo = new ImageInfo {
                    format = ImageFileFormat.GIF, height = height, width = width
                };
                var bbox = new BoundingBox
                {
                    leftTop = new Point {
                        point = new PlainPoint {
                            x = left, y = top
                        }
                    },
                    rightBottom = new Point {
                        point = new PlainPoint {
                            x = right, y = bottom
                        }
                    }
                };

                var profile = string.Empty;
                var layers  = new List <Layer>();
                switch (mode)
                {
                case XMapMode.Street:     // only streets
                    profile = "ajax-bg";
                    layers.Add(new StaticPoiLayer {
                        name = "town", visible = false, category = -1, detailLevel = 0
                    });
                    layers.Add(new StaticPoiLayer {
                        name = "background", visible = false, category = -1, detailLevel = 0
                    });
                    break;

                case XMapMode.Town:     // only labels
                    profile = "ajax-fg";
                    break;

                case XMapMode.Custom:     // no base layer
                    profile = "ajax-fg";
                    layers.Add(new StaticPoiLayer {
                        name = "town", visible = false, category = -1, detailLevel = 0
                    });
                    layers.Add(new StaticPoiLayer {
                        name = "street", visible = false, category = -1, detailLevel = 0
                    });
                    layers.Add(new StaticPoiLayer {
                        name = "background", visible = false, category = -1, detailLevel = 0
                    });
                    break;

                case XMapMode.Background:     // only streets and polygons
                    profile = "ajax-bg";
                    layers.Add(new StaticPoiLayer {
                        name = "town", visible = false, category = -1, detailLevel = 0
                    });
                    break;
                }

                // add custom xmap layers
                if (CustomXMapLayers != null)
                {
                    // remove layers in the local 'layers' which are also defined as custom layers...
                    foreach (var customXMapLayers in CustomXMapLayers)
                    {
                        var xMapLayers = customXMapLayers; // Temporary variable needed for solving closure issues in the next code line
                        foreach (var layer in layers.Where(layer => layer.GetType() == xMapLayers.GetType() && layer.name == xMapLayers.name))
                        {
                            layers.Remove(layer);
                            break;
                        }
                    }

                    layers.AddRange(CustomXMapLayers);
                }

                if (!string.IsNullOrEmpty(CustomProfile))
                {
                    profile = CustomProfile;
                }

                var callerContextProps = new List <CallerContextProperty>
                {
                    new CallerContextProperty {
                        key = "CoordFormat", value = "PTV_MERCATOR"
                    },
                    new CallerContextProperty {
                        key = "Profile", value = profile
                    }
                };
                if (CustomCallerContextProperties != null)
                {
                    callerContextProps.AddRange(CustomCallerContextProperties);
                }

                if (!string.IsNullOrEmpty(ContextKey))
                {
                    callerContextProps.Add(new CallerContextProperty {
                        key = "ContextKey", value = ContextKey
                    });
                }

                var cc = new CallerContext {
                    wrappedProperties = callerContextProps.ToArray()
                };

                if (ReferenceTime.HasValue)
                {
                    mapParams.referenceTime = ReferenceTime.Value.ToString("o");
                }

                service.Timeout = 8000;
                var map = service.renderMapBoundingBox(bbox, mapParams, imageInfo, layers.ToArray(), true, cc);

#if DEBUG
                if (!BoundingBoxesAreEqual(bbox, map.visibleSection.boundingBox))
                {
                    IssueBoundingBoxWarning(bbox, map.visibleSection.boundingBox, width, height, profile);
                }
#endif

                mapObjects = map.wrappedObjects?
                             .Select(objects => objects.wrappedObjects?.Select(layerObject => new XMap1MapObject(objects, layerObject)))
                             .Where(objects => objects != null && objects.Any())
                             .SelectMany(objects => objects)
                             .ToArray();

                return(map.image.rawImage);
            }
        }
        private void UpdateMap()
        {
            var track       = Model?.Track;
            var plugin      = Model?.SelectedObject.CmPlugin;
            var leaderboard = plugin?.Leaderboard;

            if (track == null || leaderboard == null)
            {
                return;
            }

            if (_mapParams == null || _mapParams.Track != Model.Track)
            {
                _mapParams = new MapParams(Model.Track);
            }

            foreach (var image in TrackMapItems.Children.OfType <BetterImage>())
            {
                _mapItemPool.Add(image);
            }

            var mapWidth  = TrackMap.ActualWidth;
            var mapHeight = TrackMap.ActualHeight;

            foreach (var item in leaderboard.ConnectedOnly)
            {
                var driver   = item.Driver;
                var location = item.Location;
                if (driver == null || location.PositionX == 0f && location.PositionZ == 0f)
                {
                    continue;
                }

                var image = MapCreateItem(driver.CarSkin?.LiveryImage);
                if (image.Filename != driver.CarSkin?.LiveryImage)
                {
                    image.Filename    = driver.CarSkin?.LiveryImage;
                    image.DataContext = item;
                }
                if (image.Visibility != Visibility.Visible)
                {
                    image.Visibility = Visibility.Visible;
                }
                var transform = (TranslateTransform)image.RenderTransform;
                var newX      = _mapParams.GetRelativeX(location.PositionX) * mapWidth;
                var newY      = _mapParams.GetRelativeY(location.PositionZ) * mapHeight;
                if ((newX - transform.X).Abs() > 10 || (newY - transform.Y).Abs() > 10)
                {
                    transform.X = newX;
                    transform.Y = newY;
                }
                else
                {
                    transform.X += (newX - transform.X) * 0.2;
                    transform.Y += (newY - transform.Y) * 0.2;
                }
            }

            foreach (var image in _mapItemPool)
            {
                image.Visibility = Visibility.Collapsed;
            }
        }
예제 #15
0
        /// <summary>
        /// Checks if one or n certain layers are available or not.
        /// </summary>
        /// <param name="url">The url to the XMap instance.</param>
        /// <param name="contextKey">The used context key or null if none is used.</param>
        /// <param name="layers">The layers to check.</param>
        /// <param name="profile">The profile used to check the availability.</param>
        /// <param name="expectedErrorCode">The expected error code if the at least one layer does not exist.
        /// SoapExceptions carrying this error code will be caught and the return value of the method will be false.
        /// SoapExceptions carrying another error code will not be caught and thus be thrown by this API.
        /// </param>
        /// <param name="xServerUser">User name needed for Azure Cloud.</param>
        /// <param name="xServerPassword">Password needed for Azure Cloud.</param>
        /// <returns>True if one or n layers are available, false if at least one layer is not available.
        /// May throw exceptions in case of malformed url or wrong contextKey definition.</returns>
        public static bool AreXMapLayersAvailable(string url, string contextKey, Layer[] layers, string profile, string expectedErrorCode, string xServerUser = null, string xServerPassword = null)
        {
            string key = url + profile;

            key = layers.Aggregate(key, (current, l) => current + "_" + l.name);

            if (CheckedXMapLayers.ContainsKey(key) && CheckedXMapLayers[key] != null)
            {
                return(CheckedXMapLayers[key].Value);
            }

            try
            {
                Service = Service ?? new XMapWSServiceImpl(url);

                if (!string.IsNullOrEmpty(xServerUser) && !string.IsNullOrEmpty(xServerPassword))
                {
                    ((SoapHttpClientProtocol)Service).PreAuthenticate = true;
                    ((SoapHttpClientProtocol)Service).Credentials     = new CredentialCache {
                        { new Uri(url), "Basic", new NetworkCredential(xServerUser, xServerPassword) }
                    };
                }

                var mapParams = new MapParams {
                    showScale = false, useMiles = false
                };
                var imageInfo = new ImageInfo {
                    format = ImageFileFormat.GIF, height = 32, width = 32
                };
                var bbox = new BoundingBox
                {
                    leftTop = new xserver.Point {
                        point = new PlainPoint {
                            x = 0, y = 10
                        }
                    },
                    rightBottom = new xserver.Point {
                        point = new PlainPoint {
                            x = 0, y = 10
                        }
                    }
                };

                var callerContextProps = new List <CallerContextProperty>
                {
                    new CallerContextProperty {
                        key = "CoordFormat", value = "PTV_MERCATOR"
                    },
                    new CallerContextProperty {
                        key = "Profile", value = profile
                    }
                };
                if (!string.IsNullOrEmpty(contextKey))
                {
                    callerContextProps.Add(new CallerContextProperty {
                        key = "ContextKey", value = contextKey
                    });
                }

                var cc = new CallerContext {
                    wrappedProperties = callerContextProps.ToArray()
                };

                try
                {
                    Service.renderMapBoundingBox(bbox, mapParams, imageInfo, layers, true, cc);
                }
                catch (SoapException se)
                {
                    if (!se.Code.Name.Equals(expectedErrorCode))
                    {
                        throw;
                    }

                    CheckedXMapLayers.Add(key, false);
                    return(false);
                }

                CheckedXMapLayers.Add(key, true);
                return(true);
            }
            finally
            {
                (Service as IDisposable)?.Dispose();
                Service = null;
            }
        }
예제 #16
0
        /// <inheritdoc/>
        public override byte[] TryGetStreamInternal(double left, double top, double right, double bottom, int width,
                                                    int height, out IEnumerable <IMapObject> mapObjects)
        {
            using (var service = new XMapWSServiceImpl(url))
            {
                var mapParams = new MapParams {
                    showScale = false, useMiles = false
                };
                var imageInfo = new ImageInfo {
                    format = ImageFileFormat.GIF, height = height, width = width
                };

                var bbox = new BoundingBox
                {
                    leftTop = new Point {
                        point = new PlainPoint {
                            x = left, y = top
                        }
                    },
                    rightBottom = new Point {
                        point = new PlainPoint {
                            x = right, y = bottom
                        }
                    }
                };

                var profile = CustomProfile == null ? "ajax-av" : CustomProfile;

                var ccProps = new List <CallerContextProperty>
                {
                    new CallerContextProperty {
                        key = "CoordFormat", value = "PTV_MERCATOR"
                    },
                    new CallerContextProperty {
                        key = "Profile", value = profile
                    }
                };

                if (!string.IsNullOrEmpty(ContextKey))
                {
                    ccProps.Add(new CallerContextProperty {
                        key = "ContextKey", value = ContextKey
                    });
                }

                if (CustomCallerContextProperties != null)
                {
                    ccProps.AddRange(CustomCallerContextProperties);
                }

                var cc = new CallerContext
                {
                    wrappedProperties = ccProps.ToArray()
                };


                if (!string.IsNullOrEmpty(User) && !string.IsNullOrEmpty(Password))
                {
                    service.PreAuthenticate = true;

                    var credentialCache = new System.Net.CredentialCache
                    {
                        { new Uri(url), "Basic", new System.Net.NetworkCredential(User, Password) }
                    };

                    service.Credentials = credentialCache;
                }

                var map = service.renderMapBoundingBox(bbox, mapParams, imageInfo,
                                                       CustomXMapLayers != null ? CustomXMapLayers.ToArray() : null,
                                                       true, cc);

                mapObjects = map.wrappedObjects?
                             .Select(objects =>
                                     objects.wrappedObjects?.Select(layerObject =>
                                                                    (IMapObject) new XMap1MapObject(objects, layerObject)))
                             .Where(objects => objects != null && objects.Any())
                             .SelectMany(objects => objects);

                return(map.image.rawImage);
            }
        }