This project has moved and is read-only. For the latest updates, please go here.

Point location via its ID...

Topics: Data Access, General Topics, SharpMap Project, SharpMap v0.9 / v1.x, SharpMap v2.0, Web Controls
Dec 9, 2010 at 1:53 AM

Hi, I have a map layer (points shapefile), every feature of the shapefile have its ID, NAME, DESCRIPTION fields... I need to type in a textbox the name of the feature in order to search the point in the map and zoom/center to the point...

In a web app, how can I do that?

If somebody have some sample code, it will be great..



Dec 9, 2010 at 12:55 PM

Hi, I have this sample code working for me, put the code in MapHelper.cs

Hope this help you.

 public static void Search(SharpMap.Map map, String value, String field, string layer_name)
        Boolean found;
        found = false;
        uint idx;
        idx = 0;
        SharpMap.Layers.VectorLayer layer;
        layer = (SharpMap.Layers.VectorLayer)map.Layers[layer_name];
        idx = ZoomTo(layer, value, field, ref found);
        if (found == false)
    private static uint ZoomTo(SharpMap.Layers.VectorLayer layer, string value, string field, ref Boolean found)
        Collection<uint> indexes = layer.DataSource.GetObjectIDsInView(layer.DataSource.GetExtents());

        uint return_value;
        return_value = 0;
        found = false;
        foreach (uint idx in indexes)
            SharpMap.Data.FeatureDataRow feature = layer.DataSource.GetFeature(idx);
            if (feature[field].ToString().Equals(value))
                return_value = idx;
                found = true;
        return return_value;