コード例 #1
0
        private Image AreaPolygon(Area area)
        {
            Image    areaImage = area.Blob.GetImage(300, 200);
            Graphics graphics  = Graphics.FromImage(areaImage);

            if (area.Coordinates.Count >= 3)
            {
                Point[] points = new Point[area.Coordinates.Count];
                for (int i = 0; i < area.Coordinates.Count; i++)
                {
                    AreaCoordinate coord = area.Coordinates[i];
                    points[i] = area.MapCoordToPixelCoord(coord.Latitude, coord.Longitude, 300, 200);
                }

                Pen pen = new Pen(Color.Red);
                pen.Width = 3;
                graphics.DrawPolygon(pen, points);
            }

            return(areaImage);
        }
コード例 #2
0
        private void BuildMap()
        {
            showGroupType = Boolean.Parse(ShowGroupTypeSetting);
            showMeetingDay = Boolean.Parse(ShowMeetingDaySetting) && category.MeetingDayCaption.Trim() != string.Empty;
            showMeetingTime = Boolean.Parse(ShowMeetingTimeSetting);
            showTopic = Boolean.Parse(ShowTopicSetting) && category.TopicCaption.Trim() != string.Empty;
            showMaritalPreference = Boolean.Parse(ShowMaritalPreferenceSetting) && category.MaritalPreferenceCaption.Trim() != string.Empty;
            showAgeGroup = Boolean.Parse(ShowAgeGroupSetting) && category.AgeGroupCaption.Trim() != string.Empty;
            showAverageAge = Boolean.Parse(ShowAverageAgeSetting);
            showCity = Boolean.Parse(ShowCitySetting);
            showDescription = Boolean.Parse(ShowDescriptionSetting) && category.DescriptionCaption.Trim() != string.Empty;
            showNotes = Boolean.Parse(ShowNotesSetting) && category.NotesCaption.Trim() != string.Empty;

            pnlMap.Controls.Clear();

            if (Request.Url.Port == 443)
                Page.ClientScript.RegisterStartupScript(typeof(string), "VirtualEarth", "<script src=\"https://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6&s=1\"></script>", false);
            else
                Page.ClientScript.RegisterStartupScript(typeof(string), "VirtualEarth", "<script src=\"http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6\"></script>", false);

            pnlMap.Style.Add("position", "relative");
            pnlMap.Style.Add("width", string.Format("{0}px", MapWidthSetting));
            pnlMap.Style.Add("height", string.Format("{0}px", MapHeightSetting));

            StringBuilder sbVEScript = new StringBuilder();

            sbVEScript.Append("var map = null;\n");
            sbVEScript.Append("var mapGroupLayer = null;\n");

            sbVEScript.Append("window.onload = function() {LoadMyMap();};\n");

            sbVEScript.Append("\nfunction LoadMyMap(){\n");
            sbVEScript.AppendFormat("\tmap = new VEMap('{0}');\n", pnlMap.ClientID);

            switch (MapDashboardSizeSetting)
            {
                case "Normal":
                    sbVEScript.Append("\tmap.SetDashboardSize(VEDashboardSize.Normal);\n");
                    break;
                case "Small":
                    sbVEScript.Append("\tmap.SetDashboardSize(VEDashboardSize.Small);\n");
                    break;
                case "Tiny":
                    sbVEScript.Append("\tmap.SetDashboardSize(VEDashboardSize.Tiny);\n");
                    break;
            }

            sbVEScript.Append("\tmap.LoadMap();\n\n");
            //sbVEScript.Append("\tmap.ClearInfoBoxStyles();\n\n");

            Address selectedAddress = null;
            if (Session["PersonAddress"] != null)
                selectedAddress = (Address)Session["PersonAddress"];

            if (selectedAddress == null && CurrentPerson != null)
                selectedAddress = CurrentPerson.PrimaryAddress;

            if (selectedAddress != null &&
                selectedAddress.Latitude != 0 &&
                selectedAddress.Longitude != 0)
            {
                sbVEScript.AppendFormat("\n\tshape = new VEShape(VEShapeType.Pushpin, new VELatLong({0}, {1}));\n",
                    selectedAddress.Latitude.ToString(),
                    selectedAddress.Longitude.ToString());
                sbVEScript.AppendFormat("\tshape.SetCustomIcon('{0}');\n", AddressIconSetting);
                sbVEScript.AppendFormat("\tshape.SetTitle(\"{0}\");\n", Utilities.replaceCRLF(selectedAddress.ToString()));
                sbVEScript.Append("\tmap.AddShape(shape);\n");
            }

            if (Area != null && Area.AreaID != -1)
            {
                sbVEScript.Append("\tvar points = new Array(\n");
                for (int i = 0; i < Area.Coordinates.Count; i++)
                {
                    AreaCoordinate coord = Area.Coordinates[i];
                    sbVEScript.AppendFormat("\t\tnew VELatLong({0}, {1})", coord.Latitude.ToString(), coord.Longitude.ToString());
                    if (i < Area.Coordinates.Count - 1)
                        sbVEScript.Append(",\n");
                }
                sbVEScript.Append("\n\t);\n");
                sbVEScript.Append("\tvar shape = new VEShape(VEShapeType.Polygon, points);\n");
                sbVEScript.Append("\tmap.SetMapView(points);\n");

                sbVEScript.AppendFormat("\tshape.SetLineColor(new VEColor({0}));\n", AreaBorderColorSetting);
                sbVEScript.AppendFormat("\tshape.SetLineWidth({0});\n", AreaBorderWidthSetting);
                sbVEScript.AppendFormat("\tshape.SetFillColor(new VEColor({0}));\n", AreaBackgroundColorSetting);
                sbVEScript.Append("\tshape.HideIcon();\n");
                sbVEScript.AppendFormat("\tshape.SetTitle('{0}');\n", Area.Name);
                sbVEScript.Append("\n\tmap.AddShape(shape);\n");

                sbVEScript.Append("\n\tmapGroupLayer = new VEShapeLayer();\n");
                sbVEScript.Append("\tmapGroupLayer.SetTitle('Groups');\n");
                sbVEScript.Append("\tmap.AddShapeLayer(mapGroupLayer);\n");

                mapGroupCount = 0;
                GroupCollection groups = new GroupCollection();
                groups.LoadByArea(Area.AreaID, category.CategoryID);
                foreach (Group group in groups)
                {
                    if (group.Active)
                    {
                        if (Boolean.Parse(ShowFullGroupsSetting) == false)
                        {
                            int groupCount = (group.LeaderID == -1 ? 0 : 1);
                            foreach (GroupMember member in group.Members)
                                if (member.Active)
                                    groupCount++;

                            if (groupCount < group.MaxMembers)
                                sbVEScript.Append(GroupShape(group));
                        }
                        else
                            sbVEScript.Append(GroupShape(group));
                    }
                }
            }
            else
            {
                GroupClusterCollection clusters = new GroupClusterCollection(category.CategoryID, CurrentOrganization.OrganizationID);
                sbVEScript.Append(RecurseClusters(clusters));

                if (selectedAddress != null &&
                    selectedAddress.Latitude != 0 &&
                    selectedAddress.Longitude != 0)
                {
                    sbVEScript.AppendFormat("\tmap.SetCenterAndZoom(new VELatLong({0}, {1}),12);\n", selectedAddress.Latitude, selectedAddress.Longitude);
                }
                else
                {
                    sbVEScript.Append("\tvar maxPoints = new Array(\n");
                    sbVEScript.AppendFormat("\t\tnew VELatLong({0}, {1}),\n", minLatitude.ToString(), minLongitude.ToString());
                    sbVEScript.AppendFormat("\t\tnew VELatLong({0}, {1}))\n", maxLatitude.ToString(), maxLongitude.ToString());
                    sbVEScript.Append("\tmap.SetMapView(maxPoints);\n");
                    //sbVEScript.Append("\tmap.ZoomIn();\n\n");
                }
            }

            sbVEScript.Append("}\n");

            sbVEScript.Append("\nfunction ShowGroup(shapeIndex){\n");
            sbVEScript.Append("\tvar shape = mapGroupLayer.GetShapeByIndex(shapeIndex);\n");
            sbVEScript.Append("\tvar latLong = shape.GetPoints();\n");
            sbVEScript.Append("\tmap.SetCenterAndZoom(latLong[0], 15);\n");
            sbVEScript.Append("\tsetTimeout(\"ShowInfoBox(\" + shapeIndex + \")\", 1000);\n");
            sbVEScript.Append("}\n");

            sbVEScript.Append("\nfunction ShowInfoBox(shapeIndex){\n");
            sbVEScript.Append("\tvar shape = mapGroupLayer.GetShapeByIndex(shapeIndex);\n");
            sbVEScript.Append("\tvar latLong = shape.GetPoints();\n");
            sbVEScript.Append("\tmap.ShowInfoBox(shape, latLong[0]);\n");
            sbVEScript.Append("}\n");

            // add Safari fix
            sbVEScript.Append("VEValidator.ValidateFloat = function(float) {");
            sbVEScript.Append("\treturn true;");
            sbVEScript.Append("}");

            Page.ClientScript.RegisterStartupScript(typeof(string), "LoadMap", sbVEScript.ToString(), true);
        }
