0

My 1 Service have only 1 layer with year wise archive data. Like it have same geometries at different year along with some addon in another year.

I want to use this Dynamic layer for representing the geoms on map yearwise with different symbols [Polyline] when user choose year. I m using MVVM Light, Silverlight. I do what ever but not able to change the rendering of Layer.

I crate ArcGISDynamicMapServiceLayer when User click on check box and create the layer. Then add to LayersCollection. once it initialize then I add Rendere. But still no hope. Can any one help me?

 public void ProjectLayer(ref HpmsMapLayerModel lyr, ref HpmsBaseEsriMapViewModel baseVm,bool isDynamic)
    {
        currentProjection = null;
        currentProjection = lyr;
        BaseVm = baseVm;
        ArcGISDynamicMapServiceLayer mapLayer = new ArcGISDynamicMapServiceLayer();

        mapLayer.Url = lyr.Url;
        mapLayer.ID = lyr.Id;
        mapLayer.DisableClientCaching = true;
        LayerInfo linf = new LayerInfo();
        linf.ID = 0;
        linf.SubLayerIds = new int[]{0};
        linf.DefaultVisibility = false;

      DynamicLayerInfoCollection  dyLyInfColx= mapLayer.CreateDynamicLayerInfosFromLayerInfos();
         dyLyInfColx = new DynamicLayerInfoCollection();

          BaseMapVM.Layers.Add(mapLayer);
        mapLayer.Initialized+=mapLayer_Initialized;
        GetFeatures("HPMSYEAR='" + 2013 + "'", lyr, baseVm);

    }

    private void mapLayer_Initialized(object sender, EventArgs e)
    {
        var rlyr = sender as ArcGISDynamicMapServiceLayer;
        var lyr = BaseMapVM.Layers.Where(L => L.ID == rlyr.ID).FirstOrDefault() as ArcGISDynamicMapServiceLayer;
        lyr.Layers[0].DefaultVisibility = false;
        DynamicLayerInfo layer1 = new DynamicLayerInfo();
        layer1.ID = 0;
        LayerMapSource lms =  new LayerMapSource();
        lms.MapLayerID = 4;
        layer1.Source = lms;
        DynamicLayerInfoCollection dyLyInfColx = lyr.CreateDynamicLayerInfosFromLayerInfos();
        dyLyInfColx.Add(layer1);

        lyr.DynamicLayerInfos = dyLyInfColx;

        LayerDefinition ldef = new LayerDefinition();
        ldef.LayerID = 0;
        string whereClse = "HPMSYEAR='" +2013+"'";
        ldef.Definition = whereClse;
        ObservableCollection<LayerDefinition> layerDrfins = new ObservableCollection<LayerDefinition>();
        layerDrfins.Add(ldef);
        lyr.LayerDefinitions = layerDrfins;

        LayerDrawingOptions ldrOpns = new LayerDrawingOptions();
        ldrOpns.LayerID = 0;
        UniqueValueRenderer myUniqueValueRenderer = new UniqueValueRenderer();
        myUniqueValueRenderer.Field = "HPMSYEAR";
        UniqueValueInfo myUniqueValueInfo1 = new UniqueValueInfo();
        myUniqueValueInfo1.Value = 2013;
        //SimpleFillSymbol mySimpleFillSymbol1 = 
        //    new SimpleFillSymbol();
        SimpleLineSymbol smp = new SimpleLineSymbol();
        smp.Color = BrushConstants.Green; // BrushConstants.DefaultBrushes[colorIndex];
        smp.Width = 5;
        myUniqueValueInfo1.Symbol = smp;
        myUniqueValueRenderer.Infos.Add(myUniqueValueInfo1);
        ldrOpns.Renderer = myUniqueValueRenderer;

        LayerDrawingOptionsCollection ldoc = new LayerDrawingOptionsCollection();
        ldoc.Add(ldrOpns);
        lyr.LayerDrawingOptions = ldoc;
        ArcGISDynamicMapServiceLayer rLyr = null;
        rLyr = BaseMapVM.Layers.Where(L => L.ID == lyr.ID).FirstOrDefault() as ArcGISDynamicMapServiceLayer;
        if (rLyr != null)
        {
           // BaseMapVM.Layers.Remove(rLyr);
           // BaseMapVM.Layers.Add(lyr);
            lyr.Refresh();
        }

        var b = e;
    }

