Ejemplo n.º 1
0
    /// <summary>
    /// mode = true, uses the movementMap. mode = false, uses the unitOcupationMap
    /// </summary>
    public static Hex FindClosestOpenHex(FractionalHex position, RuntimeMap map, bool mode)
    {
        Dictionary <Hex, bool> mapValuesToUse;

        if (mode)
        {
            mapValuesToUse = new Dictionary <Hex, bool>(map.MovementMapValues);
        }
        else
        {
            mapValuesToUse = new Dictionary <Hex, bool>(map.UnitsMapValues);
        }

        var   closestOpenHex         = Hex.Zero;
        Fix64 closestOpenHexDistance = Fix64.MaxValue;

        foreach (var hexValuePair in mapValuesToUse)
        {
            if (!hexValuePair.Value)
            {
                continue;
            }

            var hex      = hexValuePair.Key;
            var distance = position.Distance((FractionalHex)hex);

            if (distance <= closestOpenHexDistance)
            {
                closestOpenHex         = hex;
                closestOpenHexDistance = distance;
            }
        }

        return(closestOpenHex);
    }
Ejemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string agent = ConfigurationManager.AppSettings["MapAgentUrl"];

            IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
                "Maestro.Http",
                "Url", agent,
                "SessionId", Request.Params["SESSION"]);

            IMappingService mpSvc   = (IMappingService)conn.GetService((int)ServiceType.Mapping);
            string          rtMapId = "Session:" + conn.SessionID + "//" + Request.Params["MAPNAME"] + ".Map";

            RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);

            string xml = Request.Params["SELECTION"];

            //The map selection contains one or more layer selections
            //each containing a one or more sets of identity property values
            //(because a feature may have multiple identity properties)

            MapSelection selection = new MapSelection(rtMap, HttpUtility.UrlDecode(xml));

            if (selection.Count > 0)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < selection.Count; i++)
                {
                    MapSelection.LayerSelection layerSel = selection[i];
                    sb.Append("<p>Layer: " + layerSel.Layer.Name + " (" + layerSel.Count + " selected item)");
                    sb.Append("<table>");

                    for (int j = 0; j < layerSel.Count; j++)
                    {
                        sb.Append("<tr>");
                        object[] values = layerSel[j];
                        for (int k = 0; k < values.Length; k++)
                        {
                            sb.Append("<td>");
                            sb.Append(values[k].ToString());
                            sb.Append("</td>");
                        }
                        sb.AppendFormat("<td><a href='FeatureInfo.aspx?MAPNAME={0}&SESSION={1}&LAYERID={2}&ID={3}'>More Info</a></td>",
                                        rtMap.Name,
                                        conn.SessionID,
                                        layerSel.Layer.ObjectId,
                                        HttpUtility.UrlEncode(layerSel.EncodeIDString(values)));
                        sb.Append("</tr>");
                    }
                    sb.Append("</table>");

                    lblMessage.Text = "Showing IDs of selected features";

                    result.InnerHtml = sb.ToString();
                }
            }
            else
            {
                lblMessage.Text = "Nothing selected. Select some features first then run this sample again.";
            }
        }
Ejemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string agent = ConfigurationManager.AppSettings["MapAgentUrl"];

            IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
                "Maestro.Http",
                "Url", agent,
                "SessionId", Request.Params["SESSION"]);

            IMappingService mpSvc   = (IMappingService)conn.GetService((int)ServiceType.Mapping);
            string          rtMapId = "Session:" + conn.SessionID + "//" + Request.Params["MAPNAME"] + ".Map";

            RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);

            RuntimeMapGroup group = rtMap.Groups[Request.Params["GROUPNAME"]];

            if (group != null)
            {
                group.Visible = !group.Visible;

                rtMap.Save(); //Always save changes after modifying

                Page.ClientScript.RegisterStartupScript(
                    this.GetType(),
                    "load",
                    "<script type=\"text/javascript\"> window.onload = function() { parent.parent.Refresh(); } </script>");

                lblMessage.Text = "Group (" + group.Name + ") visible: " + group.Visible;
            }
            else
            {
                lblMessage.Text = "Group (" + group.Name + ") not found!";
            }
        }