コード例 #3
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;

            status.Text = string.Empty;

            this.Show();
            System.Windows.Forms.Application.DoEvents();

            string mapPointFile = string.Empty;

            openFileDialog1.Filter           = "Mappoint Files (*.ptm)|*.ptm";
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                mappointAreas = new AreaCollection();

                MapPoint.Application mApp = new MapPoint.Application();
                mApp.Visible     = false;
                mApp.UserControl = false;

                MapPoint.Map map = mApp.OpenMap(openFileDialog1.FileName, false);

                int i = 0;
                foreach (MapPoint.Shape shape in map.Shapes)
                {
                    //try
                    //{
                    if (shape.Type == GeoShapeType.geoFreeform)
                    {
                        i++;

                        status.Text = "Importing Shape " + i.ToString();
                        System.Windows.Forms.Application.DoEvents();

                        AreaCoordinateCollection coordinates = new AreaCoordinateCollection();

                        System.Object[] objects = (System.Object[])shape.Vertices;

                        foreach (System.Object obj in objects)
                        {
                            if (obj is MapPoint.Location)
                            {
                                MapPoint.Location location = (MapPoint.Location)obj;

                                AreaCoordinate coordinate = new AreaCoordinate();
                                coordinate.Latitude  = location.Latitude;
                                coordinate.Longitude = location.Longitude;
                                coordinates.Add(coordinate);

                                System.Windows.Forms.Application.DoEvents();
                            }
                        }

                        Area area = new Area(coordinates.MinLatitude(), coordinates.MinLongitude());
                        if (area == null || area.AreaID == -1)
                        {
                            area.AreaID         = int.MinValue;
                            area.OrganizationID = OrganizationId;
                            area.Name           = "Area: " + i.ToString();
                            area.MapHeight      = 400;
                            area.MapWidth       = 600;
                        }

                        area.Coordinates = coordinates;

                        for (int j = 0; j < area.Coordinates.Count; j++)
                        {
                            AreaCoordinate aCoordinate = area.Coordinates[j];
                            aCoordinate.AreaID = area.AreaID;
                            aCoordinate.Order  = j;
                        }

                        if (area.Blob != null)
                        {
                            area.Blob.DateModified = DateTime.Now;
                        }

                        mappointAreas.Add(area);
                    }
                    //}
                    //catch (System.Exception ex)
                    //{
                    //    MessageBox.Show("Area " + i.ToString() + ": " + ex.Message, "Error Reading Area");
                    //}
                }

                LoadExistingAreas();
                LoadMappointAreas(0);
            }
            else
            {
                btnLink.Enabled      = false;
                btnCreateNew.Enabled = false;
                btnRemove.Enabled    = false;
                btnImport.Enabled    = false;
            }

            status.Text    = string.Empty;
            Cursor.Current = Cursors.Default;
        }
