private void map1_MouseDown(object sender, MouseButtonEventArgs e) { if (createPoint) { System.Windows.Point clickPoint = e.GetPosition(map1); getMapClick(clickPoint); createPoint = false; } } private void getMapClick(System.Windows.Point clickPoint) { try { Envelope env = map1.GetRotatedExtent(); Coordinate coord; //GeoTransformation geoTransform = new GeoTransformation(SpatialReference.Create(3857)); // WGS 1984 Web Mecrator Auxiliary Sphere transformer //SpatialReferenceConverter src = new SpatialReferenceConverter(SpatialReference.CreateWgs84SpatialReference(), SpatialReference.Create(3857), geoTransform); System.Drawing.Point point = new System.Drawing.Point(Convert.ToInt32(clickPoint.X), Convert.ToInt32(clickPoint.Y)); coord = map1.ToMap(point); //System.Windows.MessageBox.Show("map coord" + coord.X.ToString() + " " + coord.Y.ToString()); saveNewObservation(new ESRI.ArcGIS.Mobile.Geometries.Point(coord)); } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message.ToString(), "Map Click Error"); } } private void saveNewObservation(ESRI.ArcGIS.Mobile.Geometries.Point point) { try { //get feature layer FeatureLayer featureLayer = getFeatureLayer("Observations", mobileCache); //if still null if (featureLayer == null) { System.Windows.MessageBox.Show("Could not find feature layer 'Observations' in map cache", "Search Error", MessageBoxButton.OK, MessageBoxImage.Error); } //create datareader FeatureDataTable featDataTable = featureLayer.GetDataTable(new QueryFilter()); DataRow newFeatDataRow = featDataTable.NewRow(); newFeatDataRow[featDataTable.GeometryColumnIndex] = point; //populate new row with some defatul data values newFeatDataRow["OBSERVATIONID"] = "1"; newFeatDataRow["TYPEID"] = 1; newFeatDataRow["STATUS"] = "Active"; newFeatDataRow["CREATEDATE"] = DateTime.Now; featDataTable.Rows.Add(newFeatDataRow); //now save edits featureLayer.SaveEdits(featDataTable); featDataTable.Dispose(); featureLayer = null; } catch (Exception e) { System.Windows.MessageBox.Show(e.Message.ToString(), "saveNewObservation"); } }
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.