Example #1
0
        // Summary:
        //     Load features in a FeatureTable into a GraphicsLayer
        //
        async Task<IS3GraphicsLayer> featureTable2GraphicsLayer(FeatureTable table,
            int start = 0, int maxFeatures = 0, bool isShp = false)
        {
            if (table == null)
                return null;

            if (_srEMap == null)
            {
                // The spatial reference in the first table is used as the project spatial reference.
                // All features on other layers will be projected to the spatial reference.
                _srEMap = table.SpatialReference;
                _map.SpatialReference = table.SpatialReference;
            }

            //// We cannot use the feature layer class because it typically 
            //// has a different SpatialReferece object (coordinate system)
            //// other than the tiled layer (WKID = 3857 or 102100),
            //// and there is no easy way to reproject feature layer
            //// to another coordinate system.
            //// We can only use the feature layer when there is no tiled layer defined,
            //// which is not a usual case.
            //FeatureLayer fLayer = new FeatureLayer(table);
            //fLayer.ID = table.Name;
            //fLayer.DisplayName = table.Name;
            //_map.Layers.Add(fLayer);

            QueryFilter qf = new QueryFilter();
            qf.WhereClause = "1=1";
            IEnumerable<Feature> features = await table.QueryAsync(qf);
            IS3GraphicCollection graphics = new IS3GraphicCollection();

            int index = 0, count = 0;
            foreach (Feature f in features)
            {
                // jump to start position
                if (index++ < start)
                    continue;

                // Note:
                //     In ArcGIS Runtime SDK: User-defined coordinate system
                //     is not allowed when using ShapefileTable.OpenAsync().
                // Workaround:
                //     (1) Do not assign user-defined CS in shape file;
                //     (2) Assign CS dynamically here to _srEMap.
                //
                Geometry geometry = f.Geometry;
                if (isShp == true)
                {
                    geometry = ArcGISMappingUtility.ChangeSpatailReference(geometry, _srEMap);
                    if (geometry == null)
                        continue;
                }

                if (_srEMap != null && isShp == false && geometry.SpatialReference != _srEMap)
                    geometry = GeometryEngine.Project(geometry, _srEMap);

                // import the attributes
                IS3Graphic g = new IS3Graphic(geometry);
                foreach (KeyValuePair<string, object> item in f.Attributes.AsEnumerable())
                    g.Attributes.Add(item);
                graphics.Add(g);

                // Load max featuers
                if (maxFeatures != 0 && count++ == maxFeatures)
                    break;
            }

            IS3GraphicsLayer gLayer = new IS3GraphicsLayer();
            gLayer.DisplayName = table.Name;
            gLayer.GraphicsSource = graphics;
            gLayer.geometryType = (IS3.Core.Geometry.GeometryType)(int)table.GeometryType;

            return gLayer;
        }
Example #2
0
        // Summary:
        //     Set the GraphicsLayer display options according to the definition
        //     which is specified in the LocalELayer.
        //     The display options include selection color, renderer, and labelling
        //
        void setGraphicLayerDisplayOptions(LayerDef layerDef, IS3GraphicsLayer gLayer)
        {
            if (layerDef == null || gLayer == null)
                return;

            gLayer.IsVisible = layerDef.IsVisible;

            gLayer.SelectionColor = layerDef.SelectionColor;
            if (layerDef.RendererDef == null)
            {
                ISymbol symbol = GraphicsUtil.GenerateLayerSymbol(layerDef, gLayer.geometryType);
                gLayer.renderer = Runtime.graphicEngine.newSimpleRenderer(symbol);
            }
            else
            {
                gLayer.renderer = Runtime.graphicEngine.newRenderer(layerDef.RendererDef);
            }

            if (layerDef.EnableLabel == true)
            {
                AttributeLabelClass labelClass = generateLayerAttributeLable(layerDef, gLayer.geometryType);
                gLayer.Labeling.LabelClasses.Add(labelClass);
            }
        }
Example #3
0
        public async Task drawGraphics(DrawShapeType drawShapeType)
        {
            if (Globals.isThreadUnsafe())
            {
                await Globals.application.Dispatcher.Invoke(new Func<Task>(async () =>
                {
                    await drawGraphics(drawShapeType);
                }));
                return;
            }

            // Add a drawing graphics layer
            if (_drawingLayer == null)
            {
                _drawingLayer = new IS3GraphicsLayer();
                _drawingLayer.ID = "0";
                _drawingLayer.DisplayName = "0";
                _map.Layers.Add(_drawingLayer);
            }

            if (_mapView.Editor.IsActive)
                return;

            try
            {
                Geometry geom = await _mapView.Editor.RequestShapeAsync((DrawShape)drawShapeType);
                if (_srEMap != null)
                    geom = GeometryEngine.Project(geom, _srEMap);
                IGeometry iGeom = IS3GeometryEngine.fromGeometry(geom);
                IGraphic g = Runtime.graphicEngine.newGraphic(iGeom);
                GraphicsUtil.AssignDefaultDrawingSymbol(g);

                _drawingLayer.graphics.Add(g);

                // trigger a drawing graphics changed event
                if (drawingGraphicsChangedTrigger != null)
                {
                    DrawingGraphicsChangedEventArgs args =
                        new DrawingGraphicsChangedEventArgs();
                    List<IGraphic> addedItems = new List<IGraphic>();
                    addedItems.Add(g);
                    args.addedItems = addedItems;
                    drawingGraphicsChangedTrigger(this, args);
                }
            }
            catch (TaskCanceledException)
            {
                // Ignore TaskCanceledException - usually happens if the editor gets cancelled or restarted
            }
        }