Ejemplo n.º 4
0
 private static bool SupportsMutableMapProperties(RuntimeMap runtimeMap)
 {
     return(runtimeMap.SupportsMutableBackgroundColor &&
            runtimeMap.SupportsMutableCoordinateSystem &&
            runtimeMap.SupportsMutableExtents &&
            runtimeMap.SupportsMutableMetersPerUnit);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RuntimeMapLayer"/> class.
 /// </summary>
 /// <param name="parent">The parent.</param>
 /// <param name="ldf">The Layer Definition.</param>
 /// <param name="suppressErrors">If true, any errors while creating the layer are suppressed. The nature of the error may result in un-selectable layers</param>
 protected internal RuntimeMapLayer(RuntimeMap parent, ILayerDefinition ldf, bool suppressErrors)
     : this(parent)
 {
     _disableChangeTracking = true;
     Initialize(ldf, suppressErrors);
     _disableChangeTracking = false;
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance
 /// </summary>
 /// <param name="parent"></param>
 /// <param name="source"></param>
 /// <param name="ldf"></param>
 /// <param name="suppressErrors"></param>
 protected internal RuntimeMapLayer(RuntimeMap parent, IBaseMapLayer source, ILayerDefinition ldf, bool suppressErrors)
     : this(parent, ldf, suppressErrors)
 {
     Check.ArgumentNotNull(source, nameof(source));
     Check.ArgumentNotNull(ldf, nameof(ldf));
     Check.ThatPreconditionIsMet(source.ResourceId == ldf.ResourceID, $"{nameof(source)}.{nameof(source.ResourceId)} == {nameof(ldf)}.{nameof(ldf.ResourceID)}");
 }
Ejemplo n.º 7
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            _rtMap = null;
            SetSelectedObject(null);
            trvLayersAndGroups.Nodes.Clear();
            lstDrawOrder.Items.Clear();
            trvSelection.Nodes.Clear();
            if (rdMapName.Checked)
            {
                _rtMap = _mappingSvc.OpenMap($"Session:{txtSessionId.Text}//{txtMapName.Text}.Map"); //NOXLATE
            }
            else if (rdResourceId.Checked)
            {
                _rtMap = _mappingSvc.OpenMap(txtResourceId.Text);
            }

            if (_rtMap == null)
            {
                btnMapImage.Enabled = false;
                MessageBox.Show(Strings.ErrFailedRuntimeMapOpen);
                return;
            }
            btnMapImage.Enabled = true;
            InitTabs();
        }
Ejemplo n.º 8
0
        static RuntimeMapGroup CreateGroup(RuntimeMap map, IBaseMapGroup grp)
        {
            var ctor  = typeof(RuntimeMapGroup).GetInternalConstructor(new[] { typeof(RuntimeMap), typeof(IBaseMapGroup) });
            var group = ctor.Invoke(new object[] { map, grp }) as RuntimeMapGroup;

            return(group);
        }
Ejemplo n.º 9
0
        static RuntimeMapGroup CreateGroup(RuntimeMap map, string name)
        {
            var ctor  = typeof(RuntimeMapGroup).GetInternalConstructor(new[] { typeof(RuntimeMap), typeof(string) });
            var group = ctor.Invoke(new object[] { map, name }) as RuntimeMapGroup;

            return(group);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RuntimeMapGroup"/> class.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="name">The name.</param>
        protected internal RuntimeMapGroup(RuntimeMap map, string name)
            : this()
        {
            this.Parent = map;
            this.Name   = name;

            _disableChangeTracking = false;
        }
Ejemplo n.º 11
0
        protected void btnDescribe_Click(object sender, EventArgs e)
        {
            string agent = ConfigurationManager.AppSettings["MapAgentUrl"];

            MAPNAME.Value = Request.Params["MAPNAME"];
            SESSION.Value = Request.Params["SESSION"];

            IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
                "Maestro.Http",
                "Url", agent,
                "SessionId", SESSION.Value);

            IMappingService mpSvc   = (IMappingService)conn.GetService((int)ServiceType.Mapping);
            string          rtMapId = "Session:" + conn.SessionID + "//" + MAPNAME.Value + ".Map";

            RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);

            //Get the selected layer
            RuntimeMapLayer rtLayer = rtMap.Layers.GetByObjectId(ddlLayers.SelectedValue);

            //Get the class definition
            ClassDefinition clsDef = conn.FeatureService.GetClassDefinition(rtLayer.FeatureSourceID, rtLayer.QualifiedClassName);

            StringBuilder sb = new StringBuilder();

            sb.Append("<h3>Layer Properties</h3><hr/>");
            sb.Append("<p>Name: " + rtLayer.Name + "</p>");
            sb.Append("<p>Legend Label: " + rtLayer.LegendLabel + "</p>");
            sb.Append("<p>Display Level: " + rtLayer.DisplayOrder + "</p>");
            sb.Append("<p>Expand In Legend: " + rtLayer.ExpandInLegend + "</p>");
            sb.Append("<p>Show In Legend: " + rtLayer.ShowInLegend + "</p>");
            sb.Append("<p>Visible: " + rtLayer.Visible + "</p>");
            sb.Append("<p>Layer Definition: " + rtLayer.LayerDefinitionID + "</p>");
            sb.Append("<p>Has Tooltips: " + rtLayer.HasTooltips + "</p>");
            sb.Append("<p>Filter: " + rtLayer.Filter + "</p>");

            sb.Append("<h3>Class Definition</h3><hr/>");

            sb.Append("<p>Schema: " + clsDef.QualifiedName.Split(':')[0] + "</p>");
            sb.Append("<p>Class Name: " + clsDef.Name + "</p>");
            sb.Append("<strong>Properties (* indicates identity):</strong>");
            sb.Append("<ul>");
            for (int i = 0; i < clsDef.Properties.Count; i++)
            {
                PropertyDefinition prop = clsDef.Properties[i];
                bool isIdentity         = false;

                if (prop.Type == PropertyDefinitionType.Data)
                {
                    isIdentity = clsDef.IdentityProperties.Contains((DataPropertyDefinition)prop);
                }
                string name = (isIdentity ? "* " + prop.Name : prop.Name);
                sb.AppendFormat("<li><p>Name: {0}</p><p>Type: {1}</p></li>", name, prop.Type.ToString());
            }
            sb.Append("</ul>");

            classDef.InnerHtml = sb.ToString();
        }
