Пример #1
0
    private void CreatePdfOverviewMap(PdfContentByte content, Configuration.PrintTemplateContentRow row)
    {
        AppState appState = new AppState();

        appState.Application = _appState.Application;
        Configuration.ApplicationRow application = AppContext.GetConfiguration().Application.First(o => o.ApplicationID == appState.Application);

        appState.MapTab = application.OverviewMapID;
        appState.Extent = application.GetFullExtentEnvelope();

        int pixelWidth  = Convert.ToInt32(row.Width * PixelsPerInch);
        int pixelHeight = Convert.ToInt32(row.Height * PixelsPerInch);

        MapMaker     mapMaker     = new MapMaker(appState, pixelWidth, pixelHeight, 2);
        MapImageData mapImageData = mapMaker.GetImage();

        System.Drawing.Bitmap bitmap      = new System.Drawing.Bitmap(new MemoryStream(mapImageData.Image));
        Transformation        trans       = new AffineTransformation(pixelWidth * 2, pixelHeight * 2, appState.Extent);
        MapGraphics           mapGraphics = MapGraphics.FromImage(bitmap, trans);

        double   minSize = (trans.Transform(new Coordinate(1, 0)).X - trans.Transform(new Coordinate(0, 0)).X) * 12;
        Envelope extent  = new Envelope(new Coordinate(_appState.Extent.MinX, _appState.Extent.MinY), new Coordinate(_appState.Extent.MaxX, _appState.Extent.MaxY));

        if (extent.Width < minSize)
        {
            extent = new Envelope(new Coordinate(extent.Centre.X - minSize * 0.5, extent.MinY), new Coordinate(extent.Centre.X + minSize * 0.5, extent.MaxY));
        }

        if (extent.Height < minSize)
        {
            extent = new Envelope(new Coordinate(extent.MinX, extent.Centre.Y - minSize * 0.5), new Coordinate(extent.MaxX, extent.Centre.Y + minSize * 0.5));
        }

        System.Drawing.Brush brush = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(64, System.Drawing.Color.Red));
        System.Drawing.Pen   pen   = new System.Drawing.Pen(System.Drawing.Color.Red, 4);

        mapGraphics.FillEnvelope(brush, extent);
        mapGraphics.DrawEnvelope(pen, extent);

        MemoryStream stream = new MemoryStream();

        bitmap.Save(stream, mapImageData.Type == CommonImageType.Png ? System.Drawing.Imaging.ImageFormat.Png : System.Drawing.Imaging.ImageFormat.Jpeg);
        byte[] mapImage = stream.ToArray();

        float originX = Convert.ToSingle(row.OriginX) * PointsPerInch;
        float originY = Convert.ToSingle(row.OriginY) * PointsPerInch;
        float width   = Convert.ToSingle(row.Width) * PointsPerInch;
        float height  = Convert.ToSingle(row.Height) * PointsPerInch;

        iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(mapImage);
        image.SetAbsolutePosition(originX, originY);
        image.ScaleAbsolute(width, height);

        content.AddImage(image);

        CreatePdfBox(content, row, false);
    }
Пример #2
0
    private void SaveMapImage()
    {
        AppState appState = AppState.FromJson(Request.Form["state"]);
        int      width    = Convert.ToInt32(Math.Round(Convert.ToDouble(Request.Form["width"])));
        int      height   = Convert.ToInt32(Math.Round(Convert.ToDouble(Request.Form["height"])));

        MapImageData mapImageData = CompositeMapImage(appState, width, height);

        Response.ContentType = mapImageData.Type == CommonImageType.Png ? "image/png" : "image/jpeg";
        Response.AddHeader("Content-Disposition", "attachment; filename=Map." + (mapImageData.Type == CommonImageType.Png ? "png" : "jpg"));
        Response.BinaryWrite(mapImageData.Image);
    }