コード例 #4
0
        private void ShowView()
        {
            phMap.Controls.Clear();
            Page.ClientScript.RegisterStartupScript(typeof(string), "VirtualEarth", "<script src=\"http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=5\"></script>", false);

            if (Area == null || Area.AreaID == -1)
            {
                System.Web.UI.WebControls.Panel pnlMap = new System.Web.UI.WebControls.Panel();
                pnlMap.ID = "pnlMap";
                pnlMap.Attributes.Add("class", "areaMap");
                pnlMap.Style.Add("position", "relative");
                pnlMap.Style.Add("width", MapWidthSetting + "px");
                pnlMap.Style.Add("height", MapHeightSetting + "px");
                phMap.Controls.Add(pnlMap);

                StringBuilder sbVEScript = new StringBuilder();

                sbVEScript.Append("var map = null;\n");
                sbVEScript.Append("var currentShape = null;\n");

                sbVEScript.Append("window.onload = function() {LoadMyMap();};\n");

                sbVEScript.Append("\nfunction LoadMyMap(){\n\n");
                sbVEScript.AppendFormat("\tmap = new VEMap('{0}');\n", pnlMap.ClientID);
                sbVEScript.Append("\tmap.SetDashboardSize(VEDashboardSize.Tiny);\n");
                sbVEScript.Append("\tmap.LoadMap();\n\n");
                sbVEScript.Append("\tmap.AttachEvent('onmouseover', mapMouseOver);\n");
                sbVEScript.Append("\tmap.AttachEvent('onmouseout', mapMouseOut);\n");
                sbVEScript.Append("\tmap.AttachEvent('onclick', mapClick);\n\n");
                //sbVEScript.Append("\tmap.ClearInfoBoxStyles();\n\n");

                sbVEScript.Append("\tvar shape = null;\n");
                sbVEScript.Append("\tvar areaPoints = null;\n\n");

                StringBuilder sbAllPoints = new StringBuilder();

                double maxLatitude  = double.MinValue;
                double maxLongitude = double.MinValue;
                double minLatitude  = double.MinValue;
                double minLongitude = double.MinValue;

                foreach (Area area in new AreaCollection(CurrentOrganization.OrganizationID))
                {
                    if (area.Coordinates.Count > 0)
                    {
                        sbVEScript.Append("\tareaPoints = new Array(\n");
                        for (int i = 0; i < area.Coordinates.Count; i++)
                        {
                            AreaCoordinate coord = area.Coordinates[i];

                            if (maxLatitude == double.MinValue || maxLatitude < coord.Latitude)
                            {
                                maxLatitude = coord.Latitude;
                            }
                            if (maxLongitude == double.MinValue || maxLongitude < coord.Longitude)
                            {
                                maxLongitude = coord.Longitude;
                            }
                            if (minLatitude == double.MinValue || minLatitude > coord.Latitude)
                            {
                                minLatitude = coord.Latitude;
                            }
                            if (minLongitude == double.MinValue || minLongitude > coord.Longitude)
                            {
                                minLongitude = coord.Longitude;
                            }

                            sbVEScript.AppendFormat("\t\tnew VELatLong({0}, {1})", coord.Latitude.ToString(), coord.Longitude.ToString());
                            if (i < area.Coordinates.Count - 1)
                            {
                                sbVEScript.Append(",\n");
                            }

                            sbAllPoints.AppendFormat("\t\tnew VELatLong({0}, {1}),\n", coord.Latitude.ToString(), coord.Longitude.ToString());
                        }
                        sbVEScript.Append(");\n");

                        sbVEScript.Append("\tshape = new VEShape(VEShapeType.Polygon, areaPoints);\n\n");
                        sbVEScript.Append("\tshape.SetLineColor(new VEColor(255,0,0,1));\n");
                        sbVEScript.Append("\tshape.SetLineWidth(1);\n");
                        sbVEScript.Append("\tshape.SetFillColor(new VEColor(236,183,49,.3));\n");
                        sbVEScript.AppendFormat("\tshape.SetTitle(\"{0}\");\n", area.Name);
                        sbVEScript.AppendFormat("\tshape.SetDescription(\"{0}\");\n", AreaDetailsHTML(area));
                        sbVEScript.AppendFormat("\tshape.SetMoreInfoURL('default.aspx?page={0}&area={1}');\n", AreaPageIDSetting, area.AreaID.ToString());
                        sbVEScript.Append("\tshape.HideIcon();\n");
                        sbVEScript.Append("\tmap.AddShape(shape);\n\n");
                    }
                }

                sbVEScript.Append("\tvar allPoints = new Array(\n");
                sbVEScript.AppendFormat("\t\tnew VELatLong({0}, {1}),\n", minLatitude.ToString(), minLongitude.ToString());
                sbVEScript.AppendFormat("\t\tnew VELatLong({0}, {1}))\n", maxLatitude.ToString(), maxLongitude.ToString());
                sbVEScript.Append("\tmap.SetMapView(allPoints);\n");
                sbVEScript.Append("\tmap.ZoomIn();\n");
                sbVEScript.Append("}\n");

                sbVEScript.Append("\nfunction mapMouseOver(e){\n");
                sbVEScript.Append("\tvar shape = map.GetShapeByID(e.elementID);\n");
                sbVEScript.Append("\tshape.SetLineWidth(2);\n");
                sbVEScript.Append("\tif (currentShape != null)\n");
                sbVEScript.Append("\t\tcurrentShape.SetLineWidth(1);\n");
                sbVEScript.Append("\tcurrentShape = shape;\n");
                sbVEScript.Append("}\n");

                sbVEScript.Append("\nfunction mapMouseOut(e){\n");
                sbVEScript.Append("\tvar shape = map.GetShapeByID(e.elementID);\n");
                sbVEScript.Append("\tshape.SetLineWidth(1);\n");
                sbVEScript.Append("}\n");

                sbVEScript.Append("\nfunction mapClick(e){\n");
                sbVEScript.Append("\tvar shape = map.GetShapeByID(e.elementID);\n");
                sbVEScript.Append("\twindow.location = shape.GetMoreInfoURL();\n");
                sbVEScript.Append("}\n");

                Page.ClientScript.RegisterStartupScript(typeof(string), "LoadMap", sbVEScript.ToString(), true);
            }
            else
            {
                System.Web.UI.WebControls.Panel pnlMap = new System.Web.UI.WebControls.Panel();
                pnlMap.ID = "pnlMap";
                pnlMap.Style.Add("position", "relative");
                pnlMap.Style.Add("width", "600px");
                pnlMap.Style.Add("height", "400px");
                phMap.Controls.Add(pnlMap);

                StringBuilder sbVEScript = new StringBuilder();

                sbVEScript.Append("var map = null;\n");

                sbVEScript.Append("window.onload = function() {LoadMyMap();};\n");

                sbVEScript.Append("\nfunction LoadMyMap(){\n");
                sbVEScript.AppendFormat("\tmap = new VEMap('{0}');\n", pnlMap.ClientID);
                sbVEScript.Append("\tmap.LoadMap();\n\n");
                sbVEScript.Append("\tmap.ClearInfoBoxStyles();\n\n");

                sbVEScript.Append("\tvar points = new Array(\n");
                for (int i = 0; i < Area.Coordinates.Count; i++)
                {
                    AreaCoordinate coord = Area.Coordinates[i];
                    sbVEScript.AppendFormat("\t\tnew VELatLong({0}, {1})", coord.Latitude.ToString(), coord.Longitude.ToString());
                    if (i < Area.Coordinates.Count - 1)
                    {
                        sbVEScript.Append(",\n");
                    }
                }
                sbVEScript.Append("\n\t);\n");
                sbVEScript.Append("\tvar shape = new VEShape(VEShapeType.Polygon, points);\n");
                sbVEScript.Append("\tmap.SetMapView(points);\n");

                sbVEScript.Append("\tshape.SetLineColor(new VEColor(255,0,0,1));\n");
                sbVEScript.Append("\tshape.SetLineWidth(2);\n");
                sbVEScript.Append("\tshape.SetFillColor(new VEColor(236,183,49,.3));\n");
                sbVEScript.Append("\tshape.HideIcon();\n");
                sbVEScript.AppendFormat("\tshape.SetTitle('{0}');\n", Area.Name);
                sbVEScript.Append("\n\tmap.AddShape(shape);\n");

                GroupCollection groups = new GroupCollection();
                groups.LoadByArea(Area.AreaID, 1);
                foreach (Group group in groups)
                {
                    if (group.TargetLocation != null)
                    {
                        sbVEScript.AppendFormat("\n\tshape = new VEShape(VEShapeType.Pushpin, new VELatLong({0}, {1}));\n",
                                                group.TargetLocation.Latitude.ToString(),
                                                group.TargetLocation.Longitude.ToString());
                        sbVEScript.Append("\tshape.SetCustomIcon('images/map/pin_blue.png');\n");
                        sbVEScript.AppendFormat("\tshape.SetTitle(\"{0}\");\n", BuildDetailTitle(group.Title));
                        sbVEScript.AppendFormat("\tshape.SetDescription('{0}');\n", BuildDetailPanel(group));

                        sbVEScript.Append("\tmap.AddShape(shape);\n");
                    }
                }

                sbVEScript.Append("}\n");

                Page.ClientScript.RegisterStartupScript(typeof(string), "LoadMap", sbVEScript.ToString(), true);
            }
        }