예제 #1
0
        public void ApplyCustomDictionary()
        {
            // Create overrides for expected field names that are different in this dataset.
            Dictionary <string, string> styleToFieldMappingOverrides = new Dictionary <string, string>();

            styleToFieldMappingOverrides.Add("style", "Style");
            styleToFieldMappingOverrides.Add("price", "Price");
            styleToFieldMappingOverrides.Add("healthgrade", "Inspection");
            styleToFieldMappingOverrides.Add("rating", "Rating");

            // Create overrides for expected text field names (if any).
            Dictionary <string, string> textFieldOverrides = new Dictionary <string, string>();

            textFieldOverrides.Add("name", "Name");

            // Set the text visibility configuration setting.
            _restaurantStyle.Configurations.ToList().Find(c => c.Name == "text").Value = "ON";

            // Create the dictionary renderer with the style file and the field overrides.
            DictionaryRenderer dictRenderer = new DictionaryRenderer(_restaurantStyle, styleToFieldMappingOverrides, textFieldOverrides);

            // Apply the dictionary renderer to the layer.
            FeatureLayer restaurantLayer = MyMapView.Map.OperationalLayers.First() as FeatureLayer;

            restaurantLayer.Renderer = dictRenderer;
        }
예제 #2
0
        private async void Initialize()
        {
            try
            {
                // Create a new map with a streets basemap.
                Map map = new Map(Basemap.CreateStreetsVector());

                // Create the restaurants layer and add it to the map.
                FeatureLayer restaurantLayer = new FeatureLayer(_restaurantUri);
                map.OperationalLayers.Add(restaurantLayer);

                // Load the feature table for the restaurants layer.
                await restaurantLayer.FeatureTable.LoadAsync();

                // Open the custom style file.
                DictionarySymbolStyle restaurantStyle = await DictionarySymbolStyle.CreateFromFileAsync(_stylxPath);

                // Create the dictionary renderer with the style file and the field overrides.
                DictionaryRenderer dictRenderer = new DictionaryRenderer(restaurantStyle);

                // Set the restaurant layer renderer to the dictionary renderer.
                restaurantLayer.Renderer = dictRenderer;

                // Set the map's initial extent to that of the restaurants.
                map.InitialViewpoint = new Viewpoint(restaurantLayer.FullExtent);

                // Set the map to the map view.
                MyMapView.Map = map;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        public async Task DictionaryTemplateEngine_SimpleStringBinding()
        {
            var engine = new DictionaryRenderer(_templateFixture.Templates1);
            var result = await engine.RenderTemplate(null, "en", "stringTemplate", new { name = "joe" });

            Assert.Equal(typeof(string), result.GetType());
            Assert.Equal("en: joe", (string)result);
        }
예제 #4
0
        public async Task DictionaryTemplateEngine_SimpleStringBinging()
        {
            var engine = new DictionaryRenderer(templates1);
            var result = await engine.RenderTemplate(null, "en", "stringTemplate", new { name = "joe" });

            Assert.IsInstanceOfType(result, typeof(string));
            Assert.AreEqual("en: joe", (string)result);
        }
        private async void Initialize()
        {
            // Create new Map with basemap
            Map myMap = new Map(Basemap.CreateTopographic());

            // Provide Map to the MapView
            _myMapView.Map = myMap;

            // Get the path to the geodatabase
            string geodbFilePath = GetGeodatabasePath();

            // Load the geodatabase from local storage
            Geodatabase baseGeodatabase = await Geodatabase.OpenAsync(geodbFilePath);

            // Get the path to the symbol dictionary
            string symbolFilepath = GetStyleDictionaryPath();

            try
            {
                // Load the symbol dictionary from local storage
                //     Note that the type of the symbol definition must be explicitly provided along with the file name
                DictionarySymbolStyle symbolStyle = await DictionarySymbolStyle.OpenAsync("mil2525d", symbolFilepath);

                // Add geodatabase features to the map, using the defined symbology
                foreach (FeatureTable table in baseGeodatabase.GeodatabaseFeatureTables)
                {
                    // Load the table
                    await table.LoadAsync();

                    // Create the feature layer from the table
                    FeatureLayer myLayer = new FeatureLayer(table);

                    // Load the layer
                    await myLayer.LoadAsync();

                    // Create a Dictionary Renderer using the DictionarySymbolStyle
                    DictionaryRenderer dictRenderer = new DictionaryRenderer(symbolStyle);

                    // Apply the dictionary renderer to the layer
                    myLayer.Renderer = dictRenderer;

                    // Add the layer to the map
                    myMap.OperationalLayers.Add(myLayer);
                }

                // Create geometry for the center of the map
                MapPoint centerGeometry = new MapPoint(-13549402.587055, 4397264.96879385, SpatialReference.Create(3857));

                // Set the map's viewpoint to highlight the desired content
                _myMapView.SetViewpoint(new Viewpoint(centerGeometry, 201555));
            }
            catch (Exception e)
            {
                new AlertDialog.Builder(this).SetMessage(e.ToString()).SetTitle("Error").Show();
            }
        }
예제 #6
0
        private async void Initialize()
        {
            // Create new Map with basemap
            Map myMap = new Map(Basemap.CreateTopographic());

            // Provide Map to the MapView
            MyMapView.Map = myMap;

            // Get the path to the geodatabase
            string geodbFilePath = GetGeodatabasePath();

            // Load the geodatabase from local storage
            Geodatabase baseGeodatabase = await Geodatabase.OpenAsync(geodbFilePath);

            // Get the path to the symbol dictionary
            string symbolFilepath = GetStyleDictionaryPath();

            try
            {
                // Load the symbol dictionary from local storage
                DictionarySymbolStyle symbolStyle = await DictionarySymbolStyle.CreateFromFileAsync(symbolFilepath);

                // Add geodatabase features to the map, using the defined symbology
                foreach (FeatureTable table in baseGeodatabase.GeodatabaseFeatureTables)
                {
                    // Load the table
                    await table.LoadAsync();

                    // Create the feature layer from the table
                    FeatureLayer myLayer = new FeatureLayer(table);

                    // Load the layer
                    await myLayer.LoadAsync();

                    // Create a Dictionary Renderer using the DictionarySymbolStyle
                    DictionaryRenderer dictRenderer = new DictionaryRenderer(symbolStyle);

                    // Apply the dictionary renderer to the layer
                    myLayer.Renderer = dictRenderer;

                    // Add the layer to the map
                    myMap.OperationalLayers.Add(myLayer);
                }

                // Create geometry for the center of the map
                MapPoint centerGeometry = new MapPoint(-13549402.587055, 4397264.96879385, SpatialReference.Create(3857));

                // Set the map's viewpoint to highlight the desired content
                MyMapView.SetViewpoint(new Viewpoint(centerGeometry, 201555));
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert("Error", e.ToString(), "OK");
            }
        }
예제 #7
0
        public async Task DictionaryTemplateEngine_SimpleActivityBinding()
        {
            var engine = new DictionaryRenderer(templates1);
            var result = await engine.RenderTemplate(null, "en", "activityTemplate", new { name = "joe" });

            Assert.IsInstanceOfType(result, typeof(Activity));
            var activity = result as Activity;

            Assert.AreEqual(ActivityTypes.Message, activity.Type);
            Assert.AreEqual("(Activity)en: joe", activity.Text);
        }
        public async Task DictionaryTemplateEngine_SimpleActivityBinding()
        {
            var engine = new DictionaryRenderer(_templateFixture.Templates1);
            var result = await engine.RenderTemplate(null, "en", "activityTemplate", new { name = "joe" });

            Assert.Equal(typeof(Activity), result.GetType());

            var activity = result as Activity;

            Assert.Equal(ActivityTypes.Message, activity.Type);
            Assert.Equal("(Activity)en: joe", activity.Text);
        }
        private async void Initialize()
        {
            // Create new Map with basemap
            Map myMap = new Map(Basemap.CreateTopographic());

            // Provide Map to the MapView
            MyMapView.Map = myMap;

            // Create geometry for the center of the map
            MapPoint centerGeometry = new MapPoint(-13549402.587055, 4397264.96879385, SpatialReference.Create(3857));

            // Set the map's viewpoint to highlight the desired content
            await MyMapView.SetViewpointCenterAsync(centerGeometry);

            await MyMapView.SetViewpointScaleAsync(201555.279);

            // Get the path to the geodatabase
            string geodbFilePath = await GetPreparedFilePath(_geodatabaseName, _geodatabaseId);

            // Load the geodatabase from local storage
            Geodatabase baseGeodatabase = await Geodatabase.OpenAsync(geodbFilePath);

            // Get the path to the symbol dictionary
            string symbolFilepath = await GetPreparedFilePath(_symbolDefName, _symbolDefId);

            // Load the symbol dictionary from local storage
            //     Note that the type of the symbol definition must be explicitly provided along with the file name
            DictionarySymbolStyle symbolStyle = await DictionarySymbolStyle.OpenAsync("mil2525d", symbolFilepath);

            // Add geodatabase features to the map, using the defined symbology
            foreach (FeatureTable table in baseGeodatabase.GeodatabaseFeatureTables)
            {
                // Load the table
                await table.LoadAsync();

                // Create the feature layer from the table
                FeatureLayer myLayer = new FeatureLayer(table);

                // Load the layer
                await myLayer.LoadAsync();

                // Create a Dictionary Renderer using the DictionarySymbolStyle
                DictionaryRenderer dictRenderer = new DictionaryRenderer(symbolStyle);

                // Apply the dictionary renderer to the layer
                myLayer.Renderer = dictRenderer;

                // Add the layer to the map
                myMap.OperationalLayers.Add(myLayer);
            }
        }
예제 #10
0
        public void TemplateManager_Registration()
        {
            var templateManager = new TemplateManager();

            Assert.AreEqual(templateManager.List().Count, 0, "nothing registered yet");

            var templateEngine1 = new DictionaryRenderer(templates1);
            var templateEngine2 = new DictionaryRenderer(templates2);

            templateManager.Register(templateEngine1);
            Assert.AreEqual(templateManager.List().Count, 1, "one registered");

            templateManager.Register(templateEngine2);
            Assert.AreEqual(templateManager.List().Count, 2, "two registered");
        }
예제 #11
0
        public async Task Template_TemplateManager_MultiTemplate()
        {
            var templateManager = new TemplateManager();

            Assert.AreEqual(templateManager.List().Count, 0, "nothing registered yet");
            var templateEngine1 = new DictionaryRenderer(templates1);
            var templateEngine2 = new DictionaryRenderer(templates2);

            templateManager.Register(templateEngine1);
            Assert.AreEqual(templateManager.List().Count, 1, "one registered");

            templateManager.Register(templateEngine1);
            Assert.AreEqual(templateManager.List().Count, 1, "only  one registered");

            templateManager.Register(templateEngine2);
            Assert.AreEqual(templateManager.List().Count, 2, "two registered");
        }
        public void TemplateManager_MultiTemplate()
        {
            var templateManager = new TemplateManager();

            Assert.Empty(templateManager.List());

            var templateEngine1 = new DictionaryRenderer(_templateFixture.Templates1);
            var templateEngine2 = new DictionaryRenderer(_templateFixture.Templates2);

            templateManager.Register(templateEngine1);
            Assert.Single(templateManager.List());

            // Test that only one has to be registered.
            templateManager.Register(templateEngine1);
            Assert.Single(templateManager.List());

            templateManager.Register(templateEngine2);
            Assert.Equal(2, templateManager.List().Count);
        }
        private async void RenderSymbols(Dictionary <string, object> info, bool initialize = false)
        {
            FeatureCollectionTable dTable;
            FeatureCollectionTable uTable;

            DictionaryRenderer  dRend;
            UniqueValueRenderer uRend;

            string[] codes = Newtonsoft.Json.JsonConvert.DeserializeObject <string[]>(info["codes"].ToString());
            int      page  = int.Parse(info["page"].ToString());

            if (initialize)
            {
                // Create the default symbol
                SimpleMarkerSymbol sms = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Colors.Red, 12)
                {
                    Outline = new SimpleLineSymbol(SimpleLineSymbolStyle.Solid, Colors.Black, 1)
                };

                // Create the Dictionary and Unique Value renderers
                dRend = new DictionaryRenderer(DictionarySymbolStyle.OpenAsync("mil2525c_b2", StylePath).Result);
                uRend = new UniqueValueRenderer(new[] { FieldName }, null, "MilSymbol", sms);

                // Create the fields for the Feature Collection table
                Field[] fields = { new Field(FieldType.Text, FieldName, FieldName, 15) };

                // Create the Feature Collection Tables
                dTable = new FeatureCollectionTable(fields, GeometryType.Point, SpatialReferences.WebMercator)
                {
                    Renderer = dRend
                };
                uTable = new FeatureCollectionTable(fields, GeometryType.Point, SpatialReferences.WebMercator)
                {
                    Renderer = uRend
                };

                // Add the tables to the feature collection
                FeatureCollection collection = new FeatureCollection(new[] { dTable, uTable });

                // Add the collection to the map
                MyMapView.Map.OperationalLayers.Add(new FeatureCollectionLayer(collection));
            }
            else
            {
                // Get the feature collection from the map
                FeatureCollection collection = (MyMapView.Map.OperationalLayers.First() as FeatureCollectionLayer).FeatureCollection;

                // Get the tables from the collection
                dTable = collection.Tables.First();
                uTable = collection.Tables.Last();

                // Clear the records from the table and overlay
                QueryParameters query = new QueryParameters {
                    WhereClause = "1=1"
                };
                await dTable.DeleteFeaturesAsync(dTable.QueryFeaturesAsync(query).Result);

                await uTable.DeleteFeaturesAsync(uTable.QueryFeaturesAsync(query).Result);

                MyMapView.GraphicsOverlays.First().Graphics.Clear();

                // Clear the symbols from the unique value renderer
                (uTable.Renderer as UniqueValueRenderer)?.UniqueValues.Clear();
            }

            // Show the Page #
            MapPoint   titleLocation = new MapPoint(AOI.GetCenter().X, AOI.Extent.YMax + 25);
            TextSymbol titleBar      = new TextSymbol
            {
                Text                = string.Format("Page: {0}", page),
                Color               = Colors.Black,
                BackgroundColor     = Colors.DodgerBlue,
                FontWeight          = Esri.ArcGISRuntime.Symbology.FontWeight.Bold,
                Size                = 50,
                HorizontalAlignment = Esri.ArcGISRuntime.Symbology.HorizontalAlignment.Center,
                VerticalAlignment   = Esri.ArcGISRuntime.Symbology.VerticalAlignment.Bottom,
                OutlineColor        = Colors.Black,
                OutlineWidth        = 2
            };

            MyMapView.GraphicsOverlays.First().Graphics.Add(new Graphic(titleLocation, titleBar));

            int rows = codes.Length / Columns;

            double rowMargin = (AOI.XMax - AOI.XMin) / (Columns - 1);
            double colMargin = (AOI.YMax - AOI.YMin) / rows;

            int count = 0;

            for (double x = AOI.XMin; x < AOI.XMax; x += rowMargin)
            {
                if (count >= codes.Length)
                {
                    break;
                }

                for (double y = AOI.YMax; y > AOI.YMin; y -= colMargin)
                {
                    if (count >= codes.Length)
                    {
                        break;
                    }

                    string code = codes[count];

                    if (code.Length != 15)
                    {
                        System.Diagnostics.Debug.WriteLine(string.Format("Possible invalid code: {0}", code));
                    }
                    else
                    {
                        // Create features with the sidc code
                        Feature dFeature = dTable.CreateFeature(new Dictionary <string, object> {
                            { FieldName, code }
                        }, new MapPoint(x, y, SpatialReferences.WebMercator));
                        Feature uFeature = uTable.CreateFeature(new Dictionary <string, object> {
                            { FieldName, code }
                        }, new MapPoint(x + (rowMargin * 0.5), y, SpatialReferences.WebMercator));

                        // Create a label to display the code
                        TextSymbol label = new TextSymbol
                        {
                            Text            = code,
                            FontWeight      = Esri.ArcGISRuntime.Symbology.FontWeight.Bold,
                            Color           = Colors.DarkGoldenrod,
                            BackgroundColor = Colors.Black,
                            FontFamily      = "Consolas",
                            Size            = 16
                        };

                        MapPoint labelPoint = new MapPoint(x + (rowMargin * 0.25), y - (colMargin * 0.25), SpatialReferences.WebMercator);
                        MyMapView.GraphicsOverlays.First().Graphics.Add(new Graphic(labelPoint, label));

                        // Add the feature to the table
                        await dTable.AddFeatureAsync(dFeature);

                        await uTable.AddFeatureAsync(uFeature);

                        // Triple the size of the Unique Value symbol
                        MultilayerPointSymbol symbol = (MultilayerPointSymbol)(dTable.Renderer as DictionaryRenderer).GetSymbol(dFeature);
                        symbol.Size *= 3;

                        // Add the military symbol to the unique value renderer
                        UniqueValue uval = new UniqueValue(code, code, symbol, code);
                        (uTable.Renderer as UniqueValueRenderer).UniqueValues.Add(uval);
                    }

                    count++;

                    System.Diagnostics.Debug.WriteLine(string.Format(@"Processed feature {0} for {1}...", count, codes.Length));
                }
            }
        }