In My map iam loading parcel layer on the map.when i click on layer it has to show the layer feature details.if my layer is not loading on the map means if the layer is having more data means for loading it is taking more time at that time if i click on layer it thrown an error like "Index was outside the bounds of the array.".when i zoom in at this time also it is taking more time to load on the map.at this time also iam getting error.so can we show message like map is loading like that so that user can know layer is loading on the map.
Index was outside the bounds of the array
Even if i use this code at this time also it is camming Map1_Click() in server side.So can we try this same type of thing from server side in Map1_Click event.so that in this Map1_click event if we are not able to find any features then we can show one message like map is loading like that
foreach (ShapeFileFeatureLayer item in Map1.StaticOverlay.Layers)
{
Collection<feature> features= item.QueryTools.GetFeaturesContaining(e.Position, ReturningColumnsType.AllColumns);</feature>
}
Here it is returning the Features count as 1 but still iam getting error like index was outside of the range.so here can we restrict ro show a message.then we can show message from here one
Raj,
Could you please provide your sample to us to test? Maybe we can find the problem through the sample.
Thanks,
Edgar
protected void Map1_Click(object sender, MapClickedEventArgs e)
{
if (Map1.StaticOverlay.Layers.Count > 0)
{
foreach (ShapeFileFeatureLayer item in Map1.StaticOverlay.Layers)
{
item.Open();
if (shapeFileType == ShapeFileType.Point || shapeFileType == ShapeFileType.Multipoint)//points
{
double resolution = Math.Max(Map1.CurrentExtent.Width / Map1.WidthInPixels, Map1.CurrentExtent.Height / Map1.HeightInPixels);
// this indicates decimal degree gap in 4 pixels on screen.
// if this still returns multiple features, please try to set clickScreenTolerance smaller.
double clickScreenTolerance = 4;
double clickWorldTolerance = clickScreenTolerance * resolution;
RectangleShape clickArea = new RectangleShape(e.Position.X - clickWorldTolerance, e.Position.Y + clickWorldTolerance, e.Position.X + clickWorldTolerance, e.Position.Y - clickWorldTolerance);
features = item.QueryTools.GetFeaturesIntersecting(clickArea, ReturningColumnsType.AllColumns);
item.Close();
if (features.Count > 0)
{
int id = Convert.ToInt32(features[0].Id.ToString());
Session["layerfieldid"] = id.ToString();
found = true;
break;
}
}
if (shapeFileType == ShapeFileType.Polygon)//polygon
{
features = item.QueryTools.GetFeaturesContaining(e.Position, ReturningColumnsType.AllColumns);//here iam getting error
if (features.Count > 0)
{
//do something
int id = Convert.ToInt32(features[0].Id.ToString());
Session["layerfieldid"] = id.ToString();
Collection<FeatureSourceColumn> allColumns = item.QueryTools.GetColumns();
for (int i = 0; i < allColumns.Count; i++)
{
//DataColumn dc = new DataColumn();
//dc.ColumnName = allColumns.ColumnName.ToString();
//dt.Columns.Add(dc);
if (allColumns.ColumnName.ToString().Trim() == "PARCEL_ID")
{
Session["parcelID"] = features[0].ColumnValues["PARCEL_ID"].Trim();
}
}
found = true;
break;
}
}
if (shapeFileType == ShapeFileType.Polyline || shapeFileType == ShapeFileType.PolylineM)//lines
{
features = item.QueryTools.GetFeaturesWithinDistanceOf(e.Position, GeographyUnit.Meter, DistanceUnit.Meter, 10, ReturningColumnsType.AllColumns);
if (features.Count > 0)
{
//do something
int id = Convert.ToInt32(features[0].Id.ToString());
Session["layerfieldid"] = id.ToString();
found = true;
break;
}
}
}
}
}
}
first i load my shape files on map.after that iam clicking on map layer points/area.if the map is not loaded completely then iam getting error.if the shapefile is polygon means iam getting error in this point.means if user click on map when the map is partially loades means iam getting error can we restrict like showing a mesage like map is loaded partially so that we wont get any server error.
features = item.QueryTools.GetFeaturesContaining(e.Position, ReturningColumnsType.AllColumns);
Raj,
Sorry we still can’t recreate your scenario. We tried to click the map immediately before a large shape file loading finished. But we never encounter the error “Index was outside the bounds of the array”. Besides, we also used the code “features = item.QueryTools.GetFeaturesContaining(e.Position, ReturningColumnsType.AllColumns” and seemed it worked fine. And here is my partial code for test:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF"));
Map1.CurrentExtent = new RectangleShape(-125, 72, 50, -46);
Map1.MapUnit = GeographyUnit.DecimalDegree;
ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath("~/innerwater.shp"));
worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
Map1.StaticOverlay.Layers.Add(worldLayer);
}
}
protected void Map1_Click(object sender, MapClickedEventArgs e)
{
if (Map1.StaticOverlay.Layers.Count > 0)
{
foreach (ShapeFileFeatureLayer item in Map1.StaticOverlay.Layers)
{
item.Open();
Collection<Feature> features = item.QueryTools.GetFeaturesContaining(e.Position, ReturningColumnsType.AllColumns);//we didn’t encountered the error you commented out [//here iam getting error]
if (features.Count > 0)
{
//do something
break;
}
}
}
}
we really hope you can provide us a project which can recreate your error.
Thanks,
Edgar