Example #1
0
        public static LayerMetadata ReadLayerMetadata( JsonObject json )
        {
            json.RequireArgument<JsonObject>( "json" ).NotNull<JsonObject>();

            LayerMetadata lyr = new LayerMetadata();

            lyr.ID = (int)GetRequiredEntryValue( json, LYR_ID );
            lyr.Name = (string)GetRequiredEntryValue( json, LYR_NAME );
            lyr.Type = (string)GetRequiredEntryValue( json, LYR_TYPE );
            lyr.GeometryType = ( string ) GetRequiredEntryValue( json, LYR_GEOMETRY_TYPE );
            lyr.Description = ( string ) GetRequiredEntryValue( json, LYR_DESCRIPTION );
            lyr.DefinitionExpression = ( string ) GetRequiredEntryValue( json, LYR_DEFINITION_EXPRESSION );
            lyr.CopyrightText = ( string ) GetRequiredEntryValue( json, LYR_COPYRIGHT_TEXT );
            lyr.MinimumScale = ( double ) GetRequiredEntryValue( json, LYR_MINIMUM_SCALE );
            lyr.MaximumScale = ( double ) GetRequiredEntryValue( json, LYR_MAXIMUM_SCALE );

            string extent_entry = GetMatchingKey( json, LYR_EXTENT );
            if( string.IsNullOrEmpty( extent_entry ) )
                throw new FormatException( "An extent member is required in the layer metadata object." );
            if( !( json[ LYR_EXTENT ] is JsonObject ) )
                throw new FormatException( "The extent member should be of type JsonObject." );

            lyr.Extent = ReadEnvelope( json[ LYR_EXTENT ] as JsonObject);
            lyr.DisplayField = ( string ) GetRequiredEntryValue( json, LYR_DISPLAY_FIELD );

            string fields_entry = GetMatchingKey( json, LYR_FIELDS );
            if( string.IsNullOrEmpty( fields_entry ) )
                throw new FormatException( "A fields member is required in the layer metadata object." );
            if( json[ LYR_FIELDS ] != null )
            {
                if( !( json[ LYR_FIELDS ] is JsonArray ) )
                    throw new FormatException( "The fields member should be of type JsonArray." );

                lyr.Fields = ReadFieldMetadataArray( json[ LYR_FIELDS ] as JsonArray );
            }

            string parentLayer_entry = GetMatchingKey( json, LYR_PARENT_LAYER );
            if( string.IsNullOrEmpty( parentLayer_entry ) )
                throw new FormatException( "An parentLayer member is required in the layer metadata object." );
            if(json[LYR_PARENT_LAYER] != null)
            {
                if( !( json[ LYR_PARENT_LAYER ] is JsonObject ) )
                    throw new FormatException( "The parentLayer member should be of type JsonObject." );

                lyr.ParentLayer = ReadLayerReference( json[ LYR_PARENT_LAYER ] as JsonObject);
            }

            string subLayers_entry = GetMatchingKey( json, LYR_SUBLAYERS );
            if( string.IsNullOrEmpty( subLayers_entry ) )
                throw new FormatException( "A subLayers member is required in the layer metadata object." );
            if( json[ LYR_SUBLAYERS ] != null )
            {
                if( !( json[ LYR_SUBLAYERS ] is JsonArray ) )
                    throw new FormatException( "The subLayers member should be of type JsonArray." );

                lyr.SubLayers = ReadLayerReferenceArray( json[ LYR_SUBLAYERS ] as JsonArray );
            }

            return lyr;
        }
        private void HandleLayerMetaData( string metadata )
        {
            JsonObject lyrMetadataJSON = JsonObject.Parse( metadata ) as JsonObject;
            LayerMetadata = ArcJSONReader.ReadLayerMetadata( lyrMetadataJSON );
            LayerType = LayerTypeProvider.CreateLayerRecordType( LayerMetadata );

            QueryTask queryTask = new QueryTask( "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer/5" );
            queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
            queryTask.Failed += QueryTask_Failed;

            Query query = new Query();
            query.OutFields.Add( "*" );
            query.Where = "1=1";
            queryTask.ExecuteAsync( query );
        }