public void Execute(IPlatformFactory factory, ITestLogger logger) { 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); MgMapBase map1 = factory.CreateMap(coordsys, env, "map1"); MgMapBase map2 = factory.CreateMap(coordsys, env, "map2"); MgMapBase map3 = factory.CreateMap(coordsys, env, "map3"); MgMapBase map4 = factory.CreateMap(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 (MgMapBase map in coll) { txt += "[" + map.GetName() + "]"; } Assert.AreEqual("[map1][map4][map3]", txt); }
public MgMapBase CreateMap(string coordSys, MgEnvelope env, string name) { var map = new MgMap(_siteConn); map.Create(coordSys, env, name); return(map); }
/// <summary> /// Установка зумирования и активной выборки (запуск через командную строку - отсюда название) /// </summary> /// <param name="sel_base">выборка, которую следует отобразить</param> internal static void ThroughAssZoomAndSelection(MgSelectionBase sel_base) { internal_saved_selection = AcMapFeatureEntityService.AddFeaturesToSelectionSet(null, sel_base); // преобразование в SelectionSet и обратно, sel_base = AcMapFeatureEntityService.GetSelection(internal_saved_selection); // иначе дает сбой метод GetSelectedFeatures() MgEnvelope extents = new MgEnvelope(); MgReadOnlyLayerCollection layers = sel_base.GetLayers(); foreach (MgLayerBase layer in layers) { MgFeatureReader ftr_reader = sel_base.GetSelectedFeatures(layer, layer.FeatureClassName, false); string geom_prop_name = ftr_reader.GetClassDefinition().DefaultGeometryPropertyName; while (ftr_reader.ReadNext()) { MgByteReader byte_reader = ftr_reader.GetGeometry(geom_prop_name); MgAgfReaderWriter agf_reader_writer = new MgAgfReaderWriter(); MgGeometry curr_geom = agf_reader_writer.Read(byte_reader); extents.ExpandToInclude(curr_geom.Envelope()); } } // зумирование и вызов функции выбора через командную строку Core.no_handle_selection = true; // чтобы изменение выборки не обрабатывалось string zoom_str; if ((extents.Width == 0) && (extents.Width == extents.Height)) { zoom_str = "'_zoom _c " + extents.LowerLeftCoordinate.X.ToString() + "," + extents.LowerLeftCoordinate.Y.ToString() + " "; } else { zoom_str = "'_zoom _w " + (extents.LowerLeftCoordinate.X - extents.Width / 2).ToString() + "," + (extents.LowerLeftCoordinate.Y - extents.Height / 2).ToString() + " " + (extents.UpperRightCoordinate.X + extents.Width / 2).ToString() + "," + (extents.UpperRightCoordinate.Y + extents.Height / 2).ToString(); } Core.SendStringToExecute(zoom_str + "\n" + "ThroughAssZoomAndSelectionHelperFunction\n" , true, false, false); }
public void Execute(IPlatformFactory factory, ITestLogger logger) { MgEnvelope env = new MgEnvelope(-180, -90, 180, 90); Assert.AreEqual(-180, env.LowerLeftCoordinate.GetX()); Assert.AreEqual(-90, env.LowerLeftCoordinate.GetY()); Assert.AreEqual(180, env.UpperRightCoordinate.GetX()); Assert.AreEqual(90, env.UpperRightCoordinate.GetY()); Assert.AreEqual(360, env.Width); Assert.AreEqual(180, env.Height); Assert.IsNaN(env.Depth); }
public static string MgEnvelopeToString(MgEnvelope env) { try { var ll = env.GetLowerLeftCoordinate(); var ur = env.GetUpperRightCoordinate(); return(string.Format(CultureInfo.InvariantCulture, "({0}:{1})-({2}:{3})", ll.GetX(), ll.GetY(), ur.GetX(), ur.GetY())); } catch (MgException ex) { throw new UnitTestException(string.Format("Exception from MapGuide:\n{0}", ex.GetDetails())); } }
public void Execute(IPlatformFactory factory, ITestLogger logger) { 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 = (MgMap)factory.CreateMap(coordsys, env, "map1"); MgMap map2 = (MgMap)factory.CreateMap(coordsys, env, "map2"); MgMap map3 = (MgMap)factory.CreateMap(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); }
private void btnCreateRdbms_Click(object sender, EventArgs e) { try { var fact = new MgdServiceFactory(); var featureSvc = (MgdFeatureService)fact.CreateService(MgServiceType.FeatureService); var param = new MgdRdbmsFeatureSourceParams(); param.CoordinateSystemWkt = txtCoordinateSystemWkt.Text; param.Service = txtService.Text; param.DataStore = txtDataStore.Text; param.Username = txtUsername.Text; param.Password = txtPassword.Text; var schemas = featureSvc.XmlToSchema(File.ReadAllText(txtSchemaXml.Text)); param.FeatureSchema = schemas.GetItem(0); param.ProviderName = txtProvider.Text; param.SpatialContextDescription = "Created from MgFileFeatureSourceParams"; param.SpatialContextName = txtCoordinateSystemName.Text; param.XYTolerance = double.Parse(txtXYTolerance.Text); param.ZTolerance = double.Parse(txtZTolerance.Text); string[] tokens = txtExtents.Text.Split(',').Select(x => x.Trim()).ToArray(); MgEnvelope env = new MgEnvelope( double.Parse(tokens[0]), double.Parse(tokens[1]), double.Parse(tokens[2]), double.Parse(tokens[3])); param.SpatialContextExtents = env; var fsId = new MgResourceIdentifier(txtResourceId.Text); featureSvc.CreateFeatureSource(fsId, param); MessageBox.Show("Success"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
private void btnZoom_Click(object sender, EventArgs e) { //Collect the bounding boxes of all geometries and zoom to that MgEnvelope env = new MgEnvelope(); int idx = Array.IndexOf(_columns, _geomProp); if (idx < 0) { MessageBox.Show(string.Format(Strings.ErrorGeometryPropertyNotFound, _geomProp)); return; } foreach (DataGridViewRow row in grdResults.SelectedRows) { var geom = row.Cells[idx].Value as BoxedGeometry; MgEnvelope tmp = new MgEnvelope(geom.GeomBounds.LowerX, geom.GeomBounds.LowerY, geom.GeomBounds.UpperX, geom.GeomBounds.UpperY); env.ExpandToInclude(tmp); } var ll = env.LowerLeftCoordinate; var ur = env.UpperRightCoordinate; _viewer.ZoomToExtents(ll.X, ll.Y, ur.X, ur.Y); }
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 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; } }
public override void Invoke() { var viewer = this.Viewer; var sel = viewer.GetSelection(); var selLayers = sel.GetLayers(); if (selLayers == null) { MessageBox.Show(Strings.TextNoSelection); return; } //This doesn't work :( // //var provider = viewer.GetProvider(); //var featSvc = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService); //var ext = sel.GetExtents(featSvc); //var ll = ext.LowerLeftCoordinate; //var ur = ext.UpperRightCoordinate; //viewer.ZoomToExtents(ll.X, ll.Y, ur.X, ur.Y); MgEnvelope env = new MgEnvelope(); if (_agfRw == null) { _agfRw = new MgAgfReaderWriter(); } for (var i = 0; i < selLayers.GetCount(); i++) { var layer = selLayers.GetItem(i); var fr = sel.GetSelectedFeatures(layer, layer.FeatureClassName, false); try { string geomName = layer.GetFeatureGeometryName(); while (fr.ReadNext()) { if (!fr.IsNull(geomName)) { MgByteReader agf = null; MgGeometry geom = null; try { agf = fr.GetGeometry(geomName); geom = _agfRw.Read(agf); env.ExpandToInclude(geom.Envelope()); } finally { if (agf != null) { agf.Dispose(); agf = null; } if (geom != null) { geom.Dispose(); geom = null; } } } } } finally { fr.Close(); } } var ll = env.LowerLeftCoordinate; var ur = env.UpperRightCoordinate; viewer.ZoomToExtents(ll.X, ll.Y, ur.X, ur.Y); }
public override void Invoke() { var viewer = this.Viewer; var sel = viewer.GetSelection(); var selLayers = sel.GetLayers(); if (selLayers == null) { MessageBox.Show(Strings.TextNoSelection); return; } //This doesn't work :( // //var provider = viewer.GetProvider(); //var featSvc = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService); //var ext = sel.GetExtents(featSvc); //var ll = ext.LowerLeftCoordinate; //var ur = ext.UpperRightCoordinate; //viewer.ZoomToExtents(ll.X, ll.Y, ur.X, ur.Y); MgEnvelope env = new MgEnvelope(); if (_agfRw == null) _agfRw = new MgAgfReaderWriter(); for (var i = 0; i < selLayers.GetCount(); i++) { var layer = selLayers.GetItem(i); var fr = sel.GetSelectedFeatures(layer, layer.FeatureClassName, false); try { string geomName = layer.GetFeatureGeometryName(); while (fr.ReadNext()) { if (!fr.IsNull(geomName)) { MgByteReader agf = null; MgGeometry geom = null; try { agf = fr.GetGeometry(geomName); geom = _agfRw.Read(agf); env.ExpandToInclude(geom.Envelope()); } finally { if (agf != null) { agf.Dispose(); agf = null; } if (geom != null) { geom.Dispose(); geom = null; } } } } } finally { fr.Close(); } } var ll = env.LowerLeftCoordinate; var ur = env.UpperRightCoordinate; viewer.ZoomToExtents(ll.X, ll.Y, ur.X, ur.Y); }
public override System.IO.Stream RenderRuntimeMap(RuntimeMap rtmap, double x1, double y1, double x2, double y2, int width, int height, int dpi, string format, bool clip) { var resourceId = rtmap.ResourceID; MgRenderingService rnd = this.Connection.CreateService(MgServiceType.RenderingService) as MgRenderingService; MgResourceService res = this.Connection.CreateService(MgServiceType.ResourceService) as MgResourceService; MgGeometryFactory gf = new MgGeometryFactory(); string mapname = new ResourceIdentifier(resourceId).Path; //TODO: The render is missing the clip param for the extent override method GetByteReaderMethod fetch = () => { MgMap map = new MgMap(); map.Open(res, mapname); MgSelection sel = new MgSelection(map); //The color accepted by MgColor has alpha as the last value, but the returned has alpha first MgColor color = new MgColor(Utility.ParseHTMLColor(map.GetBackgroundColor())); MgEnvelope env = new MgEnvelope(gf.CreateCoordinateXY(x1, y1), gf.CreateCoordinateXY(x2, y2)); return rnd.RenderMap(map, sel, env, width, height, color, format); }; LogMethodCall("MgRenderingService::RenderMap", true, "MgMap", "MgSelection", "MgEnvelope", width.ToString(), height.ToString(), "MgColor", format); return new MgReadOnlyStream(fetch); }
public void Envelope() { MgEnvelope env = new MgEnvelope(-180, -90, 180, 90); Assert.AreEqual(-180, env.LowerLeftCoordinate.GetX()); Assert.AreEqual(-90, env.LowerLeftCoordinate.GetY()); Assert.AreEqual(180, env.UpperRightCoordinate.GetX()); Assert.AreEqual(90, env.UpperRightCoordinate.GetY()); Assert.AreEqual(360, env.Width); Assert.AreEqual(180, env.Height); Assert.IsNaN(env.Depth); }
public override void Execute(IPlatformFactory factory, ITestLogger logger) { //For a map definition that links to a default provider tile set and both have the same coordinate //system, it should be using the map definition's extents and we should not have null extents or view //center MgCoordinateSystemFactory csFactory = new MgCoordinateSystemFactory(); string csWkt = csFactory.ConvertCoordinateSystemCodeToWkt("LL84"); MgResourceService resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService); var root = "../../TestData/TileService/"; LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs"); LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf"); LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf"); LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs"); LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf"); LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf"); LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs"); LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf"); LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf"); string tsd = Encoding.UTF8.GetString(Properties.Resources.UT_BaseMapTileSet); tsd = string.Format(tsd, csWkt, -87.5, 43.5, -86.5, 44.5); byte[] tsdBytes = Encoding.UTF8.GetBytes(tsd); MgByteSource sourceTSD = new MgByteSource(tsdBytes, tsdBytes.Length); MgByteReader contentTSD = sourceTSD.GetReader(); MgResourceIdentifier resTSD = new MgResourceIdentifier("Library://UnitTests/TileSets/Test.TileSetDefinition"); resSvc.SetResource(resTSD, contentTSD, null); string mdf = Encoding.UTF8.GetString(Properties.Resources.UT_LinkedTileSet); mdf = string.Format(mdf, csWkt, -87.0, 43.0, -86.0, 44.0, resTSD.ToString()); byte[] mdfBytes = Encoding.UTF8.GetBytes(mdf); MgByteSource sourceMDF = new MgByteSource(mdfBytes, mdfBytes.Length); MgByteReader contentMDF = sourceMDF.GetReader(); MgResourceIdentifier resMDF = new MgResourceIdentifier("Library://UnitTests/Maps/LinkedTileSet.MapDefinition"); resSvc.SetResource(resMDF, contentMDF, null); MgMapBase map = factory.CreateMap(resMDF); MgEnvelope extent = map.GetMapExtent(); Assert.IsNotNull(extent); Assert.IsNotNull(map.MapExtent); MgPoint center = map.GetViewCenter(); Assert.IsNotNull(center); Assert.IsNotNull(map.ViewCenter); MgCoordinate ll = extent.GetLowerLeftCoordinate(); MgCoordinate ur = extent.GetUpperRightCoordinate(); Assert.IsNotNull(ll); Assert.IsNotNull(ur); Assert.AreEqual(-87.0, ll.X); Assert.AreEqual(43.0, ll.Y); Assert.AreEqual(-86.0, ur.X); Assert.AreEqual(44.0, ur.Y); }