ThinkGeo.com    |     Documentation    |     Premium Support

Show Feature Data in the Table Grid

The following sample has something similar to what i am looking for.

http://samples.thinkgeo.com/WebApiEdition/SampleTemplates/QueryTools/openlayers/

The problem is that when I see the sample I do no see where the data is been past to the table view.

In the sample it returns a string, I tried to find who is calling that method but it does not show.

Thanks!!

Hi Jose,

Actually, that is a WebAPI sample, you can get the sample code click here.

We have the same sample for Web, please refer to http://samples.thinkgeo.com/webEdition/HowDoISamples/


Hope it can help you,

Thanks,
Emil

Correct, this sample is not the same as the other sample though.

As you can see the other table view shows in the bottom and its width is bigger. Do you know if what I have is an old sample?

Thanks!!
Jose

Hi Jose,

I think Emil means you hadn’t view the correct sample.

The sample you mentioned is for our WebAPI edition, but you put the post in our WebEdition sub fourm, so we think you are trying to implement that in our WebEdition, please make sure whether you want to find a sample for WebEdtion or WebAPI Edition?

If you want to show the bottom table in WebEdition, you should want to adjust the CSS for the table I think.

Regards,

Don

Yes Don,

What I mean is the for the WebEdition.

Here is a question, I notice that by default the grid shows up when we load the program. Could the grid be shown after an action.

For example, I draw an area and i bring in all the data withing that area i have drawn into the grid. The grid would only show up when i create the area. Also, is it possible to add close button to the grid?

Hi Jose,

Sure, please use the “GetFeaturesWithin” API to get the all of the internalFeatures that within the target area, just like “layer.QueryTools.GetFeaturesWithin”. please refer to
Online Sample:
http://samples.thinkgeo.com/webEdition/HowDoISamples/
Source Code:
http://wiki.thinkgeo.com/wiki/map_suite_web_edition_all_samples#map_suite_web_edition_how_do_i_samples

For close button please view our sample, as shown above ‘D’ and see how it implement that.

Thanks,
Emil

Thanks Emil.

I might not have been specific on my question, and my sincere apologies for that.

The sample above gets all the features within, which the code i have is already doing perfectly. I create a box in the map and get all the features within the box, and it works great :grinning: because I can count the amount of features and they are correct.

My question is, after I get how ever many features how can i get the attribute data from each retrieved feature to show in the table grid you all have?

In the following example, you all have something called get all feature data.

http://samples.thinkgeo.com/WebApiEdition/SampleTemplates/QueryTools/openlayers/

I know that is something somewhat different that what you all have here. But that is somewhat of my workflow.

Create a rectangle, get all the features within the rectangle and show the feature data in a table grid.

Thanks!!
Jose

Hi Jose,

You are welcome, please refer to the following code snippets it shows how to get the attribute data and generate the DataSource for GridView:

GridView1.DataSource = GetDataTableFromFeatureLayer(worldLayer);
GridView1.DataBind();

    private DataTable GetDataTableFromFeatureLayer(FeatureLayer featureLayer)
    {
        DataTable dataTable = new DataTable();
        featureLayer.Open();
        // Add the columns of featurelayer into datatable
        Collection<FeatureSourceColumn> allColumns = featureLayer.QueryTools.GetColumns();
        foreach (FeatureSourceColumn column in allColumns)
        {
            dataTable.Columns.Add(column.ColumnName);
        }

        // Get the feature within the box.
        RectangleShape box = new RectangleShape(5, 78, 30, 26);
        // Set ReturningColumnsType to 'AllColumns', it is important.
        Collection<Feature> resultFeature = featureLayer.QueryTools.GetFeaturesWithin(box, ReturningColumnsType.AllColumns);

        // Add row for each feature.
        foreach (Feature feature in resultFeature)
        {
            AddRow(dataTable, feature);
        }
        return dataTable;
    }

    private void AddRow(DataTable dataTable, Feature feature)
    {
        DataRow dataRow = dataTable.NewRow();

        foreach (DataColumn column in dataTable.Columns)
        {
            // get the value of column
            dataRow[column] = feature.ColumnValues[column.ColumnName];
        }
        dataTable.Rows.Add(dataRow);
    }

