Пример #1
0
        /// <summary>
        /// Creates a new shape
        /// </summary>
        /// <param name="viewModel"></param>
        /// <returns></returns>
        private MapShape CreateShape(object viewModel)
        {
            var path = GetPathValue(viewModel);

            if (path != null && path.Any())
            {
                var newShape = CreateDrawable(viewModel, path);
                newShape.Tapped += ShapeTapped;

                MapElementProperties.SetViewModel(newShape, viewModel);
                MapElementProperties.SetLayerName(newShape, LayerName);

                // Listen to property changed event of geometry property to check if the shape needs to
                // be redrawed
                var evt = viewModel.GetType().GetRuntimeEvent("PropertyChanged");
                if (evt != null)
                {
                    Observable.FromEventPattern <PropertyChangedEventArgs>(viewModel, "PropertyChanged")
                    .Subscribe(se =>
                    {
                        if (se.EventArgs.PropertyName == PathPropertyName)
                        {
                            ReplaceShape(se.Sender);
                        }
                    });
                }
                return(newShape);
            }
            return(null);
        }
Пример #2
0
        private void RemoveShape(object viewModel)
        {
            var shape = _mapLayer.Shapes.FirstOrDefault(p => MapElementProperties.GetViewModel(p) == viewModel);

            if (shape != null)
            {
                _mapLayer.Shapes.Remove(shape);
                shape.Tapped -= ShapeTapped;
            }
        }
Пример #3
0
        private void ShapeTapped(object sender, TappedRoutedEventArgs e)
        {
            var shape = sender as MapShape;

            if (shape != null)
            {
                var viewModel = MapElementProperties.GetViewModel(shape);
                if (viewModel != null)
                {
                    FireViewmodelCommand(viewModel, TapCommand);
                }
            }
        }
Пример #4
0
        private void ReplaceShape(object viewModel)
        {
            var shape = _mapLayer.Shapes.FirstOrDefault(p => MapElementProperties.GetViewModel(p) == viewModel);

            if (shape != null)
            {
                var shapeLocation = _mapLayer.Shapes.IndexOf(shape);
                if (shapeLocation != -1)
                {
                    var newShape = CreateShape(viewModel);
                    if (newShape != null)
                    {
                        _mapLayer.Shapes[shapeLocation].Tapped -= ShapeTapped;
                        _mapLayer.Shapes[shapeLocation]         = CreateShape(viewModel);
                    }
                }
            }
            else
            {
                AddNewShape(viewModel);
            }
        }