Exemple #1
0
        private void SearchAsync()
        {
            EndInvoke(_asyncResult);
            string search = $"{TextEditName.Text}, {SearchLookupEditState.EditValue}, {(SearchLookupEditCountry.EditValue as CodeName)?.Name}";

            BingSearchDataProvider.Search(search);
        }
        public override InformationDataProviderBase CreateDataProvider(InformationLayer layer, string search, int resultCount)
        {
            GeoPoint anchorPoint = null;

            if (AnchorPoint != null && AnchorPoint.Length > 0 && AnchorPoint.Length != 2)
            {
                throw new Exception("Invalid anchor point. Shall be a double array with 2 elements.");
            }

            if (AnchorPoint != null && AnchorPoint.Length == 2)
            {
                anchorPoint = new GeoPoint(AnchorPoint[0], AnchorPoint[1]);
            }

            SearchBoundingBox boundingBox = null;

            if (BoundingBox != null && BoundingBox.Length > 0 && BoundingBox.Length != 4)
            {
                throw new Exception("Invalid bounding box. Shall be a double array with 4 elements.");
            }

            if (BoundingBox != null && BoundingBox.Length == 4)
            {
                boundingBox = new SearchBoundingBox(BoundingBox[0], BoundingBox[1], BoundingBox[2], BoundingBox[3]);
            }

            var provider = new BingSearchDataProvider()
            {
                BingKey               = Parameters.BingMapKey,
                ConnectionProtocol    = ConnectionProtocol.Https,
                GenerateLayerItems    = true,
                MaxVisibleResultCount = resultCount,
                ProcessMouseEvents    = false
            };

            provider.SearchOptions.ResultsCount = resultCount;

            layer.DataProvider = provider;

            /*
             * var completion = new TaskCompletionSource<InformationDataProviderBase>();
             *
             * provider.SearchCompleted += (s, e) =>
             * {
             *      completion.SetResult(provider);
             * };
             */

            provider.Search(search, Culture, anchorPoint, boundingBox);

            //return completion.Task.Result;
            return(provider);
        }
Exemple #3
0
 void OnDataProviderChanged(BingSearchDataProvider oldValue, BingSearchDataProvider newValue)
 {
     if (oldValue != null)
     {
         oldValue.SearchCompleted -= OnDataProviderSearchCompleted;
     }
     if (newValue != null)
     {
         newValue.SearchCompleted += OnDataProviderSearchCompleted;
     }
     UpdateLocation();
 }
Exemple #4
0
        public Form1()
        {
            InitializeComponent();

            BingSearchDataProvider searchProvider = new BingSearchDataProvider()
            {
                BingKey = bingKey
            };

            searchProvider.SearchOptions.ResultsCount = 5;

            SearchLayer.DataProvider = searchProvider;
        }
        public SCMap AddBingSearchLayer(string search, BingSearchLayerOptions options = null)
        {
            options ??= new BingSearchLayerOptions();

            GeoPoint anchorPoint = null;

            if (options.AnchorPoint != null && options.AnchorPoint.Length > 0 && options.AnchorPoint.Length != 2)
            {
                throw new Exception("Invalid anchor point. Shall be a double array with 2 elements.");
            }

            if (options.AnchorPoint != null && options.AnchorPoint.Length == 2)
            {
                anchorPoint = new GeoPoint(options.AnchorPoint[0], options.AnchorPoint[1]);
            }

            SearchBoundingBox boundingBox = null;

            if (options.BoundingBox != null && options.BoundingBox.Length > 0 && options.BoundingBox.Length != 4)
            {
                throw new Exception("Invalid bounding box. Shall be a double array with 4 elements.");
            }

            if (options.BoundingBox != null && options.BoundingBox.Length == 4)
            {
                boundingBox = new SearchBoundingBox(options.BoundingBox[0], options.BoundingBox[1], options.BoundingBox[2], options.BoundingBox[3]);
            }

            var provider = new BingSearchDataProvider()
            {
                BingKey               = Parameters.BingMapKey,
                ConnectionProtocol    = ConnectionProtocol.Https,
                GenerateLayerItems    = true,
                MaxVisibleResultCount = options.ResultCount,
                ProcessMouseEvents    = false
            };

            provider.SearchOptions.ResultsCount = options.ResultCount;

            options.CreateLayer(this, provider);

            provider.Search(search, options.Culture, anchorPoint, boundingBox);

            return(this);
        }
Exemple #6
0
        private void PrepareMap()
        {
            // Create a map control.
            map = new MapControl();

            // Specify the map position on the form.
            map.Dock = DockStyle.Fill;

            // Add the map control to the window.
            this.Controls.Add(map);

            // Bring the map to the front.
            map.BringToFront();

            // Create an image tiles layer and add it to the map.
            ImageLayer tilesLayer = new ImageLayer();

            map.Layers.Add(tilesLayer);

            // Create an information layer and add it to the map.
            InformationLayer infoLayer = new InformationLayer();

            map.Layers.Add(infoLayer);

            VectorItemsLayer items = new VectorItemsLayer();

            items.Data = new MapItemStorage();
            map.Layers.Add(items);

            // Create a Bing data provider and specify the Bing key.
            BingMapDataProvider bingProvider = new BingMapDataProvider();

            tilesLayer.DataProvider = bingProvider;
            bingProvider.BingKey    = yourBingKey;

            // Create a Bing search data provider and specify the Bing key.
            searchProvider                    = new BingSearchDataProvider();
            infoLayer.DataProvider            = searchProvider;
            searchProvider.GenerateLayerItems = false;
            searchProvider.BingKey            = yourBingKey;
            map.ShowSearchPanel               = false;
        }