Thanks,
Emil

Thanks Emil.

I was able to add your code, and when I got to fully execute I am still not seen the grid in the map.

I am currently facing the following error:

The following is the function i use to make the connection and load the data into the map.

    private void LoadAMapFromMsSQL2008()
    {
        string connectString = "Data Source=dataSource; Initial Catalog=catalog; User ID=id; Password=pass";
        MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "table", "index");
        sql2008Layer.CustomGeometryColumnName = "item";
        sql2008Layer.Open();

        //MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "MajorCities", "ID");
        sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
        sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        sql2008Layer.Open();
        sql2008Layer.EditTools.BeginTransaction();
        sql2008Layer.EditTools.Add(new PointShape());
        sql2008Layer.EditTools.CommitTransaction();
        
        LayerOverlay pointsOverlay = new LayerOverlay("InspectionsLayer");
        pointsOverlay.Layers.Add("LayerOfInspectionPoints",sql2008Layer);
        Map1.CustomOverlays.Add(pointsOverlay);
        //Map1.StaticOverlay.Layers.Add("Sql2008Layer", sql2008Layer);
        Map1.CurrentExtent = sql2008Layer.GetBoundingBox();
        /*string connectString = "User ID=userid;Password=password;Data Source=192.168.0.178/orcl;";
        MsSql2008FeatureLayer sql2008Layer = new MsSql2008FeatureLayer(connectString, "states", "recid");
        sql2008Layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
        sql2008Layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        Map1.StaticOverlay.Layers.Add("Sql2008Layer", sql2008Layer);*/
    }

The following function is what gets called when the user finishes drawing the rectangle:
protected void Map1_TrackShapeFinished(object sender, EventArgs e)
{
// Get the Overlayers.
LayerOverlay staticOverlay = (LayerOverlay)Map1.CustomOverlays[“InspectionsLayer”];
MsSql2008FeatureLayer shapeFileLayer = (MsSql2008FeatureLayer)(staticOverlay.Layers[“LayerOfInspectionPoints”]);
shapeFileLayer.Open();

        Feature targetFeature = Map1.EditOverlay.Features[Map1.EditOverlay.Features.Count - 1];

        shapeFileLayer.Close();


        FeaturesGridView.DataSource = GetDataTableFromFeatures(shapeFileLayer, targetFeature);
        FeaturesGridView.DataBind();
    }

The other two functions GetDataTableFromFeatures and AddRow are the same as above.

Where i am seeing the error is in either of the lines that I have made bold.

    private DataTable GetDataTableFromFeatures(FeatureLayer featureLayer, Feature targetFeature)
    {
        DataTable dataTable = new DataTable();
        featureLayer.Open();
        // Add the columns of featurelayer into datatable
        **

Collection allColumns = featureLayer.QueryTools.GetColumns();

**
foreach (FeatureSourceColumn column in allColumns)
{
dataTable.Columns.Add(column.ColumnName);
}

        // Get the feature within the box.
        //RectangleShape box = new RectangleShape(5, 78, 30, 26);
        // Set ReturningColumnsType to 'AllColumns', it is important.
        **

Collection resultFeature = featureLayer.QueryTools.GetFeaturesWithin(targetFeature, ReturningColumnsType.AllColumns);

**

        // Add row for each feature.
        foreach (Feature feature in resultFeature)
        {
            AddRow(dataTable, feature);
        }
        return dataTable;
    }

Hi Jose,

From your screen shot, it looks this exception is caused by you try to repeatedly open a DataReader.

And I guess that’s because you call
layer.Open(); // Your MsSql2008FeatureLayer
in different place.

You can try to close all this layer in each function after you open it, or just only open it once and don’t open and close that again.

I think you can have a try to modify the code and see whether that works.

Regards,

Don

Thanks Don,

I am still having on/off problem with the connection. I think I have play with it a bit more later on to fix that.

Here is another question, how can i build the another description dragable panel like the following?

I tried, to look into it but could not figure it out.

Thanks!!
Jose

Hi Jose,

We implement this panel in client side, you can find this panel in our HowDoISamples, the coder is under “Helper” folder.

Wish that’s helpful.

Regards,

Don