コード例 #1
0
        public string ToPdf(Map map, GeoCollection <object> args)
        {
            PdfDocument document         = new PdfDocument();
            PdfPage     page             = document.AddPage();
            string      selectedItemText = args[0].ToString();

            if (selectedItemText == "Landscape")
            {
                page.Orientation = PageOrientation.Landscape;
            }
            PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas();

            // This allows you to control the area in which you want the
            // map to draw in.  Leaving this commented out uses the whole page
            //pdfGeoCanvas.DrawingArea = new Rectangle(200, 50, 400, 400);
            Collection <SimpleCandidate> labelsInLayers = new Collection <SimpleCandidate>();

            foreach (Layer layer in map.StaticOverlay.Layers)
            {
                RectangleShape printExtent = ExtentHelper.GetDrawingExtent(map.CurrentExtent, (float)map.WidthInPixels, (float)map.HeightInPixels);
                pdfGeoCanvas.BeginDrawing(page, printExtent, GeographyUnit.DecimalDegree);
                layer.Open();
                layer.Draw(pdfGeoCanvas, labelsInLayers);
                layer.Close();
                pdfGeoCanvas.EndDrawing();
            }

            string relativePath = string.Format("~/Controllers/{0}/{1}", ControllerContext.RouteData.Values["Controller"], "MapSuite PDF Map.pdf");
            string filename     = Server.MapPath(relativePath);

            document.Save(filename);

            return(VirtualPathUtility.ToAbsolute(relativePath));
        }
コード例 #2
0
        private void ZoomToFeatures(IEnumerable <Feature> features, FeatureLayer featureLayer)
        {
            RectangleShape extent        = features.Count() == 1 ? GetBoundingBox(features.FirstOrDefault()) : ExtentHelper.GetBoundingBoxOfItems(features);
            RectangleShape drawingExtent = ExtentHelper.GetDrawingExtent(extent, (float)GisEditor.ActiveMap.ActualWidth, (float)GisEditor.ActiveMap.ActualHeight);
            var            scale         = ExtentHelper.GetScale(drawingExtent, (float)map.ActualWidth, map.MapUnit);

            map.ZoomTo(extent.GetCenterPoint(), scale);
            //GisEditor.UIManager.RefreshPlugins(new RefreshArgs(extent.GetCenterPoint(), "Identify"));
            GisEditor.UIManager.RefreshPlugins(new RefreshArgs(new Tuple <IEnumerable <Feature>, FeatureLayer>(features, featureLayer), "Identify"));
        }
コード例 #3
0
        private void TrackToExtent(Layer layer)
        {
            layer.Open();
            RectangleShape extent = layer.GetBoundingBox();

            layer.Close();

            winformsMap1.CurrentExtent = ExtentHelper.GetDrawingExtent(extent, winformsMap1.Width, winformsMap1.Height);

            winformsMap1.Refresh();
        }
コード例 #4
0
        private void CreateGridCellMatrix()
        {
            //Get the current extent since we use that to gerenate the grid.  Of course this is just for
            //the demo and in the real world you can use any extent you like
            RectangleShape currentDrawingExtent = ExtentHelper.GetDrawingExtent(Map1.CurrentExtent, (float)Map1.ActualWidth, (float)Map1.ActualHeight);

            //Calculate the cell size based on how many rows and columns you specified
            double cellSize = Math.Min(currentDrawingExtent.Width / double.Parse(txtGridIsoLineCellColumnCount.Text), currentDrawingExtent.Height / Int32.Parse(txtGridIsoLineCellRowCount.Text));

            //Greate the grid definition based on the extent, cell size etc.
            GridDefinition gridDefinition = new GridDefinition(currentDrawingExtent, cellSize, -9999, wellDepthPointData);

            //Generate the grid based on Inverse Distance Weighted interpolation model.  You can define your own model if needed.
            gridCellMatrix = GridFeatureSource.GenerateGridMatrix(gridDefinition, new InverseDistanceWeightedGridInterpolationModel(2, double.MaxValue));
        }