Ejemplo n.º 12
0
        }                                        //For mock support

        /// <summary>
        /// Initializes this instance
        /// </summary>
        /// <param name="parent"></param>
        protected internal RuntimeMapLayer(RuntimeMap parent)
        {
            _scaleRanges            = new double[] { 0.0, InfinityScale };
            _type                   = RuntimeMapLayerType.Dynamic;
            this.IdentityProperties = new PropertyInfo[0];
            _objectId               = Guid.NewGuid().ToString();
            this.Parent             = parent;
            _group                  = string.Empty;
        }
Ejemplo n.º 13
0
    public void LinePath()
    {
        var geoMap = new Dictionary <Hex, GeographicTile>
        {
            {
                new Hex(0, 0),
                new GeographicTile()
                {
                    heightLevel = MapHeight.l0,
                    walkable    = false
                }
            },
            {
                new Hex(1, -1),
                new GeographicTile()
                {
                    heightLevel = MapHeight.l0,
                    walkable    = true
                }
            },
            {
                new Hex(1, 0),
                new GeographicTile()
                {
                    heightLevel = MapHeight.l0,
                    walkable    = true
                }
            },
            {
                new Hex(0, 1),
                new GeographicTile()
                {
                    heightLevel = MapHeight.l0,
                    walkable    = true
                }
            }
        };
        RuntimeMap map       = new RuntimeMap(geoMap, 100);
        var        layout    = new Layout(Orientation.pointy, new FixVector2(1, 1), new FixVector2(0, 0));
        ActiveMap  activeMap = new ActiveMap(map, layout);

        var simplifiedPath = PathFindingSystem.HexFunnelAlgorithm
                             (
            new List <Hex>()
        {
            new Hex(0, 1),
            new Hex(1, 0),
            new Hex(1, -1)
        }, true, activeMap
                             );


        Assert.AreEqual(2, simplifiedPath.Count);
        Assert.AreEqual(new Hex(1, 0), simplifiedPath[0]);
        Assert.AreEqual(new Hex(1, -1), simplifiedPath[1]);
    }
Ejemplo n.º 14
0
        /// <summary>
        /// Initializes a new instance
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="source"></param>
        /// <param name="ldf"></param>
        /// <param name="suppressErrors"></param>
        protected internal RuntimeMapLayer(RuntimeMap parent, IMapLayer source, ILayerDefinition ldf, bool suppressErrors)
            : this(parent, (IBaseMapLayer)source, ldf, suppressErrors)
        {
            _disableChangeTracking = true;

            this.Group = source.Group;
            _visible   = source.Visible;

            _disableChangeTracking = false;
        }
Ejemplo n.º 15
0
        internal RuntimeMap Read()
        {
            _map = new RuntimeMap(_deployment, ReadRegions());

            RegisterTypes();

            RegisterAreaDependencies();

            return(_map);
        }
