Beispiel #1
0
 /// <summary> Commits changes for old element source. </summary>
 private void CommitIfNecessary(IElementSource elementSource)
 {
     if (_currentElementSource != null && _currentElementSource != elementSource)
     {
         _elementSourceEditor.Commit();
     }
 }
Beispiel #2
0
        /// <summary> Ensures that the corresponding element source is loaded. </summary>
        private void EnsureElementSource(Vector2d point)
        {
            var boundingBox   = _tileController.GetTile(point).BoundingBox;
            var elementSource = _elementSourceProvider.Get(boundingBox)
                                .SingleOrDefault(e => !e.IsReadOnly).Wait();

            // create in memory element source
            if (elementSource == null)
            {
                // NOTE use bounding box which fits whole world
                var indexBuilder = new InMemoryIndexBuilder(new BoundingBox(
                                                                new GeoCoordinate(-90, -180), new GeoCoordinate(90, 180)),
                                                            IndexSettings.CreateDefault(), _objectPool, Trace);
                indexBuilder.Build();

                elementSource = new ElementSource(indexBuilder)
                {
                    IsReadOnly = false
                };
                _elementSourceProvider.Add(elementSource);
            }

            CommitIfNecessary(elementSource);

            _currentElementSource = elementSource;
            _elementSourceEditor.ElementSource = _currentElementSource;
        }
 /// <inheritdoc />
 public void Add(IElementSource elementSource)
 {
     _tree.Insert(new TreeNode()
     {
         ElementSource = elementSource
     }, elementSource.BoundingBox);
 }
        private int ConsumeStructuredText(string data, int offset, Regex stopAt)
        {
            Match match = stopAt.Match(data, offset);

            /*
             *          if (!match.Success)
             *          {
             *              // Failure.  If an end tag is never encountered, the
             *              // begin tag does not count.
             *              // We can remove this whole clause if we want to behave
             *              // more like IE than Gecko.
             *              retval = string.Empty;
             *              return 0;
             *          }
             */

            int end = match.Success ? match.Index : data.Length;

            // HACK: this code should not be aware of parser types
            IElementSource source = (stopAt == endScript) ? (IElementSource) new JavascriptParser(data, offset, end - offset) : (IElementSource) new CssParser(data, offset, end - offset);
            Stack          stack  = new Stack();
            Element        element;
            int            last = pos;

            while (null != (element = source.Next()))
            {
                stack.Push(element);
            }
            foreach (Element el in stack)
            {
                elementStack.Push(el);
            }

            return(end - offset);
        }
        private void RaiseElementDeselectedEvent(ElementSelectionType type)
        {
            IElementSource esrc = DataContext as IElementSource;

            if (esrc != null)
            {
                RaiseEvent(new ElementDeselectedEventArgs(this, esrc.Element, type));
            }
        }
        public void Setup()
        {
            _boundingBox = BoundingBox.Create(TestHelper.BerlinTestFilePoint, 500);
            var indexBuilder = new InMemoryIndexBuilder(_boundingBox,
                                                        TestHelper.GetIndexSettings(), TestHelper.GetObjectPool(), new ConsoleTrace());

            indexBuilder.Build();

            _editor = new ElementSourceEditor();
            _editor.ElementSource = _elementSource = new ElementSource(indexBuilder);
        }
        /// <summary> Gets data from remote server. </summary>
        private IObservable <IElementSource> GetRemoteElementSource(string path, BoundingBox query)
        {
            // make online query
            var queryString = String.Format(_mapDataServerQuery,
                                            query.MinPoint.Latitude, query.MinPoint.Longitude,
                                            query.MaxPoint.Latitude, query.MaxPoint.Longitude);

            var uri = String.Format("{0}{1}", _mapDataServerUri, Uri.EscapeDataString(queryString));

            Trace.Warn(Category, Strings.NoPresistentElementSourceFound, query.ToString(), uri);
            return(ObservableWWW.GetAndGetBytes(uri)
                   .Take(1)
                   .SelectMany(bytes =>
            {
                Trace.Info(Category, "add to cache {0} and build index from {1} bytes received",
                           path, bytes.Length.ToString());
                IElementSource elementSource = null;
                lock (_tree)
                {
                    // add to persistent cache
                    if (!_fileSystemService.Exists(path))
                    {
                        using (var stream = _fileSystemService.WriteStream(path))
                            stream.Write(bytes, 0, bytes.Length);
                    }
                    // build element source from bytes
                    elementSource = BuildElementSourceInMemory(bytes);
                    _tree.Insert(new TreeNode()
                    {
                        Path = path,
                        ElementSource = elementSource
                    }, query);
                }
                return Observable.Return(elementSource);
            }));
        }