コード例 #5
0
        private void LoadWfsFeatureLayer_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

            //WfsFeatureLayer wfsFeatureLayer = new WfsFeatureLayer(@"http://giswebservices.massgis.state.ma.us/geoserver/wfs?request=GetFeature", "massgis:TOWNS_POLYM");
            WfsFeatureLayer wfsFeatureLayer = new WfsFeatureLayer(@"http://demo.boundlessgeo.com/geoserver/wfs", "topp:states");

            wfsFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = AreaStyles.State1;
            wfsFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            LayerOverlay staticOverlay = new LayerOverlay();

            staticOverlay.Layers.Add("WfsFeatureLayer", wfsFeatureLayer);
            winformsMap1.Overlays.Add(staticOverlay);

            winformsMap1.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-124.731, 49.3717, -66.9698, 24.956), winformsMap1.Width, winformsMap1.Height);
            winformsMap1.Refresh();
        }
        private void AddEventInOleDbFeatureLayer_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit       = GeographyUnit.DecimalDegree;
            winformsMap1.CurrentExtent = ExtentHelper.GetDrawingExtent(new RectangleShape(-97.7612400054933, 30.2895641326905, -97.729482650757, 30.2669048309327), winformsMap1.Width, winformsMap1.Height);
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 233, 232, 214));

            string            connectString     = string.Format(CultureInfo.InvariantCulture, "Provider=Microsoft.Jet.OLEDB.4.0; Data Source='{0}'", Samples.RootDirectory + @"Data\Austinstreets.mdb");
            OleDbFeatureLayer oleDbFeatureLayer = new OleDbFeatureLayer("Austinstreets", "TG_ID", "TG_Wkb", connectString);

            ((OleDbFeatureSource)oleDbFeatureLayer.FeatureSource).ExecutingSqlStatement += new EventHandler <ExecutingSqlStatemenOleDbFeatureSourceEventArgs>(OleDbFeature_ExecutingSqlStatement);
            oleDbFeatureLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(LineStyles.LocalRoad2);
            oleDbFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            LayerOverlay staticOverlay = new LayerOverlay();

            staticOverlay.Layers.Add("OleDbLayer", oleDbFeatureLayer);
            winformsMap1.Overlays.Add("OleDbOverlay", staticOverlay);

            winformsMap1.Refresh();
        }
コード例 #7
0
        public string ZoomToShape(Map map, GeoCollection <object> args)
        {
            PointShape position = new PointShape(double.Parse(args[0].ToString()), double.Parse(args[1].ToString()));

            LayerOverlay          staticOverlay = (LayerOverlay)map.CustomOverlays["CountryOverlay"];
            ShapeFileFeatureLayer worldLayer    = (ShapeFileFeatureLayer)staticOverlay.Layers["WorldLayer"];

            LayerOverlay         dynamicOverlay = (LayerOverlay)map.CustomOverlays["HighlightOverlay"];
            InMemoryFeatureLayer highlightLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["HighlighLayer"];

            highlightLayer.InternalFeatures.Clear();
            worldLayer.Open();
            Collection <Feature> features = worldLayer.QueryTools.GetFeaturesContaining(position, ReturningColumnsType.AllColumns);

            worldLayer.Close();

            string         dataTableHtml = string.Empty;
            RectangleShape extent        = map.CurrentExtent;

            if (features.Count > 0)
            {
                highlightLayer.InternalFeatures.Add(features[0].Id, features[0]);
                map.CurrentExtent = ExtentHelper.GetDrawingExtent(features[0].GetBoundingBox(), (float)map.WidthInPixels, (float)map.HeightInPixels);

                extent = features[0].GetBoundingBox();

                string content = string.Empty;
                foreach (string key in features[0].ColumnValues.Keys)
                {
                    content += string.Format("<tr><td style=\"border:1px solid #cccccc;\">{0}</td><td style=\"border:1px solid #cccccc;\">{1}</td></tr>", key, features[0].ColumnValues[key]);
                }
                dataTableHtml = string.Format("<table id=\"dataInfo\" cellspacing=\"0\" style=\"border: 1px solid #cccccc;\"><tr><td style=\"border: 1px solid #cccccc; background: #bbd7ed;\">Column Name</td><td style=\"border: 1px solid #cccccc; background: #bbd7ed;\">Value</td></tr>{0}</table>", content);
            }

            string extentString = string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", extent.LowerLeftPoint.X, extent.LowerLeftPoint.Y, extent.UpperRightPoint.X, extent.UpperRightPoint.Y);

            return(extentString + "|" + dataTableHtml);
        }