Ejemplo n.º 16
0
        static RuntimeMapLayer CreateLayer(RuntimeMap map, string name, string ldfId)
        {
            var ctor  = typeof(RuntimeMapLayer).GetInternalConstructor(new[] { typeof(RuntimeMap) });
            var layer = ctor.Invoke(new[] { map }) as RuntimeMapLayer;

            layer.Name = name;
            var pi = layer.GetType().GetProperty(nameof(layer.LayerDefinitionID));

            pi.SetValue(layer, ldfId);
            return(layer);
        }
        protected void btnSelect_Click(object sender, EventArgs e)
        {
            string agent = ConfigurationManager.AppSettings["MapAgentUrl"];

            MAPNAME.Value = Request.Params["MAPNAME"];
            SESSION.Value = Request.Params["SESSION"];

            IServerConnection conn = ConnectionProviderRegistry.CreateConnection(
                "Maestro.Http",
                "Url", agent,
                "SessionId", SESSION.Value);

            IMappingService mpSvc   = (IMappingService)conn.GetService((int)ServiceType.Mapping);
            string          rtMapId = "Session:" + conn.SessionID + "//" + MAPNAME.Value + ".Map";

            RuntimeMap rtMap = mpSvc.OpenMap(rtMapId);

            //Get the selected layer
            RuntimeMapLayer rtLayer = rtMap.Layers.GetByObjectId(ddlLayers.SelectedValue);

            //Query using the user filter
            IFeatureReader reader = conn.FeatureService.QueryFeatureSource(
                rtLayer.FeatureSourceID,
                rtLayer.QualifiedClassName,
                txtFilter.Text);

            //Get the selection set
            MapSelection sel = new MapSelection(rtMap);

            MapSelection.LayerSelection layerSel = null;
            if (!sel.Contains(rtLayer))
            {
                sel.Add(rtLayer);
            }
            layerSel = sel[rtLayer];

            //Clear any existing selections
            layerSel.Clear();

            //Populate selection set with query result
            int added = layerSel.AddFeatures(reader, -1);

            //Generate selection string
            string selXml = sel.ToXml();

            //Generate a client-side set selection and execute a "Zoom to Selection" afterwards
            Page.ClientScript.RegisterStartupScript(
                this.GetType(),
                "load",
                "<script type=\"text/javascript\"> window.onload = function() { parent.parent.GetMapFrame().SetSelectionXML('" + selXml + "'); parent.parent.ExecuteMapAction(10); } </script>");


            lblMessage.Text = added + " features in " + rtLayer.Name + " selected";
        }
 public MapPreviewViewContent(RuntimeMap map, IUrlLauncherService urlLauncher, string resourceId)
 {
     InitializeComponent();
     _map        = map;
     _resourceId = resourceId;
     txtCoordinateSystem.Text = map.CoordinateSystem;
     numZoomToScale.Minimum   = 1;
     numZoomToScale.Maximum   = Int32.MaxValue;
     _launcher            = urlLauncher;
     _conn                = map.CurrentConnection;
     btnGetMapKml.Enabled = (_conn.ProviderName.ToUpper() == "MAESTRO.HTTP"); //NOXLATE
 }
Ejemplo n.º 19
0
        private static RuntimeMap CreateTestMap()
        {
            var layers = new Dictionary <string, ILayerDefinition>();
            var mdf    = (IMapDefinition)ObjectFactory.Deserialize(ResourceTypes.MapDefinition.ToString(), Utils.OpenFile("UserTestData\\TestTiledMap.xml"));

            mdf.ResourceID = "Library://UnitTest/Test.MapDefinition";
            foreach (var lyr in mdf.BaseMap.BaseMapLayerGroups.First().BaseMapLayer)
            {
                var ldf = ObjectFactory.CreateDefaultLayer(LayerType.Vector, new Version(1, 0, 0));
                ldf.ResourceID = lyr.ResourceId;
                layers.Add(lyr.ResourceId, ldf);
            }
            var conn   = new Mock <IServerConnection>();
            var mapSvc = new Mock <IMappingService>();
            var resSvc = new Mock <IResourceService>();
            var caps   = new Mock <IConnectionCapabilities>();

            foreach (var kvp in layers)
            {
                resSvc.Setup(r => r.GetResource(kvp.Key)).Returns(kvp.Value);
            }
            resSvc.Setup(r => r.GetResource("Library://UnitTest/Test.MapDefinition")).Returns(mdf);

            foreach (var kvp in layers)
            {
                mapSvc.Setup(m => m.CreateMapLayer(It.IsAny <RuntimeMap>(), It.IsAny <IBaseMapLayer>()))
                .Returns((RuntimeMap rtMap, IBaseMapLayer rl) => new RuntimeMapLayer(rtMap)
                {
                    Name = rl.Name, LayerDefinitionID = kvp.Key
                });
            }
            mapSvc.Setup(m => m.CreateMapGroup(It.IsAny <RuntimeMap>(), It.IsAny <IBaseMapGroup>()))
            .Returns((RuntimeMap rtMap, IBaseMapGroup grp) => new RuntimeMapGroup(rtMap, grp));
            mapSvc.Setup(m => m.CreateMapGroup(It.IsAny <RuntimeMap>(), It.IsAny <string>()))
            .Returns((RuntimeMap rtMap, string name) => new RuntimeMapGroup(rtMap, name));

            caps.Setup(c => c.SupportedServices).Returns(new int[] { (int)ServiceType.Mapping });
            caps.Setup(c => c.SupportedCommands).Returns(new int[0]);
            caps.Setup(c => c.GetMaxSupportedResourceVersion(It.IsAny <string>())).Returns(new Version(1, 0, 0));

            conn.Setup(c => c.Capabilities).Returns(caps.Object);
            conn.Setup(c => c.ResourceService).Returns(resSvc.Object);
            conn.Setup(c => c.GetService((int)ServiceType.Mapping)).Returns(mapSvc.Object);

            var map = new RuntimeMap(conn.Object, mdf, 1.0, true);

            Assert.AreEqual(15, map.FiniteDisplayScaleCount);
            Assert.NotNull(map.Layers);
            Assert.NotNull(map.Groups);
            return(map);
        }
