Exemple #1
0
        static void SearchWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            var tuple = e.Argument as Tuple <IEnumerable <LayerInfo>, SearchRegion, MultiDimensionalObjectRelationship, bool>;

            if (tuple != null)
            {
                using (new JoobContext())
                {
                    var layerInfos    = tuple.Item1;
                    var region        = tuple.Item2;
                    var relationship  = tuple.Item3;
                    var spatialSearch = tuple.Item4;

                    long totalSearchTime;
                    IEnumerable <FeatureSet> featureSets;

                    var watch = new Stopwatch();
                    watch.Start();

                    if (spatialSearch)
                    {
                        featureSets = MapDataAdapter.SpatialSearch(layerInfos, region, relationship, out totalSearchTime);
                    }
                    else
                    {
                        featureSets = MapDataAdapter.NameSearch(layerInfos, region, out totalSearchTime);
                    }

                    e.Result = Tuple.Create(featureSets, totalSearchTime);
                }
            }
        }
        private void MenuItemLoadDefaultData_Click(object sender, EventArgs e)
        {
            var result = MessageBox.Show(this, @"Loading default data may take a long time, do you want to continue?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2);

            if (result == DialogResult.Yes)
            {
                try
                {
                    MapDataAdapter.Reset();

                    var importForm = new ImportProgressForm(new StateDataImporter(@"Data\US_States.txt"), MapDataAdapter.FeatureTypeStates);
                    var toContinue = importForm.ShowDialog(this) == DialogResult.OK;

                    if (toContinue)
                    {
                        importForm = new ImportProgressForm(new CountyDataImporter(@"Data\US_Counties.txt"), MapDataAdapter.FeatureTypeCounties);
                        toContinue = importForm.ShowDialog(this) == DialogResult.OK;
                    }

                    if (toContinue)
                    {
                        importForm = new ImportProgressForm(new CityDataImporter(@"Data\US_Cities.txt"), MapDataAdapter.FeatureTypeCities);
                        importForm.ShowDialog(this);
                    }
                }
                catch
                {
                    MessageBox.Show(this, @"Failed to import the default data, please try again.", @"Importation Failure", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                }

                _searchCtrl.RefreshData();
            }
        }
        private void AddLayerHandler(object sender, EventArgs e)
        {
            var addLayerForm = new AddLayerForm();

            if (addLayerForm.ShowDialog(this) == DialogResult.OK)
            {
                var featureSet = new FeatureSet(addLayerForm.FeatureType)
                {
                    Name = addLayerForm.LayerName
                };
                var dataPath     = addLayerForm.DataPath;
                var displayLayer = addLayerForm.DisplayAfterImportation;

                var importForm = new ImportProgressForm(new SpatialLayerDataImporter(featureSet.Name, dataPath));
                if (importForm.ShowDialog(this) == DialogResult.OK)
                {
                    if (displayLayer)
                    {
                        var geometries = importForm.GetImportedObjects <JoobGeometry>();
                        MapDataAdapter.PopulateFeatureSet(geometries, featureSet);

                        var layer = map.Layers.Add(featureSet);
                        if (layer != null)
                        {
                            layer.LegendText = featureSet.Name;
                        }
                        map.ViewExtents.ExpandToInclude(featureSet.Extent);
                    }

                    _searchCtrl.RefreshLayers();
                }
            }
        }
Exemple #4
0
        public void RefreshLayers()
        {
            chbLayerNames.Items.Clear();
            var layers = MapDataAdapter.GetAllLayers();

            if (layers.Count() > 0)
            {
                gbxLayers.Visible = true;
                chbLayerNames.Items.AddRange(layers.ToArray());
                chbLayerNames.SetItemChecked(0, true);
            }
            else
            {
                gbxLayers.Visible = false;
            }
        }
        private bool ValidateName()
        {
            string error = null;

            if (string.IsNullOrWhiteSpace(txtName.Text))
            {
                error = "Please enter a name";
            }
            else if (MapDataAdapter.GetAllLayers().Any(item => item.Name.Equals(txtName.Text, StringComparison.OrdinalIgnoreCase)))
            {
                error = "The layer name already exists";
            }

            errPrvAddLayer.DisplayError(txtName, error);
            return(error == null);
        }
        public static void PopulatePredefinedRegions()
        {
            if (PredefinedSearchRegions.Count == 0)
            {
                var geom = MapDataAdapter.GetStateGeomByAbbr("CA");
                if (geom != null)
                {
                    PredefinedSearchRegions.Add(new SearchRegion("CA", "California", geom));
                }

                geom = MapDataAdapter.GetStateGeomByAbbr("FL");
                if (geom != null)
                {
                    PredefinedSearchRegions.Add(new SearchRegion("FL", "Florida", geom));
                }

                geom = MapDataAdapter.GetStateGeomByAbbr("HI");
                if (geom != null)
                {
                    PredefinedSearchRegions.Add(new SearchRegion("HI", "Hawaii", geom));
                }

                geom = MapDataAdapter.GetStateGeomByAbbr("KY");
                if (geom != null)
                {
                    PredefinedSearchRegions.Add(new SearchRegion("KY", "Kentucky", geom));
                }

                geom = MapDataAdapter.GetStateGeomByAbbr("NV");
                if (geom != null)
                {
                    PredefinedSearchRegions.Add(new SearchRegion("NV", "Nevada", geom));
                }

                geom = MapDataAdapter.GetStateGeomByAbbr("TX");
                if (geom != null)
                {
                    PredefinedSearchRegions.Add(new SearchRegion("TX", "Texas", geom));
                }

                geom = MapDataAdapter.GetStateGeomByAbbr("WA");
                if (geom != null)
                {
                    PredefinedSearchRegions.Add(new SearchRegion("WA", "Washington", geom));
                }
            }
        }