When User Click on Check Box HpmsMapLayerModel class contains the URL, Name, Id etc information and I HpmsBaseEsriMapViewModel contains the Map Object etc.

What I m doing wrong. I m not able to figure out. All the time layer get loaded with full data. Along with predefined rendere which is of Pink Color.

1 Answer 1

1

Here is What I did :

  1. So late I figure out My Services don't have capability of Allow per request modification of layer order and symbology. I was not getting option links at service for Dynamic Legend & Dynamic All Layers change options in REST service exposed. Service change request to Admin.

  2. In my Code

    public void ProjectLayer(ref HpMapLayerModel lyr, ref HpBaseEsriMapViewModel baseVm,bool isDynamic)
    {
        currentProjection = null;
        currentProjection = lyr;
        BaseVm = baseVm;
        ArcGISDynamicMapServiceLayer mapLayer = new ArcGISDynamicMapServiceLayer();            
        mapLayer.Url = lyr.Url;
        mapLayer.ID = lyr.Id;
        mapLayer.DisableClientCaching = true;
        LayerInfo linf = new LayerInfo();
        linf.ID = 0;
        linf.SubLayerIds = new int[]{0};
        linf.DefaultVisibility = false;
        BaseMapVM.Layers.Add(mapLayer);
        mapLayer.Initialized+=mapLayer_Initialized;

    }

    private void mapLayer_Initialized(object sender, EventArgs e)
    {
        OnChangeGeomColorAsPerLayer(null);
    }
    GenerateRendererTask generateRendererTask;
    private void OnChangeGeomColorAsPerLayer(object obj)
    {
        generateRendererTask = new GenerateRendererTask();
        generateRendererTask.Url = currentProjection.Url+"/0";
        generateRendererTask.ExecuteCompleted += generateRendererTask_ExecuteCompleted;
        generateRendererTask.Failed += generateRendererTask_Failed;

        GenerateRendererParameters rendererParams = ConditionalLoadForRenderer();
        generateRendererTask.ExecuteAsync(rendererParams, rendererParams.Where);
    }

    public GenerateRendererParameters ConditionalLoadForRenderer()
    {
        GenerateRendererParameters rendererParams=null;
        if (currentProjection != null)
        {
            if (currentProjection.IsItemLayer)
            {
                if (!currentProjection.IsArchiveLayer)
                {
                    UniqueValueDefinition uniqueValueDefinition = new UniqueValueDefinition()
                    {
                        Fields = new List<string>() { "ITEMID" }
                    };

                    uniqueValueDefinition.ColorRamps.Add(new ColorRamp()
                    {
                        From = (currentProjection.DefaultBrush as SolidColorBrush).Color,
                        To = (currentProjection.DefaultBrush as SolidColorBrush).Color,
                        Algorithm = Algorithm.LabLChAlgorithm
                    });
                     rendererParams = new GenerateRendererParameters()
                    {
                        ClassificationDefinition = uniqueValueDefinition,
                        Where = "ITEMID IN (" + currentProjection.Itemm.Itemno + ")"
                    };
                }
                else
                {
                    UniqueValueDefinition uniqueValueDefinition = new UniqueValueDefinition()
                    {
                        Fields = new List<string>() { "ITEMID", "YEAR" }
                    };

                    uniqueValueDefinition.ColorRamps.Add(new ColorRamp()
                    {
                        From = (currentProjection.DefaultBrush as SolidColorBrush).Color,
                        To = (currentProjection.DefaultBrush as SolidColorBrush).Color,
                        Algorithm = Algorithm.LabLChAlgorithm
                    });

                     rendererParams = new GenerateRendererParameters()
                    {
                        ClassificationDefinition = uniqueValueDefinition,
                        Where = "ITEMID IN (" + currentProjection.Itemm.Itemno + ") AND YEAR IN (" + currentProjection.LayerYear + ")"
                    };
                }
            }
            else
            {
             if(BaseVm.Module.Modulename.ToLowerInvariant().Contains("ROUTES") ||
                 BaseVm.Module.Modulename.ToLowerInvariant().Contains("ROUTE"))
             {
                 ConditionalLoadForRoutes();
             }   
            }                
        }
        return rendererParams; 
    }

I have to build 100's of layer as per ITEMNO while table contains variable ITems so Service contains all geometries in it.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.