这是一个非常全面的讨论如何利用MapXtreme2004开发应用功能的介绍文档,共200多页,内容涉及到MapXtreme.net(2004)的方方面面,不过是英文的,对于英文好的朋友强烈推荐。
What is the equivalent function for ConvertCoord?
I need to convert the screen pixel to map lat/lon coordinates. I can use the Map.Convertcoord in the old version, but what is the equivalent method in 2004?
Thanks.
Re: What is the equivalent function for ConvertCoord?
I figured it this one out. It's the Map.DisplayTransform. It would be nice if there is a way to delete my own topic so that I wouldn't have to consume your time. Thanks.
LabelLayer invisible
I know how I can make a layer visible/invisible by using enabled true/false. But how do I do the same thing with a labellayer?
I am creating a web project using VB.NET. A small code example would be nice!
Re: LabelLayer invisible
You would use the same enabled true/false property. Here's an example:
Dim fl As MapInfo.Mapping.FeatureLayer
Dim ll As New MapInfo.Mapping.LabelLayer
Dim ls As MapInfo.Mapping.LabelSource
fl = MapControl1.Map.Layers(0)
ll = New MapInfo.Mapping.LabelLayer("test")
ls = New MapInfo.Mapping.LabelSource(fl.Table, "testsource")
ll.Sources.Append(ls)
MapControl1.Map.Layers.Add(ll)
ll.Enabled = False
Cindy
MapInfo Technical Support
Re: LabelLayer invisible
I can磘 make your code work! I have a label layer called "xxxxx" in my mws file. I have implemented your code using a button to set the label layer invisible:
Dim myLabel As MapInfo.Mapping.LabelLayer
myLabel = New MapInfo.Mapping.LabelLayer("xxxxx")
myLabel.Enabled = False
But when I click the button, the label layer is not turned off.
Re: LabelLayer invisible
Here are two ways you could do it. Get the label layer and then set enabled to false:
Dim ll As MapInfo.Mapping.LabelLayer = MapControl1.Map.Layers("Worldlabels")
ll.Enabled = False
Or, you can filter out the label layers and set enabled to false:
Dim l As IMapLayer
For Each l In MapControl1.Map.Layers.GetMapLayerEnumerator(New FilterByLayerType(LayerType.Label))
l.Enabled = False
Next
Dispersing Features
I want to plot several features at the same co-ordinates on a map. However, the features appear as one feature, not serveral, due to the fact that they overlap each other.
How can I disperse features around a point? I have been told that this is possible in Mapinfo Professional. Can I do it with MapXtreme 2004?
Re: Dispersing Features
There is a tool in MapInfo that will disperse points for you. But, there really isn't a similar canned function in MapXtreme 2004. You can write your own code to do this offsetting the coordinates for each feature that is located at the same location.
Labeling map layers
I have a workspace with a number of layers that have their labels set at design time using the Workspace Manager. However, each user will see his/her own retail location on the map. This retail location layer is loaded at runtime. How can I set the label properties (font, text size, colour, etc.) for the retailer location layer at runtime? The key, however, is that these properties will change depending on the type of map, so I cannot hard code them. Is there some way that I can create a LabelSource for the retailer location layer, but take its properties from another layer on the map (i.e. make the labels the same as those of another layer)?
Re: Labeling map layers
Does anyone know how to accomplish this?
Re: Labeling map layer s
Give this approach a try. As you are setting up your new LabelSource clone the LabelProperties object of the from the label style you wish to copy. The one thing you'll have to do afterwards is to set the caption property.
Dim Cat As MapInfo.Data.Catalog = MapInfo.Engine.Session.Current.Catalog
Dim tblCities As MapInfo.Data.Table = Cat.GetTable("City_125")
Dim lsCities As New MapInfo.Mapping.LabelSource(tblCities, "My Label", "City_125")
Dim lblLayer As MapInfo.Mapping.LabelLayer = MapControl1.Map.Layers.Item(0) 'Label Layer
Dim lsUSA As MapInfo.Mapping.LabelSource = lblLayer.Sources.Item(0)
Dim lblStyle As MapInfo.Mapping.LabelProperties = lsUSA.DefaultLabelProperties.Clone
lblStyle.Caption = lsCities.DefaultLabelProperties.Caption.Clone
lsCities.DefaultLabelProperties.Apply(lblStyle)
lblLayer.Sources.Append(lsCities)
Re: Labeling map layers
Thanks, John. This works great! One other question, though and this might be related to Workspace Manager: How can I ensure that the labels for this layer appear above all other labels? Essentially, what's happening is that when my retail location is added to the map, it's label properties are set using the method you outlined, but the label cannot be seen unless I zoom in. I do not have a zoom range set for the labels in my "dummy layer" (the one whose properties I've cloned). And in Workspace Manager, I have set the dummy layer's labels to allow both duplicate and overlapping text. However, some of my other layers (e.g. roads) do not allow overlapping text.
Do I need to somehow order or set the priority for the new retail location label layer so that it's labels are visible above the labels of all other layers?
Getting attribute data from a selection
1. When I do a selection with one of the select tools in an asp.net maxptreme app I can grab the selected features as a resultsetfeaturecollection
but..
that fc.table only contains the MI_key, Geometry, Mi_style columns
If I enumerate through the features in the collection - it too has only 3 columns. How do you get access to the other attribute data columns in a selection?
2. If I want to create a new layer from my selection - what is the easiest way to do this? (not a mapinof tab file, just a feature layer that will remain for that asp.net session - but which will not be altered when I select something else.
Re: Getting attribute data from a selection
This returned all the fields for me:
FeatureLayer lyr=mapControl1.Map.Layers["USa"] as FeatureLayer ;
IResultSetFeatureCollection irfc = Session.Current.Selections.DefaultSelection[lyr.Table ];
foreach(MapInfo.Data.Feature l in irfc )
{
foreach(MapInfo.Data.Column column in l.Columns)
{
//print out the column name and contents with the following:
MessageBox.Show (string.Format("{0}:{1}",column.ToString().ToUpper(),l[column.ToString()].ToString()));
}
}
To create a table from your selected features, you can use TableInfoFactory.CreateFromFeatureCollection. From the on-line help:
The returned TableInfo can be modified or customized and then passed to a Catalog.CreateTable(). If you want to add the rows from the feature collection into the table, use the ITableFeatureCollection.Add method on the table you created.
Or, perform the selection using a query:
MapInfo.Data.Table t=Session.Current.Catalog.OpenTable ("c:\\program files\\mapinfo\\mapx 5.0\\maps\\uscty_1k.tab");
MapInfo.Data.TableInfoView ti = new MapInfo.Data.TableInfoView ("NYCities", "select * from uscty_1k where state='NY'");
MapInfo.Data.Table tbl= Session.Current.Catalog.OpenTable(ti);
MapInfo.Data.SearchInfo si=MapInfo.Data.SearchInfoFactory.SearchAll ();
MapInfo.Data.IResultSetFeatureCollection irfc=MapInfo.Engine.Session.Current.Catalog.Search(tbl.Alias,si);
mapControl1.Map.Load(new MapTableLoader(tbl ));
FeatureLayer lyr = mapControl1.Map.Layers[0] as FeatureLayer;
mapControl1.Map.SetView(irfc);
Re: Getting attribute data from a selection
That code does not work for me - I just get the same 3 columns
In your code do you have more than one layer?
Are the layers TableInfoServer layers?
Is your application an asp.net app? (I would guess not from the messagebox code)
Maybe the asp.net app selections don't behave the same way?
Re: Getting attribute data from a selection
Here's another example:
MIConnection Connection =new MIConnection ();
Connection.Open() ;
FeatureLayer lyr=mapControl1.Map.Layers["USa"] as FeatureLayer ;
MapInfo.Data.Table ti = MapInfo.Engine.Session.Current.Catalog.GetTable("usa");
MapInfo.Data.SearchInfo si = MapInfo.Data.SearchInfoFactory.SearchAll();
si.QueryDefinition.SetColumns("*");
MapInfo.Data.IResultSetFeatureCollection irfc = MapInfo.Engine.Session.Current.Catalog.Search(ti.Alias, si);
foreach(MapInfo.Data.Feature l in irfc )
{
foreach(MapInfo.Data.Column column in l.Columns)
{
MessageBox.Show (string.Format("{0}:{1}",column.ToString().ToUpper(),l[column.ToString()].ToString()));
}
}
Let me know if this still doesn't work for you.
Re: Getting attribute data from a selection
that code returns all the data columns (not just the three) - but how do I get the attribute data for just the features that the user has selected (with rectangle select tool etc.)
If you try this
1. Create a basic web mapxtreme asp.net map application
2. Load the world.gst or wms file from the sample data.
3. add a point selection tool and a rectangle selection tool.
4. start the app
5. make only 1 layer (e.g. world countries) selectable
6. select a country with the pointselection tool
you will see that all columns are in the default selection
7. select a group of countries with the rectangle selection tool
you will see that only the 3 mi columns are available (key, geometry and style).
why do the rectangle, radius and polygon selection tools only select these 3 columns ?? the documentation saya that 'all' selection tools implelement the query select MI_Key,* from 'table'
is there anyway of redefining the query for the selection tools so that they do include all columns?
By the way I notice that the simple pointselection tool in asp.net always returns all columns in the defaultselection - but the radius,rectangle and polygon selectiontools only return the 3 mapinfo columns
Re: Getting attribute data from a selection
I had to get the MI_KEYS from the features in the selction object, construct a SQL and get all coloumns through the new feature collection
Register a image file
As shown in the developer guide, you have to register your base image map from MapInfo Pro. Is there any way to register a image through MapXtreme 2004 by creating .Tab file programmatically? If possible, what image/vector formats are supported?
Re: Register a image file
No, there isn't anyway to register an image through MapXtreme 2004 and have it create the .TAB file automatically. You have to create the .TAB file yourself through a text editor.
Re: Register a image file
Thank you very much. Your solution works for me, but my application is going to be used by my clients. Where can I got the help document about .Tab file format? With the document, I can develop a simple tool to do it.