Ejemplo n.º 20
0
        internal RuntimeMapGroup(RuntimeMap map, IBaseMapGroup group)
            : this(map, group.Name)
        {
            _disableChangeTracking = true;

            this.ExpandInLegend = group.ExpandInLegend;
            this.LegendLabel    = group.LegendLabel;
            this.ShowInLegend   = group.ShowInLegend;
            this.Visible        = group.Visible;

            this.Type = kBaseMap;

            _disableChangeTracking = false;
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RuntimeMapGroup"/> class.
        /// </summary>
        /// <param name="map">The map.</param>
        /// <param name="group">The group.</param>
        protected internal RuntimeMapGroup(RuntimeMap map, IMapLayerGroup group)
            : this(map, group.Name)
        {
            _disableChangeTracking = true;

            this.Group          = group.Group;
            this.ExpandInLegend = group.ExpandInLegend;
            this.LegendLabel    = group.LegendLabel;
            this.ShowInLegend   = group.ShowInLegend;
            this.Visible        = group.Visible;

            this.Type = kNormal;

            _disableChangeTracking = false;
        }
 public MapPreviewDialog(RuntimeMap map, IUrlLauncherService urlLauncher, string resourceId)
 {
     InitializeComponent();
     _map = map;
     if (!string.IsNullOrEmpty(resourceId))
     {
         this.Text += $" - {resourceId}"; //NOXLATE
     }
     txtCoordinateSystem.Text = map.CoordinateSystem;
     numZoomToScale.Minimum   = 1;
     numZoomToScale.Maximum   = Int32.MaxValue;
     _launcher            = urlLauncher;
     _conn                = map.CurrentConnection;
     btnGetMapKml.Enabled = (_conn.ProviderName.ToUpper() == "MAESTRO.HTTP"); //NOXLATE
 }
Ejemplo n.º 23
0
        private void MakeTempMap()
        {
            if (m_tempmap == null)
            {
                IMapDefinition m = Utility.CreateMapDefinition(m_connection, string.Empty);
                m.CoordinateSystem = @"LOCAL_CS[""*XY-M*"", LOCAL_DATUM[""*X-Y*"", 10000], UNIT[""Meter"", 1], AXIS[""X"", EAST], AXIS[""Y"", NORTH]]"; //NOXLATE
                m.SetExtents(-1, -1, 1, 1);

                //AIMS 2012 demands this checks out. Can't flub it anymore
                m.ResourceID = "Session:" + m_connection.SessionID + "//non-existing.MapDefinition"; //NOXLATE
                var mpsvc = (IMappingService)m_connection.GetService((int)ServiceType.Mapping);
                var rid   = new ResourceIdentifier(Guid.NewGuid().ToString(), ResourceTypes.Map, m_connection.SessionID);

                m_tempmap = mpsvc.CreateMap(m);
            }
        }
Ejemplo n.º 24
0
    public void TheSlopeEdgeOfASlopeAndOtherSlopeEdgeOfTheSameHeightAreTraversables()
    {
        var geoMap = new Dictionary <Hex, GeographicTile>
        {
            {
                new Hex(0, 0),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l3 | MapHeight.l4,
                    slopeData   = new SlopeData()
                    {
                        isSlope        = true,
                        heightSide_0tr = MapHeight.l3,
                        heightSide_1r  = MapHeight.l3 | MapHeight.l4,
                        heightSide_2dr = MapHeight.l4,
                        heightSide_3dl = MapHeight.l4,
                        heightSide_4l  = MapHeight.l3 | MapHeight.l4,
                        heightSide_5tl = MapHeight.l3
                    }
                }
            },
            {
                new Hex(1, 0),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l3 | MapHeight.l4,
                    slopeData   = new SlopeData()
                    {
                        isSlope        = true,
                        heightSide_0tr = MapHeight.l3,
                        heightSide_1r  = MapHeight.l3 | MapHeight.l4,
                        heightSide_2dr = MapHeight.l4,
                        heightSide_3dl = MapHeight.l4,
                        heightSide_4l  = MapHeight.l3 | MapHeight.l4,
                        heightSide_5tl = MapHeight.l3
                    }
                }
            }
        };
        RuntimeMap map       = new RuntimeMap(geoMap, 100);
        var        layout    = new Layout(Orientation.pointy, new FixVector2(1, 1), new FixVector2(0, 0));
        ActiveMap  activeMap = new ActiveMap(map, layout);

        Assert.IsTrue(MapUtilities.IsTraversable(new Hex(0, 0), new Hex(1, 0), MapUtilities.MapType.GEOGRAPHYC, activeMap));
    }
