Hi, i am trying to create a json object from a collection but keep running into errors when tryting to format it. is there a way to pull the ids and values from a collection? i am trying to get rid of the pop up and change it to a table so that the user can see it outside the map area. any help would be greatly appreciated.
public string ClickEvent(Map map, GeoCollection<object> args,ParcelInfo info){// Argument reference:// 0: World longitude coordinate (x)// 1: World latitude coordinate (y)// 2: Current scale of the map
string popupJson = string.Empty;int clickRadius;double currentScale;PointShape position = new PointShape(Convert.ToDouble(args[0]), Convert.ToDouble(args[1]));
// Wilson Parcel OverlayLayerOverlay overlay = (LayerOverlay)map.CustomOverlays[“Wilson Parcels”];ShapeFileFeatureLayer inm = overlay.Layers[0] as ShapeFileFeatureLayer;inm.Open();InMemoryFeatureLayer highlightLayer = overlay.Layers[“HighlightLayerP”] as InMemoryFeatureLayer;highlightLayer.Open();
// Wilson Subdivision OverlayLayerOverlay overlayS = (LayerOverlay)map.CustomOverlays[“Wilson Subdivisions”];ShapeFileFeatureLayer inm2 = overlayS.Layers[0] as ShapeFileFeatureLayer;inm2.Open();InMemoryFeatureLayer highlightLayerSub = overlayS.Layers[“HighlightLayerSub”] as InMemoryFeatureLayer;highlightLayerSub.Open();//Wilson TownshipsLayerOverlay overlayT = (LayerOverlay)map.CustomOverlays[“Wilson TownShips”];ShapeFileFeatureLayer inm3 = overlayT.Layers[0] as ShapeFileFeatureLayer;inm3.Open();InMemoryFeatureLayer highlightLayerTown = overlayT.Layers[“HighLightLayerTown”] as InMemoryFeatureLayer;highlightLayerTown.Open();//Wilson SectionsLayerOverlay overlaySec = (LayerOverlay)map.CustomOverlays[“Wilson Sections”];ShapeFileFeatureLayer inm4 = overlaySec.Layers[0] as ShapeFileFeatureLayer;inm4.Open();InMemoryFeatureLayer highlightLayerSec = overlaySec.Layers[“HighLightLayerSec”] as InMemoryFeatureLayer;highlightLayerSec.Open();if (overlay.IsVisible != false){// Get a list of all the columns in the parcel layer (we’ll need this for the GetFeaturesNearestTo method)Collection<FeatureSourceColumn> parcelLayerColumns = inm.FeatureSource.GetColumns();List<string> parcelLayerColumnNames = new List<string>();foreach (FeatureSourceColumn col in parcelLayerColumns){parcelLayerColumnNames.Add(col.ColumnName);}
// Adjust the click radius based on the scale of the map (via event args) for better UX – capped at 6400 meters (approx. 4 miles)if (Double.TryParse(args[2].ToString(), out currentScale) && Int32.TryParse(Math.Ceiling(currentScale / 100).ToString(), out clickRadius)){if (clickRadius > 6400 || clickRadius <= 0){clickRadius = 6400;}}else{clickRadius = 6400;}
// Create a new CloudPopup and set some common propertiesCloudPopup infoPopup = new CloudPopup(“ParcelInfoPopup”);infoPopup.HasCloseButton = true;
infoPopup.AutoPan = true;infoPopup.AutoSize = true;
// Open the highlightLayer for editing and clear any existing highlight pointshighlightLayer.FeatureSource.Open();highlightLayer.FeatureSource.BeginTransaction();highlightLayer.InternalFeatures.Clear();
// Use GetFeaturesNearestTo instead of GetFeaturesWithinDistanceOf so that the first feature returned is always closest to the click pointCollection<Feature> closestFeature = inm.FeatureSource.GetFeaturesNearestTo(position, map.MapUnit, 1, parcelLayerColumnNames as IEnumerable<string>, clickRadius, DistanceUnit.Meter);inm.Close();if (closestFeature.Any()){// Add a copy of this feature to the highlightLayerhighlightLayer.FeatureSource.AddFeature(closestFeature[0]);info.ParcelID = closestFeature[0].ColumnValues[“PARCELID”].Trim();//Create a popup with info about this featureStringBuilder message = new StringBuilder();message.AppendFormat("<li>Parcel Id: {0}<!–</code–>li>", closestFeature[0].ColumnValues[“PARCELID”].Trim());message.AppendFormat("<li>Owner: {0}<!–</code–>li>", closestFeature[0].ColumnValues[“OWNER”].Trim());//message.AppendFormat("<li>Owner Addr: {0}<!–</code–>li>", closestFeature[0].ColumnValues[“OWNADDR”].Trim());message.AppendFormat("<li>Quick Ref ID: {0}<!–</code–>li>", closestFeature[0].ColumnValues[“QuickRefID”].Trim());message.AppendFormat("<li>Acres: {0}<!–</code–>li>", closestFeature[0].ColumnValues[“CalcAcres”].Trim());message.AppendFormat("<li>Tax Unit : {0}<!–</code–>li>", closestFeature[0].ColumnValues[“TAXUNIT”].Trim());message.AppendFormat("<inputname=‘TaxData’type=‘button’id=‘btnCIC’value=‘Tax Data’onclick=‘test1()’/>");message.AppendFormat("<inputname=‘OrionData’type=‘button’id=‘btnOrion’value=‘Orion Data’onclick=‘test1()’/>");message.AppendFormat("<inputname=‘Photo’type=‘button’id=‘btnPhoto’value=‘Photo’onclick=‘test1()’/>");message.AppendFormat("<inputname=‘SVQ’type=‘button’id=‘btnSvS’value=‘SVQ’onclick=‘test1()’/>");string messageInPopup = String.Format("<divclass=\"normalBlueTx\">{0}<!–</code–>div>", message.ToString());
infoPopup.ContentHtml = messageInPopup;infoPopup.Position = closestFeature[0].GetShape().GetCenterPoint();}else{// Create a default instructional popupinfoPopup.ContentHtml = “<divclass=\"normalBlueTx\">Please click on a Parcel to show its information.<!–</code–>div>”;infoPopup.Position = position;}
// Commit changes to the highlightLayerhighlightLayer.FeatureSource.CommitTransaction();highlightLayer.FeatureSource.Close();
// Clear the map’s Popups collection and add our new onemap.Popups.Clear();map.Popups.Add(infoPopup);
// Convert the popup to JSON and return it to the clientpopupJson = infoPopup.ToJson();var x = popupJson;
return popupJson;}
if (overlayS.IsVisible != false){
// Get a list of all the columns in the parcel layer (we’ll need this for the GetFeaturesNearestTo method)Collection<FeatureSourceColumn> SubdivisionLayerColumns = inm2.FeatureSource.GetColumns();List<string> SubdivisionLayerColumnNames = new List<string>();foreach (FeatureSourceColumn col in SubdivisionLayerColumns){SubdivisionLayerColumnNames.Add(col.ColumnName);}
// Adjust the click radius based on the scale of the map (via event args) for better UX – capped at 6400 meters (approx. 4 miles)if (Double.TryParse(args[2].ToString(), out currentScale) && Int32.TryParse(Math.Ceiling(currentScale / 100).ToString(), out clickRadius)){if (clickRadius > 6400 || clickRadius <= 0){clickRadius = 6400;}}else{clickRadius = 6400;}
// Create a new CloudPopup and set some common propertiesCloudPopup infoPopup = new CloudPopup(“SubdivisionInfoPopup”);infoPopup.HasCloseButton = true;infoPopup.AutoPan = true;infoPopup.AutoSize = true;
// Open the highlightLayer for editing and clear any existing highlight pointshighlightLayerSub.FeatureSource.Open();highlightLayerSub.FeatureSource.BeginTransaction();highlightLayerSub.InternalFeatures.Clear();
// Use GetFeaturesNearestTo instead of GetFeaturesWithinDistanceOf so that the first feature returned is always closest to the click pointCollection<Feature> closestFeature = inm2.FeatureSource.GetFeaturesNearestTo(position, map.MapUnit, 1, SubdivisionLayerColumnNames as IEnumerable<string>, clickRadius, DistanceUnit.Meter);inm2.Close();if (closestFeature.Any()){// Add a copy of this feature to the highlightLayerhighlightLayerSub.FeatureSource.AddFeature(closestFeature[0]);
// Create a popup with info about this featureStringBuilder message = new StringBuilder();message.AppendFormat("<li>Name:{0}<!–</code–>li>", closestFeature[0].ColumnValues[“NAME”].Trim());message.AppendFormat("<li>Shape Length = {0}<!–</code–>li>", closestFeature[0].ColumnValues[“Shape_Leng”].Trim());string messageInPopup = String.Format("<divclass=\"normalBlueTx\">{0}<!–</code–>div>", message.ToString());
infoPopup.ContentHtml = messageInPopup;infoPopup.Position = closestFeature[0].GetShape().GetCenterPoint();}else{// Create a default instructional popupinfoPopup.ContentHtml = “<divclass=\"normalBlueTx\">Please click on a Subdivision to show its information.<!–</code–>div>”;infoPopup.Position = position;}
// Commit changes to the highlightLayerhighlightLayerSub.FeatureSource.CommitTransaction();highlightLayerSub.FeatureSource.Close();
// Clear the map’s Popups collection and add our new onemap.Popups.Clear();map.Popups.Add(infoPopup);
// Convert the popup to JSON and return it to the clientpopupJson = infoPopup.ToJson();//return popupJson;
}if (overlayT.IsVisible != false){
// Get a list of all the columns in the parcel layer (we’ll need this for the GetFeaturesNearestTo method)Collection<FeatureSourceColumn> TownShipLayerColumns = inm3.FeatureSource.GetColumns();List<string> TownShipLayerColumnNames = new List<string>();foreach (FeatureSourceColumn col in TownShipLayerColumns){TownShipLayerColumnNames.Add(col.ColumnName);}
// Adjust the click radius based on the scale of the map (via event args) for better UX – capped at 6400 meters (approx. 4 miles)if (Double.TryParse(args[2].ToString(), out currentScale) && Int32.TryParse(Math.Ceiling(currentScale / 100).ToString(), out clickRadius)){if (clickRadius > 6400 || clickRadius <= 0){clickRadius = 6400;}}else{clickRadius = 6400;}
// Create a new CloudPopup and set some common propertiesCloudPopup infoPopup = new CloudPopup(“TownShipInfoPopup”);infoPopup.HasCloseButton = true;infoPopup.HasCloseButton = true;infoPopup.AutoPan = true;infoPopup.AutoSize = true;
// Open the highlightLayer for editing and clear any existing highlight pointshighlightLayerTown.FeatureSource.Open();highlightLayerTown.FeatureSource.BeginTransaction();highlightLayerTown.InternalFeatures.Clear();
// Use GetFeaturesNearestTo instead of GetFeaturesWithinDistanceOf so that the first feature returned is always closest to the click pointCollection<Feature> closestFeature = inm3.FeatureSource.GetFeaturesNearestTo(position, map.MapUnit, 1, TownShipLayerColumnNames as IEnumerable<string>, clickRadius, DistanceUnit.Meter);inm3.Close();if (closestFeature.Any()){// Add a copy of this feature to the highlightLayerhighlightLayerTown.FeatureSource.AddFeature(closestFeature[0]);
// Create a popup with info about this featureStringBuilder message = new StringBuilder();message.AppendFormat("<li>Township: {0}<!–</code–>li>", closestFeature[0].ColumnValues[“TOWNSHIP”].Trim());message.AppendFormat("<li>Shape Length = {0}<!–</code–>li>", closestFeature[0].ColumnValues[“Shape_Leng”].Trim());string messageInPopup = String.Format("<divclass=\"normalBlueTx\">{0}<!–</code–>div>", message.ToString());
infoPopup.ContentHtml = messageInPopup;infoPopup.Position = closestFeature[0].GetShape().GetCenterPoint();}else{// Create a default instructional popupinfoPopup.ContentHtml = “<divclass=\"normalBlueTx\">Please click on a TownShip to show its information.<!–</code–>div>”;infoPopup.Position = position;}
// Commit changes to the highlightLayerhighlightLayerTown.FeatureSource.CommitTransaction();highlightLayerTown.FeatureSource.Close();
// Clear the map’s Popups collection and add our new onemap.Popups.Clear();map.Popups.Add(infoPopup);
// Convert the popup to JSON and return it to the clientpopupJson = infoPopup.ToJson();return popupJson;
}if (overlaySec.IsVisible != false){
// Get a list of all the columns in the parcel layer (we’ll need this for the GetFeaturesNearestTo method)Collection<FeatureSourceColumn> SectionsLayerColumns = inm4.FeatureSource.GetColumns();List<string> SectionsLayerColumnNames = new List<string>();foreach (FeatureSourceColumn col in SectionsLayerColumns){SectionsLayerColumnNames.Add(col.ColumnName);}
// Adjust the click radius based on the scale of the map (via event args) for better UX – capped at 6400 meters (approx. 4 miles)if (Double.TryParse(args[2].ToString(), out currentScale) && Int32.TryParse(Math.Ceiling(currentScale / 100).ToString(), out clickRadius)){if (clickRadius > 6400 || clickRadius <= 0){clickRadius = 6400;}}else{clickRadius = 6400;}
// Create a new CloudPopup and set some common propertiesCloudPopup infoPopup = new CloudPopup(“TownShipInfoPopup”);infoPopup.HasCloseButton = true;infoPopup.AutoPan = true;infoPopup.AutoSize = true;
// Open the highlightLayer for editing and clear any existing highlight pointshighlightLayerSec.FeatureSource.Open();highlightLayerSec.FeatureSource.BeginTransaction();highlightLayerSec.InternalFeatures.Clear();
// Use GetFeaturesNearestTo instead of GetFeaturesWithinDistanceOf so that the first feature returned is always closest to the click pointCollection<Feature> closestFeature = inm4.FeatureSource.GetFeaturesNearestTo(position, map.MapUnit, 1, SectionsLayerColumnNames as IEnumerable<string>, clickRadius, DistanceUnit.Meter);inm4.Close();if (closestFeature.Any()){// Add a copy of this feature to the highlightLayerhighlightLayerSec.FeatureSource.AddFeature(closestFeature[0]);
// Create a popup with info about this featureStringBuilder message = new StringBuilder();message.AppendFormat("<li>Township: {0}<!–</code–>li>", closestFeature[0].ColumnValues[“TOWNSHIP”].Trim());//message.AppendFormat("<li>Section: {0}<!–</code–>li>", closestFeature[0].ColumnValues[“SECTION_”].Trim());//message.AppendFormat("<li>Name: {0}<!–</code–>li>", closestFeature[0].ColumnValues[“POLTOWNSHIP”].Trim());message.AppendFormat("<li>Shape Length = {0}<!–</code–>li>", closestFeature[0].ColumnValues[“Shape_Leng”].Trim());string messageInPopup = String.Format("<divclass=\"normalBlueTx\">{0}<!–</code–>div>", message.ToString());
infoPopup.ContentHtml = messageInPopup;infoPopup.Position = closestFeature[0].GetShape().GetCenterPoint();}else{// Create a default instructional popupinfoPopup.ContentHtml = “<divclass=\"normalBlueTx\">Please click on a Section to show its information.<!–</code–>div>”;infoPopup.Position = position;}
// Commit changes to the highlightLayerhighlightLayerSec.FeatureSource.CommitTransaction();highlightLayerSec.FeatureSource.Close();
// Clear the map’s Popups collection and add our new onemap.Popups.Clear();map.Popups.Add(infoPopup);
// Convert the popup to JSON and return it to the clientpopupJson = infoPopup.ToJson();return popupJson;
}return string.Empty;}