Пример #3
0
    public MapImageData GetTileCompositeImage()
    {
        MapImageData mapImageData = GetImage();

        List <Bitmap> baseTiles    = GetTileImages(false);
        List <Bitmap> overlayTiles = GetTileImages(true);

        if (baseTiles.Count == 0 && overlayTiles.Count == 0)
        {
            return(mapImageData);
        }

        int width  = Convert.ToInt32(_width * _resolution);
        int height = Convert.ToInt32(_height * _resolution);

        using (Bitmap composite = new Bitmap(width, height))
        {
            using (Graphics graphics = Graphics.FromImage(composite))
            {
                graphics.Clear(Color.Transparent);

                foreach (Bitmap tileImage in baseTiles)
                {
                    graphics.DrawImage(tileImage, 0, 0, width, height);
                }

                using (MemoryStream imageStream = new MemoryStream(mapImageData.Image))
                {
                    using (Bitmap mapImage = new Bitmap(imageStream))
                    {
                        graphics.DrawImage(mapImage, 0, 0, width, height);
                    }
                }

                foreach (Bitmap tileImage in overlayTiles)
                {
                    graphics.DrawImage(tileImage, 0, 0, width, height);
                }
            }

            using (MemoryStream imageStream = new MemoryStream())
            {
                composite.Save(imageStream, ImageFormat.Png);
                mapImageData.Image = imageStream.ToArray();
                mapImageData.Type  = CommonImageType.Png;
            }
        }

        return(mapImageData);
    }
Пример #4
0
    private MapImageData CompositeMapImage(AppState appState, int width, int height)
    {
        MapMaker     mapMaker     = new MapMaker(appState, width, height);
        MapImageData mapImageData = mapMaker.GetImage();

        List <Bitmap> baseTiles    = GetTileImages(appState, width, height, false);
        List <Bitmap> overlayTiles = GetTileImages(appState, width, height, true);

        if (baseTiles.Count == 0 && overlayTiles.Count == 0)
        {
            return(mapImageData);
        }

        using (Bitmap composite = new Bitmap(width, height))
        {
            using (Graphics graphics = Graphics.FromImage(composite))
            {
                graphics.Clear(Color.Transparent);

                foreach (Bitmap tileImage in baseTiles)
                {
                    graphics.DrawImage(tileImage, 0, 0);
                }

                using (MemoryStream imageStream = new MemoryStream(mapImageData.Image))
                {
                    using (Bitmap mapImage = new Bitmap(imageStream))
                    {
                        graphics.DrawImage(mapImage, 0, 0);
                    }
                }

                foreach (Bitmap tileImage in overlayTiles)
                {
                    graphics.DrawImage(tileImage, 0, 0);
                }
            }

            using (MemoryStream imageStream = new MemoryStream())
            {
                composite.Save(imageStream, ImageFormat.Png);
                mapImageData.Image = imageStream.ToArray();
                mapImageData.Type  = CommonImageType.Png;
            }
        }

        return(mapImageData);
    }
Пример #5
0
    private void GetMapImage()
    {
        AppState appState = AppState.FromJson(Request.QueryString["state"]);

        // set the default map layers as visible
        Configuration.MapTabRow mapTab = Configuration.MapTab.FindByMapTabID(appState.MapTab);
        appState.VisibleLayers = new System.Collections.Generic.Dictionary <string, StringCollection>()
        {
            { appState.MapTab, new StringCollection(mapTab.GetMapTabLayerRows().Where(e => !e.IsCheckInLegendNull() && e.CheckInLegend == 1).Select(e => e.LayerID)) }
        };

        int width  = Convert.ToInt32(Request.QueryString["width"]);
        int height = Convert.ToInt32(Request.QueryString["height"]);

        MapMaker     mapMaker     = new MapMaker(appState, width, height);
        MapImageData mapImageData = mapMaker.GetImage();

        Response.ContentType = mapImageData.Type == CommonImageType.Png ? "image/png" : "image/jpeg";
        Response.BinaryWrite(mapImageData.Image);
    }
Пример #6
0
    private void DefaultMethod()
    {
        string key = Request.QueryString["key"];

        if (String.IsNullOrEmpty(key))
        {
            Response.End();
            return;
        }

        MapImageData mapImageData = AppContext.BrowserImageCache.Retrieve(key);

        if (mapImageData == null)
        {
            Response.End();
            return;
        }

        Response.ContentType = mapImageData.Type == CommonImageType.Png ? "image/png" : "image/jpeg";
        Response.BinaryWrite(mapImageData.Image);
    }
Пример #7
0
    private void GetOverviewImage()
    {
        Configuration.ApplicationRow application = Configuration.Application.First(o => o.ApplicationID == Request.Params["application"]);

        int width  = Convert.ToInt32(Request.Params["width"]);
        int height = Convert.ToInt32(Request.Params["height"]);

        string[] bbox = Request.Params["bbox[]"].Split(',');

        AppState appState = new AppState()
        {
            Application = application.ApplicationID,
            MapTab      = application.OverviewMapID,
            Extent      = new Envelope(new Coordinate(Convert.ToDouble(bbox[0]), Convert.ToDouble(bbox[1])), new Coordinate(Convert.ToDouble(bbox[2]), Convert.ToDouble(bbox[3])))
        };

        MapMaker     mapMaker     = new MapMaker(appState, width, height);
        MapImageData mapImageData = mapMaker.GetImage();

        Response.ContentType = mapImageData.Type == CommonImageType.Png ? "image/png" : "image/jpeg";
        Response.BinaryWrite(mapImageData.Image);
    }
