public MgMapBase CreateMap(string coordSys, MgEnvelope env, string name) { var map = new MgMap(_siteConn); map.Create(coordSys, env, name); return(map); }
public MgMapBase CreateMap(MgResourceIdentifier mapDefinition, string mapName, int width, int height, double x, double y, double scale, int dpi) { var map = new MgMap(_siteConn); map.Create(mapDefinition, mapName, width, height, x, y, scale, dpi); return(map); }
public MgMapBase CreateMap(MgResourceIdentifier mapDefinition) { var map = new MgMap(_siteConn); map.Create(mapDefinition, mapDefinition.Name); return(map); }
public MgMapBase CreateMap(MgResourceIdentifier resId) { //The test suite relies on the same map and not a new one //re-created on each test of that particular test suite if (_map != null) { return(_map); } _map = new MgMap(_siteConn); _map.Create(resId, resId.GetName()); return(_map); }
protected void Page_Load(object sender, EventArgs e) { MgUserInformation user = new MgUserInformation("Anonymous", ""); MgSite site = new MgSite(); site.Open(user); string sessionId = site.CreateSession(); user.SetMgSessionId(sessionId); MgSiteConnection siteConn = new MgSiteConnection(); siteConn.Open(user); MgResourceIdentifier mdfId = new MgResourceIdentifier("Library://Samples/Sheboygan/Maps/Sheboygan.MapDefinition"); System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); MgMap map1 = new MgMap(siteConn); map1.Create(mdfId, "ColdStart"); sw.Stop(); Trace.Write("ColdStart - " + sw.ElapsedMilliseconds + "ms"); sw.Reset(); sw.Start(); MgMap map2 = new MgMap(siteConn); map2.Create(mdfId, "WarmStart"); sw.Stop(); Trace.Write("WarmStart - " + sw.ElapsedMilliseconds + "ms"); sw.Start(); MgMap map3 = new MgMap(siteConn); map3.Create(mdfId, "WarmStart2"); sw.Stop(); Trace.Write("WarmStart2 - " + sw.ElapsedMilliseconds + "ms"); }
public void MapPlotCollection() { string coordsys = "GEOGCS[\"LL84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]"; MgEnvelope env = new MgEnvelope(10,10,20,20); MgMap map1 = new MgMap(); map1.Create(coordsys, env, "map1"); MgMap map2 = new MgMap(); map2.Create(coordsys, env, "map2"); MgMap map3 = new MgMap(); map3.Create(coordsys, env, "map3"); MgPlotSpecification spec = new MgPlotSpecification((float)8.0, (float)11.0, "in", (float)0.0, (float)0.0, (float)5.0, (float)5.0); MgResourceIdentifier resId = new MgResourceIdentifier("Library://test.WebLayout"); MgLayout layout1 = new MgLayout(resId, "Title1", "in"); MgMapPlot plot1 = new MgMapPlot(map1, spec, layout1); MgLayout layout2 = new MgLayout(resId, "Title2", "in"); MgMapPlot plot2 = new MgMapPlot(map2, spec, layout2); MgLayout layout3 = new MgLayout(resId, "Title3", "in"); MgMapPlot plot3 = new MgMapPlot(map3, spec, layout3); MgMapPlotCollection coll = new MgMapPlotCollection(); coll.Add(plot1); coll.Add(plot2); coll.Remove(plot1); Assert.AreEqual(1, coll.Count); coll.Insert(0, plot1); coll.Insert(2, plot3); MgMapPlot tmp = coll[2]; coll[2] = tmp; Assert.AreEqual(3, coll.Count); string txt = ""; foreach (MgMapPlot plot in coll) { txt += "[" + plot.GetLayout().GetTitle() + "]"; } Assert.AreEqual("[Title1][Title2][Title3]", txt); }
public void MapCollection() { string coordsys = "GEOGCS[\"LL84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]"; MgEnvelope env = new MgEnvelope(10,10,20,20); MgMap map1 = new MgMap(); map1.Create(coordsys, env, "map1"); MgMap map2 = new MgMap(); map2.Create(coordsys, env, "map2"); MgMap map3 = new MgMap(); map3.Create(coordsys, env, "map3"); MgMap map4 = new MgMap(); map4.Create(coordsys, env, "map4"); MgMapCollection coll = new MgMapCollection(); coll.Add(map1); coll.Insert(1, map2); coll.Add(map3); Assert.AreEqual(3, coll.Count); Assert.AreEqual(coll[2].GetName(), "map3"); coll[1] = map4; string txt = ""; foreach (MgMap map in coll) { txt += "[" + map.GetName() + "]"; } Assert.AreEqual("[map1][map4][map3]", txt); }
public MgMapBase CreateMap(MgResourceIdentifier resId) { //The test suite relies on the same map and not a new one //re-created on each test of that particular test suite if (_map != null) return _map; _map = new MgMap(); _map.Create(_resSvc, resId, resId.GetName()); return _map; }
public string getPlanMapImageAsBase64String(string planID, string imageWidth, string imageHeight) { try { MgUserInformation userInfo = null; string mapWebTierInit = ConfigurationManager.AppSettings["MGWebTierInit"].ToString(); MapGuideApi.MgInitializeWebTier(mapWebTierInit); // Om kartsession finns för applikationssession använd den annars skapa ny kartssitesession string mapSiteSessionID = null; if (Session["MapSiteSessionID"] != null) { mapSiteSessionID = Session["MapSiteSessionID"].ToString(); userInfo = new MgUserInformation(mapSiteSessionID); } else { // Initierar kartsite och kartsession string mapUserName = ConfigurationManager.AppSettings["MGUserName"].ToString(); string mapUserPass = ConfigurationManager.AppSettings["MGUserPass"].ToString(); userInfo = new MgUserInformation(mapUserName, mapUserPass); MgSite mapSite = new MgSite(); mapSite.Open(userInfo); userInfo.Dispose(); mapSiteSessionID = mapSite.CreateSession(); //mapSite.Close(); Session["MapSiteSessionID"] = mapSiteSessionID; userInfo = new MgUserInformation(mapSiteSessionID); } //bool test = resSvc.ResourceExists(mapResId); string mapSurfaceFactor = ConfigurationManager.AppSettings["MGMapSurfaceFactor"].ToString(); string mapRes = ConfigurationManager.AppSettings["MGMapResource"].ToString(); string planRes = ConfigurationManager.AppSettings["MGPlanytorResource"].ToString(); string planClassName = ConfigurationManager.AppSettings["MGPlanytorClassName"].ToString(); string planFilterColumn = ConfigurationManager.AppSettings["MGPlanytorFilterColumn"].ToString(); string planGeometryColumn = ConfigurationManager.AppSettings["MGPlanytorGeometryColumn"].ToString(); string planytorStrokeRgbaColor = ConfigurationManager.AppSettings["MGPlanytorStrokeRgbaColor"].ToString(); string planytorForegroundRgbaColor = ConfigurationManager.AppSettings["MGPlanytorForegroundRgbaColor"].ToString(); string mapImageSizeFromServer = ConfigurationManager.AppSettings["MGMapImageSizeFromServer"].ToString(); // Standardvärde för storlek på kartbild, används om värde ej finns i Settings.config eller skickas in som parametrar i webbmetod string mapImageWidthPixel = "400"; string mapImageHeightPixel = "300"; // Väljer bredd och höjd på kartbild om värde ska finnas i Settings.config samt indikeras att de ska användas // annars förväntas värde skickas med i webbmetod if (mapImageSizeFromServer.ToLower() == "true") { mapImageWidthPixel = ConfigurationManager.AppSettings["MGMapImageWidth"].ToString(); mapImageHeightPixel = ConfigurationManager.AppSettings["MGMapImageHeight"].ToString(); } else { if (!string.IsNullOrWhiteSpace(imageWidth) && !string.IsNullOrWhiteSpace(imageHeight)) { mapImageWidthPixel = imageWidth; mapImageHeightPixel = imageHeight; } } MgSiteConnection siteConnection = new MgSiteConnection(); siteConnection.Open(userInfo); MgResourceService resSvc = (MgResourceService)siteConnection.CreateService(MgServiceType.ResourceService); MgResourceIdentifier mapResId = new MgResourceIdentifier(mapRes); MgFeatureService featSvc = (MgFeatureService)siteConnection.CreateService(MgServiceType.FeatureService); MgResourceIdentifier planResId = new MgResourceIdentifier(planRes); // Filter för planDoc efter planDoc-ID MgFeatureQueryOptions featureQuery = new MgFeatureQueryOptions(); featureQuery.SetFilter(planFilterColumn + " = " + planID); MgFeatureReader featureReader = featSvc.SelectFeatures(planResId, planClassName, featureQuery); MgByteReader byteReaderGeometry = null; MgAgfReaderWriter agfReaderWriter = new MgAgfReaderWriter(); MgGeometryCollection geometryCollection = new MgGeometryCollection(); int featureCount = 0; try { while (featureReader.ReadNext()) { byteReaderGeometry = featureReader.GetGeometry(planGeometryColumn); MgGeometry districtGeometry = agfReaderWriter.Read(byteReaderGeometry); geometryCollection.Add(districtGeometry); featureCount++; } } finally { featureReader.Close(); } MgGeometryFactory geometryFactory = new MgGeometryFactory(); MgMultiGeometry multiGeometry = geometryFactory.CreateMultiGeometry(geometryCollection); MgMap map = new MgMap(siteConnection); MgEnvelope envelope = multiGeometry.Envelope(); // Anpassar ev. punkt till komma i tal som hanteras som textsträng för kommande konvertering if (mapImageHeightPixel.IndexOf(".") != -1) { mapImageHeightPixel = mapImageHeightPixel.Replace(".", ","); } if (mapImageWidthPixel.IndexOf(".") != -1) { mapImageWidthPixel = mapImageWidthPixel.Replace(".", ","); } // Önskad bilds höjd och bredd i punkter double imageHeightPixel = Convert.ToDouble(mapImageHeightPixel); double imageWidthPixel = Convert.ToDouble(mapImageWidthPixel); map.DisplayDpi = 120; double heightEnvelopeN = envelope.Height; double widthEnvelopeE = envelope.Width; // Anpassar utbredningen på sökta planer (envelope) till bildens format för att bevara skalriktighet string mapFarthest = string.Empty; if (heightEnvelopeN > widthEnvelopeE) mapFarthest = "height"; else mapFarthest = "width"; string imageFarthest = string.Empty; if (imageHeightPixel > imageWidthPixel) imageFarthest = "height"; else imageFarthest = "width"; double scale = 1.0; const double inch = 2.54; // Ändring av kartans utbredning och addering av utrymme i kartans bild runt planavgränsningen // Map = avgränsning enligt planytan (utbredning i kartan), Image = önskad bild att skapa med kartan // Om: kartans höjd är längst & bildens bredd är längst if (mapFarthest == "height" && imageFarthest == "width") { scale = imageWidthPixel / imageHeightPixel * inch; widthEnvelopeE = imageWidthPixel / imageHeightPixel * heightEnvelopeN * scale; } // Om: kartans bredd är längst & bildens höjd är längst else if (mapFarthest == "width" && imageFarthest == "height") { scale = imageHeightPixel / imageWidthPixel * inch; heightEnvelopeN = imageHeightPixel / imageWidthPixel * widthEnvelopeE * scale; } // Om: kartans höjd är längst & bildens höjd är längst else if (mapFarthest == "height" && imageFarthest == "height") { double compareSide = (heightEnvelopeN / (imageHeightPixel / imageWidthPixel)); bool isCompareSideFarthest = false; if (compareSide > widthEnvelopeE) { isCompareSideFarthest = true; } else { isCompareSideFarthest = false; } scale = imageHeightPixel / imageWidthPixel * inch; if (isCompareSideFarthest) { widthEnvelopeE = heightEnvelopeN / (imageHeightPixel / imageWidthPixel) * scale; } else { heightEnvelopeN = (imageHeightPixel / imageWidthPixel) * widthEnvelopeE * scale; } } // Om(annars): kartans bredd är längst & bildens bredd är längst else { double compareSide = (widthEnvelopeE / (imageWidthPixel / imageHeightPixel)); bool isCompareSideFarthest = false; if (compareSide > heightEnvelopeN) { isCompareSideFarthest = true; } else { isCompareSideFarthest = false; } scale = imageWidthPixel / imageHeightPixel * inch; if (isCompareSideFarthest) { heightEnvelopeN = widthEnvelopeE / (imageWidthPixel / imageHeightPixel) * scale; } else { widthEnvelopeE = heightEnvelopeN * (imageWidthPixel / imageHeightPixel) * scale; } } double mapSurfaceFactorDbl = Convert.ToDouble(mapSurfaceFactor.Replace('.', ',')); double newHeightN = heightEnvelopeN * mapSurfaceFactorDbl; double newWidthE = widthEnvelopeE * mapSurfaceFactorDbl; MgCoordinate lowerLeft = envelope.LowerLeftCoordinate; MgCoordinate upperRight = envelope.UpperRightCoordinate; envelope = new MgEnvelope(lowerLeft.X - (newWidthE - widthEnvelopeE) / 2, lowerLeft.Y - (newHeightN - heightEnvelopeN) / 2, upperRight.X + (newWidthE - widthEnvelopeE) / 2, upperRight.Y + (newHeightN - heightEnvelopeN) / 2); map.Create(resSvc, mapResId, mapResId.Name); // Skapa lagerdefinition i XML DefineAreaLayer areaLayer = new DefineAreaLayer(); areaLayer.FeatureName = planClassName; areaLayer.FeatureSourceName = planRes; areaLayer.GeometryColumnName = planGeometryColumn; areaLayer.Filter = planFilterColumn + " = " + planID; LayerScaleRangeCollection lsrCollection = new LayerScaleRangeCollection(); LayerScaleRange lsr = new LayerScaleRange(); // MinScale applikations-default till 0 (inklusive) om utelämnat, MaxScale applikations-default till kartans maxskala (exklusive) om utelämnat //lsr.MinScale = "0"; //lsr.MaxScale = "100000000"; AreaTypeStyle ats = new AreaTypeStyle(); AreaRuleCollection arCollection = new AreaRuleCollection(); AreaRule ar = new AreaRule(); //ar.Filter = planFilterColumn + " = " + planID; ar.LegendLabel = "Plan" + planID; AreaSymbolization2D symb2D = new AreaSymbolization2D(); Fill fill = new Fill(); fill.BackgroundColor = "FFFF0000"; fill.FillPattern = "Solid"; fill.ForegroundColor = convertRgbsToHexColor(planytorForegroundRgbaColor); Stroke stroke = new Stroke(); stroke.Color = convertRgbsToHexColor(planytorStrokeRgbaColor); stroke.LineStyle = "Solid"; stroke.Thickness = "1"; stroke.Unit = "Points"; symb2D.Fill = fill; symb2D.Stroke = stroke; ar.Symbolization2D = symb2D; arCollection.Add(ar); ats.AreaRules = arCollection; lsr.AreaTypeStyle = ats; lsrCollection.Add(lsr); areaLayer.LayerScaleRanges = lsrCollection; XmlDocument xmlFile = new XmlDocument(); //XDocument xmlFile = new XDocument(); // om returnerande av xml-dokument //xmlFile = areaLayer.CreateLayerDefinitionAsXmlDocument(); // om returnerande av xml-sträng xmlFile.LoadXml(areaLayer.CreateLayerDefinitionAsXmlString()); //xmlFile = areaLayer.CreateLayerDefinitionAsXDocument(); //xmlFile.Save(Server.MapPath(this.Context.Request.ApplicationPath) + "XmlTestLayerDefinition.xml"); using (MemoryStream msNewPlanLayer = new MemoryStream()) { xmlFile.Save(msNewPlanLayer); msNewPlanLayer.Position = 0L; //Note we do this to ensure our XML content is free of any BOM characters byte[] layerDefinition = msNewPlanLayer.ToArray(); Encoding utf8 = Encoding.UTF8; String layerDefStr = new String(utf8.GetChars(layerDefinition)); layerDefinition = new byte[layerDefStr.Length - 1]; int byteCount = utf8.GetBytes(layerDefStr, 1, layerDefStr.Length - 1, layerDefinition, 0); // Save the new layer definition to the session repository MgByteSource byteSource = new MgByteSource(layerDefinition, layerDefinition.Length); MgResourceIdentifier layerResourceID = new MgResourceIdentifier("Session:" + mapSiteSessionID + "//" + "planytor" + ".LayerDefinition"); //"SearchedPlan" + planID + ".LayerDefinition"); resSvc.SetResource(layerResourceID, byteSource.GetReader(), null); MgLayer newPlanLayer = new MgLayer(layerResourceID, resSvc); newPlanLayer.SetName("Sökta planer"); newPlanLayer.SetVisible(true); newPlanLayer.SetLegendLabel("Sökta planer"); newPlanLayer.SetDisplayInLegend(true); MgLayerCollection layerCollection = map.GetLayers(); if (!layerCollection.Contains(newPlanLayer)) { // Insert the new layer at position 0 so it is at the top // of the drawing order layerCollection.Insert(0, newPlanLayer); } else { layerCollection.Remove(newPlanLayer); layerCollection.Insert(0, newPlanLayer); } map.Save(); } double mapScale = map.ViewScale; // XML-dokument till ren text //StringWriter stringWriter = new StringWriter(); //XmlWriter xmlTextWriter = XmlWriter.Create(stringWriter); //xmlFile.WriteTo(xmlTextWriter); //xmlTextWriter.Flush(); string xmlSelection = string.Empty; //string xmlSelection = stringWriter.GetStringBuilder().ToString(); MgSelection selection = null; if (!string.IsNullOrEmpty(xmlSelection)) { selection = new MgSelection(map, xmlSelection); } else { selection = new MgSelection(map); } MgColor color = new MgColor("255,255,255"); // Skapar bild av kartan MgRenderingService renderingService = (MgRenderingService)siteConnection.CreateService(MgServiceType.RenderingService); //MgByteReader byteReader = renderingService.RenderMap(map, selection, "PNG"); MgByteReader byteReader = renderingService.RenderMap(map, selection, envelope, Convert.ToInt32(imageWidthPixel), Convert.ToInt32(imageHeightPixel), color, "PNG"); MemoryStream ms = new MemoryStream(); byte[] byteBuffer = new byte[1024]; int numBytes = byteReader.Read(byteBuffer, 1024); while (numBytes > 0) { ms.Write(byteBuffer, 0, numBytes); numBytes = byteReader.Read(byteBuffer, 1024); } byte[] mapImageByte = ms.ToArray(); string imageBase64String = Convert.ToBase64String(mapImageByte); map.Dispose(); siteConnection.Dispose(); DataTable dtResult = new DataTable(); DataColumn dc = new DataColumn("MAPIMAGEBASE64"); dtResult.Columns.Add(dc); dc = new DataColumn("WIDTH"); dtResult.Columns.Add(dc); dc = new DataColumn("HEIGHT"); dtResult.Columns.Add(dc); DataRow dr = dtResult.NewRow(); dr["MAPIMAGEBASE64"] = imageBase64String; dr["WIDTH"] = imageWidthPixel; dr["HEIGHT"] = imageHeightPixel; dtResult.Rows.Add(dr); //TODO: MAP: Vad kan returneras, base64 eller länk där bild temporärt genereras på server //JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); //return jsonSerializer.Serialize(imageBase64String); return getDatatableAsJson(dtResult); } catch (System.Exception ex) { UtilityException.LogException(ex, "Webbmetod : getPlanMapImageAsBase64String", true); return null; } }