Ejemplo n.º 25
0
    /// <summary>
    /// A new destination is needed if you cannot reach the destination or if its occupied
    /// </summary>
    private static bool NewDestinationNeeded(FractionalHex startPos, Hex end, RuntimeMap map, out Hex newDestination)
    {
        Hex startHex = startPos.Round();

        newDestination = end;
        bool destinationIsAvalible = MapUtilities.HexIsOpenAndReachable(startHex, end, map.UnitsMapValues);// HexIsFreeAndReachable(startHex, end, map);

        if (!destinationIsAvalible)
        {
            MapUtilities.TryFindClosestOpenAndReachableHex(out newDestination, (FractionalHex)end, (FractionalHex)startHex, map.UnitsMapValues);
            return(true);
        }
        else
        {
            return(false);
        }
    }
        /// <summary>
        /// Binds the specified editor service to this editor
        /// </summary>
        /// <param name="service"></param>
        public override void Bind(IEditorService service)
        {
            this.EditorService = service;
            service.RegisterCustomNotifier(this);

            _shadowCopy = (IMapDefinition)service.GetEditedResource();
            _mapSvc     = (IMappingService)service.CurrentConnection.GetService((int)ServiceType.Mapping);
            _rtMap      = _mapSvc.CreateMap(_shadowCopy);
            repoView.Init(service.CurrentConnection.ResourceService, new string[] {
                ResourceTypes.LayerDefinition.ToString(),
                ResourceTypes.FeatureSource.ToString()
            }, new string[] {
                ResourceTypes.LayerDefinition.ToString(),
                ResourceTypes.FeatureSource.ToString()
            });

            ReloadViewer();
        }
        //This method dumps the runtime state of the map. I personally
        //used this method to debug this sample as I was developing it.
        //
        //It's been kept here for reference.
        private void DumpMap(RuntimeMap rtMap)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<p>Debugging</p>");
            sb.Append("Name: " + rtMap.Name + "<br/>");
            sb.Append("Layers: <br/>");
            sb.Append("<ul>");
            foreach (var layer in rtMap.Layers)
            {
                sb.Append("<li>Name: " + layer.Name + " (Selectable: " + layer.Selectable + ", Visible: " + layer.Visible + ")<br/>");
                sb.Append("Group: " + layer.Group + "<br/>");
                sb.Append("Draw Order: " + layer.DisplayOrder + "</li>");
            }
            sb.Append("</ul>");

            debug.InnerHtml = sb.ToString();
        }