Пример #8
0
    public MapImageData GetImage()
    {
        StringCollection visibleLayers = null;

        if (_appState.VisibleLayers.ContainsKey(_appState.MapTab))
        {
            visibleLayers = _appState.VisibleLayers[_appState.MapTab];
        }

        string keyExtent = _appState.Extent.ToDelimitedString();
        string keySize   = _width.ToString() + "," + _height.ToString();
        string keyLayers = visibleLayers != null?visibleLayers.ToString('|') : "";

        string key = String.Format("{0}|{1}|{2}|{3}|{4}|{5}", _appState.MapTab, _appState.Level, keyExtent, keySize, _resolution, keyLayers);

        CommonImageType imageType = CommonImageType.Png;

        byte[] image = null;

        MapImageData mapImageData = AppContext.ServerImageCache.Retrieve(key);

        if (mapImageData != null)
        {
            imageType = mapImageData.Type;
            image     = mapImageData.Image;
        }

        Configuration config = AppContext.GetConfiguration();

        Configuration.MapTabRow mapTab    = config.MapTab.FindByMapTabID(_appState.MapTab);
        CommonDataFrame         dataFrame = AppContext.GetDataFrame(mapTab);

        bool isInteractive = !mapTab.IsInteractiveLegendNull() && mapTab.InteractiveLegend == 1;

        // create the base image if not found in the cache

        if (image == null)
        {
            CommonMap map = dataFrame.GetMap(_width, _height, _extent);

            map.Resolution = _resolution;
            map.ImageType  = CommonImageType.Png;

            double pixelSize = map.Extent.Width / _width;

            Dictionary <int, CommonLayer> layerList      = new Dictionary <int, CommonLayer>();
            Dictionary <int, String>      definitionList = new Dictionary <int, String>();
            List <String> mapTabLayerIds = new List <String>();

            foreach (Configuration.MapTabLayerRow mapTabLayer in mapTab.GetMapTabLayerRows())
            {
                Configuration.LayerRow layer = mapTabLayer.LayerRow;
                mapTabLayerIds.Add(layer.LayerID);

                CommonLayer commonLayer = dataFrame.Layers.FirstOrDefault(lyr => String.Compare(lyr.Name, layer.LayerName, true) == 0);
                int         index       = dataFrame.Layers.IndexOf(commonLayer);

                bool visibleAtScale  = commonLayer.IsWithinScaleThresholds(pixelSize);
                bool shownInLegend   = !mapTabLayer.IsShowInLegendNull() && mapTabLayer.ShowInLegend == 1;
                bool checkedInLegend = !isInteractive || mapTabLayer.IsCheckInLegendNull() || mapTabLayer.CheckInLegend < 0 || (visibleLayers != null && visibleLayers.Contains(layer.LayerID));

                bool validLevel = layer.IsLevelFieldNull() || !String.IsNullOrEmpty(_appState.Level);

                if (!layerList.ContainsKey(index) && visibleAtScale && (!shownInLegend || checkedInLegend) && validLevel)
                {
                    if (commonLayer.Type == CommonLayerType.Image)
                    {
                        map.ImageType = CommonImageType.Jpg;
                    }

                    layerList.Add(index, commonLayer);
                    definitionList.Add(index, layer.GetLevelQuery(commonLayer, _appState.Level));
                }
            }

            if (!mapTab.IsBaseMapIDNull())
            {
                foreach (Configuration.LayerRow layer in config.Layer.Where(o => !o.IsBaseMapIDNull() && o.BaseMapID == mapTab.BaseMapID))
                {
                    if (!mapTabLayerIds.Contains(layer.LayerID))
                    {
                        CommonLayer commonLayer = dataFrame.Layers.FirstOrDefault(o => String.Compare(o.Name, layer.LayerName, true) == 0);
                        int         index       = dataFrame.Layers.IndexOf(commonLayer);

                        bool visibleAtScale = commonLayer.IsWithinScaleThresholds(pixelSize);

                        if (!layerList.ContainsKey(index) && visibleAtScale)
                        {
                            if (commonLayer.Type == CommonLayerType.Image)
                            {
                                map.ImageType = CommonImageType.Jpg;
                            }

                            layerList.Add(index, commonLayer);
                            definitionList.Add(index, layer.GetLevelQuery(commonLayer, _appState.Level));
                        }
                    }
                }
            }

            int[] indexes = new int[layerList.Keys.Count];
            layerList.Keys.CopyTo(indexes, 0);
            List <int> indexList = new List <int>(indexes);
            indexList.Sort();

            for (int i = 0; i < indexList.Count; ++i)
            {
                map.AddLayer(layerList[indexList[i]], definitionList[indexList[i]]);
            }

            imageType = map.ImageType;
            image     = map.GetImageBytes();

            AppContext.ServerImageCache.Store(key, new MapImageData(imageType, image));
        }


        // draw the selected feature graphics and markup

        if (_appState.TargetIds.Count > 0 || _appState.SelectionIds.Count > 0 || _appState.MarkupGroups.Count > 0 || _appState.Markup.Count > 0)
        {
            Bitmap bitmap = new Bitmap(new MemoryStream(image));
            bitmap.SetResolution(dataFrame.Dpi, dataFrame.Dpi);
            Graphics graphics = Graphics.FromImage(bitmap);

            if (_appState.TargetIds.Count > 0 || _appState.SelectionIds.Count > 0)
            {
                StringCollection targetIds;
                StringCollection filteredIds;
                StringCollection selectionIds;

                PrepareIds(out targetIds, out filteredIds, out selectionIds);

                DrawFeatures(graphics, _appState.TargetLayer, filteredIds, AppSettings.FilteredColor, AppSettings.FilteredOpacity, AppSettings.FilteredPolygonMode, AppSettings.FilteredPenWidth, AppSettings.FilteredDotSize);
                DrawFeatures(graphics, _appState.SelectionLayer, selectionIds, AppSettings.SelectionColor, AppSettings.SelectionOpacity, AppSettings.SelectionPolygonMode, AppSettings.SelectionPenWidth, AppSettings.SelectionDotSize);
                DrawFeatures(graphics, _appState.TargetLayer, targetIds, AppSettings.TargetColor, AppSettings.TargetOpacity, AppSettings.TargetPolygonMode, AppSettings.TargetPenWidth, AppSettings.TargetDotSize);
                DrawFeatures(graphics, _appState.TargetLayer, _appState.ActiveMapId, AppSettings.ActiveColor, AppSettings.ActiveOpacity, AppSettings.ActivePolygonMode, AppSettings.ActivePenWidth, AppSettings.ActiveDotSize);

                IGeometry selectionBuffer = _appState.SelectionManager.GetSelectionBuffer();

                if (selectionBuffer != null)
                {
                    Brush bufferBrush = new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * AppSettings.BufferOpacity), AppSettings.BufferColor));
                    Pen   bufferPen   = AppSettings.BufferOutlineOpacity > 0 ? new Pen(new SolidBrush(Color.FromArgb(Convert.ToInt32(255 * AppSettings.BufferOutlineOpacity), AppSettings.BufferOutlineColor)), AppSettings.BufferOutlinePenWidth) : null;

                    switch (selectionBuffer.OgcGeometryType)
                    {
                    case OgcGeometryType.Polygon:
                        DrawPolygon(graphics, (IPolygon)selectionBuffer, bufferBrush, null, bufferPen);
                        break;

                    case OgcGeometryType.MultiPolygon:
                        DrawMultiPolygon(graphics, (IMultiPolygon)selectionBuffer, bufferBrush, null, bufferPen);
                        break;
                    }
                }
            }

            graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;

            DrawMarkup(graphics);

            MemoryStream memoryStream = new MemoryStream();

            if (imageType == CommonImageType.Jpg)
            {
                ImageCodecInfo    imageCodecInfo    = GetEncoderInfo("image/jpeg");
                EncoderParameters encoderParameters = new EncoderParameters(1);
                encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, 85L);
                bitmap.Save(memoryStream, imageCodecInfo, encoderParameters);
            }
            else
            {
                bitmap.Save(memoryStream, bitmap.RawFormat);
            }

            image = memoryStream.ToArray();
        }

        return(new MapImageData(imageType, image));
    }