コード例 #8
0
        private void DrawInternal(GeoCanvas canvas, Collection <SimpleCandidate> labelsInAllLayers)
        {
            RectangleShape currentBoundingBox = GetBoundingBox();

            AreaStyle brushStyle = BackgroundMask.CloneDeep() as AreaStyle;

            brushStyle.OutlinePen.Width = 0;
            brushStyle.Draw(new BaseShape[] { currentBoundingBox }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers);

            // Clear Cache images
            if (LastmapExtent != null)
            {
                if (LastmapExtent.UpperLeftPoint.X != MapExtent.UpperLeftPoint.X ||
                    LastmapExtent.UpperLeftPoint.Y != MapExtent.UpperLeftPoint.Y ||
                    LastmapExtent.LowerRightPoint.X != MapExtent.LowerRightPoint.X ||
                    LastmapExtent.LowerRightPoint.Y != MapExtent.LowerRightPoint.Y ||
                    IsDrawing)
                {
                    mapImageCache = null;
                }
            }

            //For adjusting the world extent of the map to the ratio of the drawing area.
            RectangleShape adjustedWorldExtent = ExtentHelper.GetDrawingExtent(MapExtent, (float)currentBoundingBox.Width, (float)currentBoundingBox.Height);
            RectangleShape boundingBox         = GetBoundingBox();
            PointShape     ajustedWorldCenter  = adjustedWorldExtent.GetCenterPoint();
            PageGeoCanvas  pageGeoCanvas       = new PageGeoCanvas(new RectangleShape(0, boundingBox.Height, boundingBox.Width, 0), currentBoundingBox);

            //if (EnableClipping)
            //{
            //    pageGeoCanvas.EnableCliping = true;
            //    pageGeoCanvas.ClipingArea = adjustedWorldExtent;
            //}

            //if (canvas is GdiPlusGeoCanvas && DrawingMode != Core.DrawingMode.Vector)
            // only display on map.
            if (DrawingMode != MapPrinterDrawingMode.Vector && !(canvas is PrinterGeoCanvas))
            {
                double   width  = boundingBox.Width / canvas.CurrentWorldExtent.Width * canvas.Width;
                double   height = boundingBox.Height / canvas.CurrentWorldExtent.Height * canvas.Height;
                GeoImage image  = GetCacheImage(pageGeoCanvas, canvas.MapUnit, adjustedWorldExtent, labelsInAllLayers, width, height);

                pageGeoCanvas.BeginDrawing(canvas, adjustedWorldExtent, MapUnit);
                if (image != null)
                {
                    pageGeoCanvas.DrawWorldImage(image, ajustedWorldCenter.X, ajustedWorldCenter.Y, (float)boundingBox.Width - 0.5f, (float)boundingBox.Height - 0.5f, DrawingLevel.LabelLevel);
                }
                if (DrawDescription)
                {
                    DrawDescriptionText(pageGeoCanvas);
                }
                //pageGeoCanvas.EnableCliping = false;
                pageGeoCanvas.EndDrawing();
            }
            // display on map or printer.
            else
            {
                pageGeoCanvas.BeginDrawing(canvas, adjustedWorldExtent, MapUnit);
                double increase = 0;
                if (BackgroundMask.OutlinePen != null)
                {
                    float haflPenWidth = BackgroundMask.OutlinePen.Width / 2;
                    increase = haflPenWidth * canvas.CurrentWorldExtent.Width / canvas.Width;
                }
                canvas.ClippingArea = new RectangleShape(
                    currentBoundingBox.UpperLeftPoint.X - increase,
                    currentBoundingBox.UpperLeftPoint.Y + increase,
                    currentBoundingBox.LowerRightPoint.X + increase,
                    currentBoundingBox.LowerRightPoint.Y - increase);
                if (canvas is PrinterGeoCanvas)
                {
                    foreach (Layer layer in Layers)
                    {
                        pageGeoCanvas.Flush();

                        float        savedDrawingMarginPercentage = 0;
                        FeatureLayer featureLayer = layer as FeatureLayer;
                        if (featureLayer != null)
                        {
                            savedDrawingMarginPercentage      = featureLayer.DrawingMarginInPixel;
                            featureLayer.DrawingMarginInPixel = 0;
                        }
                        layer.SafeProcess(() =>
                        {
                            layer.Draw(pageGeoCanvas, labelsInAllLayers);
                        });
                        if (featureLayer != null && savedDrawingMarginPercentage != 0)
                        {
                            featureLayer.DrawingMarginInPixel = savedDrawingMarginPercentage;
                        }
                    }
                }
                else
                {
                    using (MemoryStream ms = GetImageStream(canvas, labelsInAllLayers, adjustedWorldExtent, boundingBox))
                    {
                        pageGeoCanvas.DrawWorldImage(new GeoImage(ms), ajustedWorldCenter.X, ajustedWorldCenter.Y, (float)boundingBox.Width - 0.5f, (float)boundingBox.Height - 0.5f, DrawingLevel.LabelLevel);
                    }
                    //foreach (Layer layer in Layers)
                    //{
                    //    pageGeoCanvas.Flush();
                    //    layer.SafeProcess(() =>
                    //    {
                    //        layer.Draw(pageGeoCanvas, labelsInAllLayers);
                    //    });
                    //}
                }
                if (DrawDescription)
                {
                    DrawDescriptionText(pageGeoCanvas);
                }
                //pageGeoCanvas.EnableCliping = false;
                var areaStyle = new AreaStyle(BackgroundMask.OutlinePen)
                {
                    DrawingLevel = DrawingLevel.LabelLevel
                };
                areaStyle.Draw(new BaseShape[1] {
                    currentBoundingBox
                }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers);
                canvas.ClippingArea = null;
            }

            AreaStyle lineStyle = new AreaStyle(BackgroundMask.OutlinePen.CloneDeep());

            lineStyle.DrawingLevel = DrawingLevel.LabelLevel;
            lineStyle.Draw(new BaseShape[] { currentBoundingBox }, canvas, new Collection <SimpleCandidate>(), labelsInAllLayers);
            LastmapExtent = new RectangleShape(MapExtent.UpperLeftPoint.X, MapExtent.UpperLeftPoint.Y, MapExtent.LowerRightPoint.X, MapExtent.LowerRightPoint.Y);
        }