Hi,
I need help to achieve this functionality. I have server-side codes that dynamically add InMemoryFeatureLayers when a button is clicked.
These layers are features from the MsSQL2008FeatureLayer that are being added to a CustomOverlay. The custom overaly shows but my problem is the layers in it don't show on the map. I need to do the map redraw via client-side, meaning in the mapCallback. My codes below:
Server side:
[MapActionFilter]
public string ShowSQLFeatureLayers(Map map, GeoCollection<object> args)
{
string name = args["uiLayerName"].ToString();
string id = args["uiLayerId"].ToString();
try
{
MsSql2008FeatureLayer layer = GetLayer(decimal.Parse(id));
layer.Open();
var features = layer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns).ToList();
LayerOverlay co = (LayerOverlay)map.CustomOverlays.FirstOrDefault(f => f.Id == string.Format("{0}|{1}", name, id));
foreach (var feature in features)
{
InMemoryFeatureLayer inMemoryFeatureLayer = new InMemoryFeatureLayer();
inMemoryFeatureLayer.Open();
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.RoyalBlue);
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.StandardColors.Blue;
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen = new GeoPen(GeoColor.FromArgb(200, GeoColor.StandardColors.Red), 10);
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle.SymbolPen = new GeoPen(GeoColor.FromArgb(255, GeoColor.StandardColors.Red), 20);
inMemoryFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
// Projection
Proj4Projection projection = Utils.Spatial.GetDefaultMapProjection();
projection.Open();
inMemoryFeatureLayer.FeatureSource.Projection = projection;
inMemoryFeatureLayer.InternalFeatures.Add(feature);
co.Layers.Add(inMemoryFeatureLayer);
co.IsVisible = true;
}
}
catch
{
// Swallow the exception
}
return string.Format("{0}|{1}", name, id);
}
Client-side:
<script type="text/javascript">
function loadSQLFeatureLayersForOverlay(layerName, layerId) {
Map1.ajaxCallAction('Map', 'ShowSQLFeatureLayers', { 'uiLayerName': layerName, 'uiLayerId': layerId }, showGeomsForFeature);
}
function showGeomsForFeature(data) {
if (data.get_statusCode() != '404') {
var result = data.get_responseData();
var layer = Map1.getLayer(result);
layer.redraw(true);
}
}
</script>
I appreciate any help.
Thanks,
Benito