Пример #9
0
    private void SaveMapKml()
    {
        AppState appState = AppState.FromJson(Request.Form["state"]);
        int      width    = Convert.ToInt32(Math.Round(Convert.ToDouble(Request.Form["width"])));
        int      height   = Convert.ToInt32(Math.Round(Convert.ToDouble(Request.Form["height"])));

        MapMaker     mapMaker     = new MapMaker(appState, width, height);
        MapImageData mapImageData = mapMaker.GetImage();

        Configuration.ApplicationRow application = Configuration.Application.Select(String.Format("ApplicationID = '{0}'", appState.Application))[0] as Configuration.ApplicationRow;
        string appName = application.DisplayName;

        DateTime now       = DateTime.Now;
        string   timeStamp = now.ToString("yyyyMMddHHmmssff");
        string   dateNow   = now.ToString("MM/dd/yyyy hh:mm tt");

        string kmzName   = String.Format("Map_{0}.kmz", timeStamp);
        string kmlName   = String.Format("Map_{0}.kml", timeStamp);
        string imageName = String.Format("Map_{0}.", timeStamp) + (mapImageData.Type == CommonImageType.Png ? "png" : "jpg");

        double f = AppSettings.MapUnits == "feet" ? Constants.MetersPerFoot : 1;

        CoordinateSystem coordSys = AppSettings.CoordinateSystem;

        double lat;
        double lon;

        coordSys.ToGeodetic(appState.Extent.MinX * f, appState.Extent.MinY * f, out lon, out lat);
        double minLat = lat;
        double maxLat = lat;
        double minLon = lon;
        double maxLon = lon;

        coordSys.ToGeodetic(appState.Extent.MinX * f, appState.Extent.MaxY * f, out lon, out lat);
        minLat = Math.Min(minLat, lat);
        maxLat = Math.Max(maxLat, lat);
        minLon = Math.Min(minLon, lon);
        maxLon = Math.Max(maxLon, lon);

        coordSys.ToGeodetic(appState.Extent.MaxX * f, appState.Extent.MaxY * f, out lon, out lat);
        minLat = Math.Min(minLat, lat);
        maxLat = Math.Max(maxLat, lat);
        minLon = Math.Min(minLon, lon);
        maxLon = Math.Max(maxLon, lon);

        coordSys.ToGeodetic(appState.Extent.MaxX * f, appState.Extent.MinY * f, out lon, out lat);
        minLat = Math.Min(minLat, lat);
        maxLat = Math.Max(maxLat, lat);
        minLon = Math.Min(minLon, lon);
        maxLon = Math.Max(maxLon, lon);

        Coordinate p = appState.Extent.Centre;
        double     cLat;
        double     cLon;

        coordSys.ToGeodetic(p.X * f, p.Y * f, out cLon, out cLat);

        p.X = appState.Extent.MaxX;
        double eLat;
        double eLon;

        coordSys.ToGeodetic(p.X * f, p.Y * f, out eLon, out eLat);

        double rotation = Math.Atan2(eLat - cLat, eLon - cLon) * 180 / Math.PI;

        string kml = @"<?xml version=""1.0"" encoding=""UTF-8""?>
        <kml xmlns=""http://earth.google.com/kml/2.2"">
          <Folder>
            <name>{0}</name>
            <GroundOverlay>
              <name>Map: created {1}</name>
              <Icon>
                <href>{2}</href>
              </Icon>
              <LatLonBox>
                <north>{3}</north>
                <south>{4}</south>
                <east>{5}</east>
                <west>{6}</west>
                <rotation>{7}</rotation>
              </LatLonBox>
            </GroundOverlay>
          </Folder>
        </kml>";

        kml = String.Format(kml, appName, dateNow, imageName, maxLat, minLat, maxLon, minLon, rotation);

        Response.ContentType = "application/vnd.google-earth.kmz";
        Response.AddHeader("Content-Disposition", "attachment; filename=" + kmzName);

        ZipOutputStream zipStream = new ZipOutputStream(Response.OutputStream);

        MemoryStream memoryStream = new MemoryStream();

        byte[] buffer = (new UTF8Encoding()).GetBytes(kml);

        ZipEntry entry = new ZipEntry(kmlName);

        entry.Size = buffer.Length;
        zipStream.PutNextEntry(entry);
        zipStream.Write(buffer, 0, buffer.Length);

        entry      = new ZipEntry(imageName);
        entry.Size = mapImageData.Image.Length;
        zipStream.PutNextEntry(entry);
        zipStream.Write(mapImageData.Image, 0, mapImageData.Image.Length);

        zipStream.Finish();
    }