Ejemplo n.º 28
0
    public void TestElevatioFunction_OnDouble_T()
    {
        var geoMap = new Dictionary <Hex, GeographicTile>
        {
            {
                new Hex(0, 0),
                new GeographicTile()
                {
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope        = true,
                        heightSide_0tr = MapHeight.l1,
                        heightSide_1r  = MapHeight.l0,
                        heightSide_2dr = MapHeight.l0,
                        heightSide_3dl = MapHeight.l0,
                        heightSide_4l  = MapHeight.l0,
                        heightSide_5tl = MapHeight.l1
                    }
                }
            }
        };
        RuntimeMap map       = new RuntimeMap(geoMap, 100);
        var        layout    = new Layout(Orientation.pointy, new FixVector2(1, 1), new FixVector2(0, 0));
        ActiveMap  activeMap = new ActiveMap(map, layout);


        var elevation1 = MapUtilities.GetElevationOfPosition(new FractionalHex(Fix64.Zero, Fix64.Zero), activeMap);
        var elevation2 = MapUtilities.GetElevationOfPosition(new FractionalHex(-(Fix64)0.2886835f, (Fix64)0.577367f, -(Fix64)0.2886835f), activeMap);
        var elevation3 = MapUtilities.GetElevationOfPosition(new FractionalHex((Fix64)0.2886835f, -(Fix64)0.577367f, (Fix64)0.2886835f), activeMap);
        var elevation4 = MapUtilities.GetElevationOfPosition(new FractionalHex((Fix64)0.2886835f, (Fix64)0.2886835f, -(Fix64)0.577367f), activeMap);

        //var elevation5 = activeMap.GetElevationOfPosition(new FractionalHex(-(Fix64)0.5f, Fix64.Zero, (Fix64)0.5));
        //var elevation6 = activeMap.GetElevationOfPosition(new FractionalHex(-(Fix64)0.25f, Fix64.Zero, (Fix64)0.25f));

        Assert.AreEqual(50, elevation1);
        Assert.AreEqual(100, elevation2);
        Assert.AreEqual(0, elevation3);
        Assert.AreEqual(100, elevation4);
        //Assert.AreEqual(0, elevation5);
        //Assert.AreEqual(0, elevation6);
    }
Ejemplo n.º 29
0
    public void SlopeEdgeAndTileOfDiferentHeightAreNotTraversables()
    {
        var geoMap = new Dictionary <Hex, GeographicTile>
        {
            {
                new Hex(0, 1),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope = false,
                    }
                }
            },
            {
                new Hex(0, 0),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope        = true,
                        heightSide_0tr = MapHeight.l1,
                        heightSide_1r  = MapHeight.l1,
                        heightSide_2dr = MapHeight.l0 | MapHeight.l1,
                        heightSide_3dl = MapHeight.l0,
                        heightSide_4l  = MapHeight.l0,
                        heightSide_5tl = MapHeight.l0 | MapHeight.l1
                    }
                }
            }
        };
        RuntimeMap map       = new RuntimeMap(geoMap, 100);
        var        layout    = new Layout(Orientation.pointy, new FixVector2(1, 1), new FixVector2(0, 0));
        ActiveMap  activeMap = new ActiveMap(map, layout);


        Assert.IsFalse(MapUtilities.IsTraversable(new Hex(0, 1), new Hex(0, 0), MapUtilities.MapType.GEOGRAPHYC, activeMap));
    }
Ejemplo n.º 30
0
    public void  UnitMap_NotWalkableTilesAreNotTraversables()
    {
        var geoMap = new Dictionary <Hex, GeographicTile>
        {
            {
                new Hex(0, 0),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope = false,
                    }
                }
            },
            {
                new Hex(-1, 1),
                new GeographicTile()
                {
                    walkable    = true,
                    heightLevel = MapHeight.l0,
                    slopeData   = new SlopeData()
                    {
                        isSlope = false,
                    }
                }
            }
        };
        RuntimeMap map       = new RuntimeMap(geoMap, 100);
        var        layout    = new Layout(Orientation.pointy, new FixVector2(1, 1), new FixVector2(0, 0));
        ActiveMap  activeMap = new ActiveMap(map, layout);

        activeMap.map.SetUnitOcupationMapValue(new Hex(0, 0), false);


        Assert.IsFalse(MapUtilities.IsTraversable(new Hex(-1, 1), new Hex(0, 0), MapUtilities.MapType.UNIT, activeMap));
    }
Ejemplo n.º 31
0
 private static void RenderLegendAndVerifyConvenience(RuntimeMap map, int width, int height, string fileName, string format)
 {
     using (var stream = map.RenderMapLegend(width, height, Color.White, format))
     {
         using (var ms = new MemoryStream())
         using (var ms2 = new MemoryStream())
         using (var fs = new FileStream(fileName, FileMode.OpenOrCreate))
         {
             Utility.CopyStream(stream, ms);
             Utility.CopyStream(ms, ms2);
             Utility.CopyStream(ms, fs);
             //See if System.Drawing.Image accepts this
             try
             {
                 using (var img = System.Drawing.Image.FromStream(ms))
                 { }
             }
             catch (Exception ex)
             {
                 Assert.Fail(ex.Message);
             }
         }
     }
 }
