/// <summary> /// Select all features in all visible and selectable layers near a given point using a given pixel tolerance. /// </summary> /// <remarks>This method searches all features near a given point in all visible and selectable layers and then updates the /// default selection. /// </remarks> /// <param name="mapAlias">MapAlias of the map.</param> /// <param name="point">Point in pixels.</param> /// <param name="pixelTolerance">Pixel tolerance.</param> public void PointSelection(string mapAlias, System.Drawing.Point point, int pixelTolerance) { Map map = GetMapObj(mapAlias); // Do the search and show selections SearchInfo si = MapInfo.Mapping.SearchInfoFactory.SearchNearest(map, point, pixelTolerance); (si.SearchResultProcessor as ClosestSearchResultProcessor).Options = ClosestSearchOptions.StopAtFirstMatch; MapInfo.Geometry.Distance d = MapInfo.Mapping.SearchInfoFactory.ScreenToMapDistance(map, pixelTolerance); (si.SearchResultProcessor as ClosestSearchResultProcessor).DistanceUnit = d.Unit; (si.SearchResultProcessor as ClosestSearchResultProcessor).MaxDistance = d.Value; Session.Current.Selections.DefaultSelection.Clear(); IMapLayerFilter _selFilter = MapLayerFilterFactory.FilterForTools( map, MapLayerFilterFactory.FilterByLayerType(LayerType.Normal), MapLayerFilterFactory.FilterVisibleLayers(true), "MapInfo.Tools.MapToolsDefault.SelectLayers", null); ITableEnumerator table = map.Layers.GetTableEnumerator(_selFilter); if (table != null) // null will be returned is select enabled layer is not visible, thus non-selectable { Session.Current.Catalog.Search(table, si, Session.Current.Selections.DefaultSelection, ResultSetCombineMode.AddTo); } }
private void FindCity() { Find find = null; try { MapInfo.Mapping.Map map = null; // Get the map if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 || (map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null) { return; } // Do the find MapInfo.Mapping.FeatureLayer findLayer = (MapInfo.Mapping.FeatureLayer)map.Layers[_findLayerName]; find = new Find(findLayer.Table, findLayer.Table.TableInfo.Columns[_findColumnName]); FindResult result = find.Search(DropDownList1.SelectedItem.Text); if (result.ExactMatch) { // Create a Feature (point) for the location we found CoordSys csys = findLayer.CoordSys; FeatureGeometry g = new MapInfo.Geometry.Point(csys, result.FoundPoint.X, result.FoundPoint.Y); Feature f = new Feature(g, new MapInfo.Styles.SimpleVectorPointStyle(52, System.Drawing.Color.DarkGreen, 32)); // Delete the existing find object and add the new one MapInfo.Mapping.FeatureLayer workingLayer = (MapInfo.Mapping.FeatureLayer)map.Layers[_workingLayerName]; if (workingLayer != null) { (workingLayer.Table as ITableFeatureCollection).Clear(); workingLayer.Table.InsertFeature(f); } // Set the map's center and zooom map.Center = new DPoint(result.FoundPoint.X, result.FoundPoint.Y); MapInfo.Geometry.Distance d = new MapInfo.Geometry.Distance(1000, map.Zoom.Unit); map.Zoom = d; } else { this.Label3.Text = ("Cannot find the country"); } find.Dispose(); } catch (Exception) { if (find != null) { find.Dispose(); } } }
public override void Process() { MapControlModel model = MapControlModel.GetModelFromSession(); model.SetMapSize(MapAlias, MapWidth, MapHeight); MapInfo.Mapping.Map map = model.GetMapObj(MapAlias); if (map == null) { return; } MapInfo.Geometry.Distance savezoom = map.Zoom; map.Zoom = new MapInfo.Geometry.Distance(savezoom.Value * 4, savezoom.Unit); if (ExportFormat == "undefined") { ExportFormat = "Gif"; } System.IO.MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat); StreamImageToClient(ms); map.Zoom = savezoom; /* * MapControlModel model = MapControlModel.GetModelFromSession(); * Map oMap = model.GetMapObj(MapAlias); * if (oMap == null) * { * return; * } * * MapInfo.Geometry.Distance zoom = oMap.Zoom; * zoom = new MapInfo.Geometry.Distance(zoom.Value * 4, zoom.Unit ); * oMap.Zoom = zoom; * if (ExportFormat == "undefined" ) * { * ExportFormat = "Gif"; * } * System.IO.MemoryStream ms = model.GetMap(MapAlias, MapWidth, MapHeight, ExportFormat); * StreamImageToClient(ms); * zoom = new MapInfo.Geometry.Distance(zoom.Value / 4, zoom.Unit); * oMap.Zoom = zoom; */ }
private void FindCity() { Find find = null; try { MapInfo.Mapping.Map map = null; // Get the map if (MapInfo.Engine.Session.Current.MapFactory.Count == 0 || (map = MapInfo.Engine.Session.Current.MapFactory[MapControl1.MapAlias]) == null) { return; } // Do the find MapInfo.Mapping.FeatureLayer findLayer = (MapInfo.Mapping.FeatureLayer) map.Layers[_findLayerName]; find = new Find(findLayer.Table, findLayer.Table.TableInfo.Columns[_findColumnName]); FindResult result = find.Search(DropDownList1.SelectedItem.Text); if (result.ExactMatch) { // Create a Feature (point) for the location we found CoordSys csys = findLayer.CoordSys; FeatureGeometry g = new MapInfo.Geometry.Point(csys, result.FoundPoint.X, result.FoundPoint.Y); Feature f = new Feature(g, new MapInfo.Styles.SimpleVectorPointStyle(52, System.Drawing.Color.DarkGreen, 32)); // Delete the existing find object and add the new one MapInfo.Mapping.FeatureLayer workingLayer = (MapInfo.Mapping.FeatureLayer)map.Layers[_workingLayerName]; if (workingLayer != null) { (workingLayer.Table as ITableFeatureCollection).Clear(); workingLayer.Table.InsertFeature(f); } // Set the map's center and zooom map.Center = new DPoint(result.FoundPoint.X, result.FoundPoint.Y); MapInfo.Geometry.Distance d = new MapInfo.Geometry.Distance(1000, map.Zoom.Unit); map.Zoom = d; } else { this.Label3.Text = ("Cannot find the country"); } find.Dispose(); } catch (Exception) { if (find != null) find.Dispose(); } }