Ejemplo n.º 32
0
 private static void RenderDynamicOverlayAndVerifyConvenience(RuntimeMap map, string fileName, string format)
 {
     using (var stream = map.RenderDynamicOverlay(format, true))
     {
         using (var ms = new MemoryStream())
         using (var ms2 = new MemoryStream())
         using (var fs = new FileStream(fileName, FileMode.OpenOrCreate))
         {
             Utility.CopyStream(stream, ms);
             Utility.CopyStream(ms, ms2);
             Utility.CopyStream(ms, fs);
             //See if System.Drawing.Image accepts this
             try
             {
                 using (var img = System.Drawing.Image.FromStream(ms))
                 { }
             }
             catch (Exception ex)
             {
                 Assert.Fail(ex.Message);
             }
         }
     }
 }
Ejemplo n.º 33
0
 private static void RenderAndVerify(IMappingService mapSvc, RuntimeMap map, string fileName, string format)
 {
     using (var stream = mapSvc.RenderRuntimeMap(map, map.ViewCenter.X, map.ViewCenter.Y, map.ViewScale, map.DisplayWidth, map.DisplayHeight, map.DisplayDpi, format))
     {
         using (var ms = new MemoryStream())
         using (var ms2 = new MemoryStream())
         using (var fs = new FileStream(fileName, FileMode.OpenOrCreate))
         {
             Utility.CopyStream(stream, ms);
             Utility.CopyStream(ms, ms2);
             Utility.CopyStream(ms, fs);
             //See if System.Drawing.Image accepts this
             try
             {
                 using (var img = System.Drawing.Image.FromStream(ms))
                 { }
             }
             catch (Exception ex)
             {
                 Assert.Fail(ex.Message);
             }
         }
     }
 }
Ejemplo n.º 34
0
        protected bool Matches(RuntimeMap map, IMapDefinition mdf)
        {
            if (map.MapDefinition != mdf.ResourceID) return false;
            if (map.Groups.Count != mdf.GetGroupCount()) return false;
            if (map.Layers.Count != mdf.GetLayerCount()) return false;

            foreach (var layer in map.Layers)
            {
                var ldfr = mdf.GetLayerByName(layer.Name);
                if (ldfr == null) return false;

                if (layer.LayerDefinitionID != ldfr.ResourceId) return false;
                if (layer.LegendLabel != ldfr.LegendLabel) return false;
                if (layer.Visible != ldfr.Visible) return false;
                if (layer.Selectable != ldfr.Selectable) return false;
                if (layer.ShowInLegend != ldfr.ShowInLegend) return false;
                if (layer.ExpandInLegend != ldfr.ExpandInLegend) return false;
            }

            foreach (var group in map.Groups)
            {
                var grp = mdf.GetGroupByName(group.Name);
                if (grp == null) return false;

                if (group.ExpandInLegend != grp.ExpandInLegend) return false;
                if (group.Group != grp.Group) return false;
                if (group.LegendLabel != grp.LegendLabel) return false;
                if (group.Name != grp.Name) return false;
                if (group.ShowInLegend != grp.ShowInLegend) return false;
                if (group.Visible != grp.Visible) return false;
            }

            return true;
        }
Ejemplo n.º 35
0
        static XmlElement encodeRuntimeMap(XmlDocument doc, RuntimeMap rmap)
        {
            #if TODO
            XmlElement e = null;
            if (rmap != null)
            {
                e = doc.CreateElement("map");
                e.SetAttribute("name", rmap.getName());
                if (rmap.getTerrain() != null) e.SetAttribute("terrain", rmap.getTerrain().getName());

                foreach (RuntimeMapLayer it in rmap.getMapLayers())
                {
                    e.AppendChild(encodeRuntimeMapLayer(doc, it));
                }
            }
            return e;
            #endif
            throw new NotImplementedException();
        }
Ejemplo n.º 36
0
        static RuntimeMap decodeRuntimeMap(XmlElement e, Project proj)
        {
            RuntimeMap map = null;
            if (e != null)
            {
                map = new RuntimeMap();
                map.setName(e.GetAttribute("name"));
                map.setTerrain(proj.getTerrain(e.GetAttribute("terrain")));

                XmlNodeList map_layers = e.GetElementsByTagName("maplayer");
                foreach (XmlNode i in map_layers)
                {
                    XmlElement e2 = (XmlElement)i;
                    RuntimeMapLayer map_layer = decodeRuntimeMapLayer(e2, proj);
                    if (map_layer != null)
                        map.getMapLayers().Add(map_layer);
                }
            }
            return map;
        }