/// <summary>
        /// Показать окно настроек таблицы
        /// </summary>
        /// <param name="iTable"></param>
        /// <param name="positionElement"></param>
        public override void OpenTableSettings(AbsM.ITableBaseM iTable, UIElement positionElement = null)
        {
            RasM.RastTableBaseM rastrTable = iTable as RasM.RastTableBaseM;

            View.RastrLayerV rastrLayerV = new View.RastrLayerV();
            rastrLayerV.DataContext = new BindingProxy()
            {
                Data = rastrTable
            };
            Window window = new Window();

            window.Title     = String.Format("Редактирование свойств слоя \"{0}\"", rastrTable.Text);
            window.Content   = rastrLayerV;
            window.Icon      = System.Windows.Media.Imaging.BitmapFrame.Create(new Uri("pack://application:,,,/Pie_Chart.ico", UriKind.Absolute));
            window.Height    = 340;
            window.Width     = 330;
            window.MinHeight = 340;
            window.MinWidth  = 330;
            window.Owner     = Program.WinMain;

            if (positionElement != null)
            {
                System.Windows.Point pt = positionElement.TranslatePoint(new System.Windows.Point(0, 0), Program.WinMain);
                window.Top  = pt.Y;
                window.Left = pt.X;
            }
            window.Show();
        }
        /// <summary>
        /// Создает новый слой в источнике
        /// </summary>
        /// <param name="fileName"></param>
        public RasM.RastTableBaseM AddLayer(String filePath)
        {
            RasM.RastTableBaseM rastrTable = null;
            String fileName   = filePath;
            bool   fileExists = false;

            fileExists = fileName != "" && System.IO.File.Exists(fileName);
            if (fileExists)
            {
                if (fileName.StartsWith(System.Windows.Forms.Application.StartupPath))
                {
                    fileName = fileName.Replace(System.Windows.Forms.Application.StartupPath, ".");
                }
                var existingTables =
                    from AbsM.ITableBaseM iTable
                    in Tables
                    where
                    (iTable as RasM.RastTableBaseM).FilePath == fileName
                    select(iTable as RasM.RastTableBaseM);

                if (existingTables.Count() > 0)
                {
                    throw new Exception(String.Format("В системе уже существует слой который указывает на {0}", fileName));
                }
                else
                {
                    var fi = new FileInfo(filePath);
                    rastrTable = new RasM.RastTableBaseM(this, rastrLayerId++, fileName, AbsM.ETableType.Rastr);
                    String rastrNameBase = fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length);

                    bool   nameExists = true;
                    int    i          = 1;
                    String rastrName  = rastrNameBase;
                    while (nameExists)
                    {
                        nameExists = (from AbsM.TableBaseM rTable in Tables where rTable.Name == rastrName select rTable).Count() > 0;
                        if (nameExists)
                        {
                            rastrName = rastrNameBase + i++;
                        }
                    }
                    rastrTable.Name = rastrTable.Text = rastrName;
                    _tables.Add(rastrTable);
                    MGroupAddTable(_groups[0], rastrTable);
                }
            }
            return(rastrTable);
        }
        /// <summary>
        /// Перезагрузка растровых слоев. Информация о растровых слоях берется из конфигурационного xml файла
        /// </summary>
        public void UpdateRastrLayers(object parameter = null)
        {
            var tables = new List <RasM.RastTableBaseM>();

            foreach (var item in Program.SettingsXML.Rasters)
            {
                if (!string.IsNullOrWhiteSpace(item.Name) && !string.IsNullOrWhiteSpace(item.Path))
                {
                    try
                    {
                        var table = FindTable(item.Path) as RasM.RastTableBaseM;
                        if (table == null)
                        {
                            table = new RasM.RastTableBaseM(this, rastrLayerId++, item.Path, AbsM.ETableType.Rastr);
                        }
                        table.GeomType      = AbsM.EGeomType.None;
                        table.FilePath      = item.Path;
                        table.IsExternal    = item.IsExternal;
                        table.BuildPyramids = item.BuildPyramids;
                        table.Name          = item.Name;
                        table.Text          = item.Name;
                        table.IsHidden      = item.IsHidden;
                        table.Description   = item.Description;
                        table.UseBounds     = item.UseBounds;
                        table.MinScale      = item.MinScale;
                        table.MaxScale      = item.MaxScale;
                        table.ConnectType   = (RasM.EConnectType)item.MethodUse;

                        tables.Add(table);
                    }
                    catch (Exception ex)
                    {
                        //MessageBox.Show(ex.Message, Rekod.Properties.Resources.error, System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Error);
                    }
                }
            }
            ExtraFunctions.Sorts.SortList(_tables, tables);
            ExtraFunctions.Sorts.SortList(_groups[0].Tables, tables);
            ExtraFunctions.Sorts.SortList(_groups[1].Tables, _defaultRastrs);

            CollectionViewSource.GetDefaultView(_layers).Refresh();
            CollectionViewSource.GetDefaultView(Groups.ElementAt(0).Tables).Refresh();
        }
Exemple #4
0
 public static void SetIsNewTable(RastTableBaseM layer, bool isnew)
 {
     layer._isNewTable = isnew;
 }
        private List <RasM.RastTableBaseM> GetDefaultLayers()
        {
            var defaultRastrs = new List <RasM.RastTableBaseM>();

            RasM.RastTableBaseM table;
//            String roscosmos =
//                    @"<?xml version=""1.0"" encoding=""utf-8""?>
//                        <TMSRastr>
//                        <Url>http://geoportal.ntsomz.ru/get_tile_external.php?x=$(x)&amp;y=$(y)&amp;scale=$(z)</Url>
//                        <LayerName>roscosmos</LayerName>
//                        <MinZoom>0</MinZoom>
//                        <MaxZoom>16</MaxZoom>
//                        <Proj>+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null +no_defs</Proj>
//                        <TileSize>256</TileSize>
//                        <CacheFolder>cache/roscosmos_cache</CacheFolder>
//                        <TMSExtent>
//                          <a_x>-2.003750834E7</a_x>
//                          <a_y>-2.003750834E7</a_y>
//                          <b_x>2.003750834E7</b_x>
//                          <b_y>2.003750834E7</b_y>
//                        </TMSExtent>
//                        </TMSRastr>";
//            table = new RasM.RastTableBaseM(this, AbsM.ETableType.Rastr)
//            {
//                Text = "Карта Роскосмоса",
//                Name = "roscosmos.xml",
//                GeomType = AbsM.EGeomType.None,
//                IsExternal = true,
//                BuildPyramids = false,
//                Content = roscosmos
//            };
//            defaultRastrs.Add(table);

            String basemap =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
                        <TMSRastr>
	                        <Url>http://basemap.rekod.ru/worldmap/$(z)/$(x)/$(y).png</Url>
	                        <LayerName>worldmap</LayerName>
	                        <MinZoom>0</MinZoom>
	                        <MaxZoom>18</MaxZoom>
	                        <Proj>+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null +no_defs</Proj>
	                        <TileSize>256</TileSize>
	                        <CacheFolder>cache/basemap_cache</CacheFolder>
	                        <TMSExtent>
	                          <a_x>-2.003750834E7</a_x>
	                          <a_y>-2.003750834E7</a_y>
	                          <b_x>2.003750834E7</b_x>
	                          <b_y>2.003750834E7</b_y>
	                        </TMSExtent>
                        </TMSRastr>";

            table = new RasM.RastTableBaseM(this, AbsM.ETableType.Rastr)
            {
                Text          = "Карта России",
                Name          = "basemap.xml",
                GeomType      = AbsM.EGeomType.None,
                IsExternal    = true,
                BuildPyramids = false,
                Content       = basemap
            };
            defaultRastrs.Add(table);

            String osm =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
                        <TMSRastr>
                          <Url>http://a.tile.openstreetmap.org/$(z)/$(x)/$(y).png</Url>
                          <LayerName>osm</LayerName>
                          <MinZoom>0</MinZoom>
                          <MaxZoom>18</MaxZoom>
                          <Proj>+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null +no_defs</Proj>
                          <TileSize>256</TileSize>
                          <CacheFolder>cache/osm_cache</CacheFolder>
                          <TMSExtent>
                            <a_x>-2.003750834E7</a_x>
                            <a_y>-2.003750834E7</a_y>
                            <b_x>2.003750834E7</b_x>
                            <b_y>2.003750834E7</b_y>
                          </TMSExtent>
                        </TMSRastr>";

            table = new RasM.RastTableBaseM(this, AbsM.ETableType.Rastr)
            {
                Text          = "OpenStreetMap",
                Name          = "osm.xml",
                GeomType      = AbsM.EGeomType.None,
                IsExternal    = true,
                BuildPyramids = false,
                Content       = osm
            };
            defaultRastrs.Add(table);


            String osm_roads =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<TMSRastr>
  <Url>http://openmapsurfer.uni-hd.de/tiles/roads/x=$(x)&amp;y=$(y)&amp;z=$(z)</Url>
  <LayerName>osm_roads</LayerName>
  <MinZoom>0</MinZoom>
  <MaxZoom>18</MaxZoom>
  <Proj>+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null +no_defs</Proj>
  <TileSize>256</TileSize>
  <CacheFolder>cache/osm_roads</CacheFolder>
  <TMSExtent>
    <a_x>-2.003750834E7</a_x>
    <a_y>-2.003750834E7</a_y>
    <b_x>2.003750834E7</b_x>
    <b_y>2.003750834E7</b_y>
  </TMSExtent>
</TMSRastr>";

            table = new RasM.RastTableBaseM(this, AbsM.ETableType.Rastr)
            {
                Text          = "OpenStreetMap Roads",
                Name          = "osm_roads.xml",
                GeomType      = AbsM.EGeomType.None,
                IsExternal    = true,
                BuildPyramids = false,
                Content       = osm_roads
            };
            defaultRastrs.Add(table);


            String mapquestMap =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<TMSRastr>
  <Url>http://ttiles01.mqcdn.com/tiles/1.0.0/vy/map/$(z)/$(x)/$(y).png</Url>
  <LayerName>mapquest-map</LayerName>
  <MinZoom>0</MinZoom>
  <MaxZoom>18</MaxZoom>
  <Proj>+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null +no_defs</Proj>
  <TileSize>256</TileSize>
  <CacheFolder>cache/mapquest_map_cache</CacheFolder>
  <TMSExtent>
    <a_x>-2.003750834E7</a_x>
    <a_y>-2.003750834E7</a_y>
    <b_x>2.003750834E7</b_x>
    <b_y>2.003750834E7</b_y>
  </TMSExtent>
</TMSRastr>";

            table = new RasM.RastTableBaseM(this, AbsM.ETableType.Rastr)
            {
                Text          = "MapQuest Карта",
                Name          = "mapquest-map.xml",
                GeomType      = AbsM.EGeomType.None,
                IsExternal    = true,
                BuildPyramids = false,
                Content       = mapquestMap
            };
            defaultRastrs.Add(table);

            String mapquestSat =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<TMSRastr>
  <Url>http://ttiles01.mqcdn.com/tiles/1.0.0/vy/sat/$(z)/$(x)/$(y).png</Url>
  <LayerName>mapquest-sat</LayerName>
  <MinZoom>0</MinZoom>
  <MaxZoom>13</MaxZoom>
  <Proj>+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null +no_defs</Proj>
  <TileSize>256</TileSize>
  <CacheFolder>cache/mapquest_sat_cache</CacheFolder>
  <TMSExtent>
    <a_x>-2.003750834E7</a_x>
    <a_y>-2.003750834E7</a_y>
    <b_x>2.003750834E7</b_x>
    <b_y>2.003750834E7</b_y>
  </TMSExtent>
</TMSRastr>";

            table = new RasM.RastTableBaseM(this, AbsM.ETableType.Rastr)
            {
                Text          = "MapQuest Спутник",
                Name          = "mapquest-sat.xml",
                GeomType      = AbsM.EGeomType.None,
                IsExternal    = true,
                BuildPyramids = false,
                Content       = mapquestSat
            };
            defaultRastrs.Add(table);

            String mapquestLabel =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<TMSRastr>
  <Url>http://ttiles01.mqcdn.com/tiles/1.0.0/vy/hyb/$(z)/$(x)/$(y).png</Url>
  <LayerName>mapquest-labels</LayerName>
  <MinZoom>0</MinZoom>
  <MaxZoom>18</MaxZoom>
  <Proj>+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +units=m +k=1.0 +nadgrids=@null +no_defs</Proj>
  <TileSize>256</TileSize>
  <CacheFolder>cache/mapquest_hyb_cache</CacheFolder>
  <TMSExtent>
    <a_x>-2.003750834E7</a_x>
    <a_y>-2.003750834E7</a_y>
    <b_x>2.003750834E7</b_x>
    <b_y>2.003750834E7</b_y>
  </TMSExtent>
</TMSRastr>";

            table = new RasM.RastTableBaseM(this, AbsM.ETableType.Rastr)
            {
                Text          = "MapQuest Подписи",
                Name          = "mapquest-labels.xml",
                GeomType      = AbsM.EGeomType.None,
                IsExternal    = true,
                BuildPyramids = false,
                Content       = mapquestLabel
            };
            defaultRastrs.Add(table);

            String yandex_map =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<TMSRastr>
  <Url>http://vec02.maps.yandex.net/tiles?l=map&amp;v=4.3.3&amp;x=$(x)&amp;y=$(y)&amp;z=$(z)&amp;lang=ru_RU</Url>
  <LayerName>yandex map</LayerName>
  <MinZoom>0</MinZoom>
  <MaxZoom>18</MaxZoom>
  <Proj>+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs</Proj>
  <TileSize>256</TileSize>
  <CacheFolder>cache/yandex_map</CacheFolder>
  <TMSExtent>
    <a_x>-2.003750834E7</a_x>
    <a_y>-2.003750834E7</a_y>
    <b_x>2.003750834E7</b_x>
    <b_y>2.003750834E7</b_y>
  </TMSExtent>
</TMSRastr>";

            table = new RasM.RastTableBaseM(this, AbsM.ETableType.Rastr)
            {
                Text          = "Яндекс Карта",
                Name          = "yandex_map.xml",
                GeomType      = AbsM.EGeomType.None,
                IsExternal    = true,
                BuildPyramids = false,
                Content       = yandex_map
            };
            defaultRastrs.Add(table);

            String yandex_sat =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<TMSRastr>
  <Url>http://sat02.maps.yandex.net/tiles?l=sat&amp;v=3.132.0&amp;x=$(x)&amp;y=$(y)&amp;z=$(z)&amp;lang=ru_RU</Url>
  <LayerName>yandex-sat</LayerName>
  <MinZoom>0</MinZoom>
  <MaxZoom>18</MaxZoom>
  <Proj>+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs</Proj>
  <TileSize>256</TileSize>
  <CacheFolder>cache/yandex_sat</CacheFolder>
  <TMSExtent>
    <a_x>-2.003750834E7</a_x>
    <a_y>-2.003750834E7</a_y>
    <b_x>2.003750834E7</b_x>
    <b_y>2.003750834E7</b_y>
  </TMSExtent>
</TMSRastr>";

            table = new RasM.RastTableBaseM(this, AbsM.ETableType.Rastr)
            {
                Text          = "Яндекс Спутник",
                Name          = "yandex_sat.xml",
                GeomType      = AbsM.EGeomType.None,
                IsExternal    = true,
                BuildPyramids = false,
                Content       = yandex_sat
            };
            defaultRastrs.Add(table);

            String yandex_label =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<TMSRastr>
  <Url>http://vec02.maps.yandex.net/tiles?l=skl&amp;v=4.4.9&amp;x=$(x)&amp;y=$(y)&amp;z=$(z)&amp;lang=ru_RU</Url>
  <LayerName>yandex-label</LayerName>
  <MinZoom>0</MinZoom>
  <MaxZoom>18</MaxZoom>
  <Proj>+proj=merc +lon_0=0 +k=1 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs</Proj>
  <TileSize>256</TileSize>
  <CacheFolder>cache/yandex_label</CacheFolder>
  <TMSExtent>
    <a_x>-2.003750834E7</a_x>
    <a_y>-2.003750834E7</a_y>
    <b_x>2.003750834E7</b_x>
    <b_y>2.003750834E7</b_y>
  </TMSExtent>
</TMSRastr>";

            table = new RasM.RastTableBaseM(this, AbsM.ETableType.Rastr)
            {
                Text          = "Яндекс Подписи",
                Name          = "yandex_label.xml",
                GeomType      = AbsM.EGeomType.None,
                IsExternal    = true,
                BuildPyramids = false,
                Content       = yandex_label
            };
            defaultRastrs.Add(table);


            String rosreestr_map =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<TWMSRastr>
  <Url>http://maps.rosreestr.ru/ArcGIS/rest/services/CadastreNew/Cadastre/MapServer/export?dpi=96&amp;transparent=true&amp;format=png32&amp;bbox=$(box)&amp;bboxSR=$(boxsrid)&amp;imageSR=$(imagesrid)&amp;size=$(width),$(height)&amp;f=image</Url>
  <Layers>
    <TWMSLayerM>
      <LayerName>RosReester</LayerName>
      <StyleName/>
    </TWMSLayerM>
  </Layers>
  <SRID>3395</SRID>
  <TileSize>256</TileSize>
  <ZoomCount>20</ZoomCount>
  <CacheFolder>cache/RosReester</CacheFolder>
  <TWMSExtent>
    <a_x>-20037508.3428</a_x>
    <a_y>-15496570.7397</a_y>
    <b_x>20037508.3428</b_x>
    <b_y>18764656.2314</b_y>
  </TWMSExtent>
</TWMSRastr>";

            table = new RasM.RastTableBaseM(this, AbsM.ETableType.Rastr)
            {
                Text          = "Росреестр",
                Name          = "rosreestr.xml",
                GeomType      = AbsM.EGeomType.None,
                IsExternal    = true,
                BuildPyramids = false,
                Content       = rosreestr_map
            };
            defaultRastrs.Add(table);

            return(defaultRastrs);
        }
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            BindingGroup bindingGroup = (BindingGroup)value;

            if (bindingGroup.Items.Count > 0)
            {
                RasM.RastTableBaseM         rastrLayer = (RasM.RastTableBaseM)(bindingGroup.Items[0]);
                RasVM.RastrDataRepositoryVM rastrRepo  = rastrLayer.Source as RasVM.RastrDataRepositoryVM;
                Object filePathObject = null;
                if (bindingGroup.TryGetValue(rastrLayer, "FilePath", out filePathObject))
                {
                    String filePath   = Convert.ToString(filePathObject);
                    bool   fileExists = false;
                    fileExists = filePath != "" && System.IO.File.Exists(filePath);
                    if (!fileExists)
                    {
                        if (filePath.StartsWith("."))
                        {
                            filePath = System.Windows.Forms.Application.StartupPath + "\\" + filePath.TrimStart(new char[] { '.', '\\' });
                            if (System.IO.File.Exists(filePath))
                            {
                                fileExists = true;
                            }
                        }
                    }
                    if (!fileExists)
                    {
                        return(new ValidationResult(false, "Путь к файлу задан неправильно"));
                    }
                    else
                    {
                        foreach (var iTable in rastrRepo.Tables)
                        {
                            RasM.RastTableBaseM rastrTable = iTable as RasM.RastTableBaseM;
                            if (rastrTable != rastrLayer && rastrTable.FilePath == filePath)
                            {
                                return(new ValidationResult(false,
                                                            "В системе уже присутствует растровый слой который указывает на этот файл"));
                            }
                        }
                    }
                }
                else
                {
                    return(new ValidationResult(false, "Не задано свойство \"Путь к файлу\""));
                }

                String rastrName = (String)bindingGroup.GetValue(rastrLayer, "Text");
                if (String.IsNullOrEmpty(rastrName.Trim()))
                {
                    return(new ValidationResult(false, "Не задано название растрового слоя"));
                }

                bool rastrNameExists =
                    (from AbsM.TableBaseM rastrTable in rastrRepo.Tables where (rastrTable.Text == rastrName && rastrLayer != rastrTable) select rastrTable).Count() > 0;
                if (rastrNameExists)
                {
                    return(new ValidationResult(false, "Слой с таким названием уже существует"));
                }


                BooleanYesNoConverter boolYesNo = new BooleanYesNoConverter();
                bool useBounds = Convert.ToBoolean(boolYesNo.ConvertBack(bindingGroup.GetValue(rastrLayer, "UseBounds"), null, null, null));

                object minScaleObj = bindingGroup.GetValue(rastrLayer, "MinScale");
                object maxScaleObj = bindingGroup.GetValue(rastrLayer, "MaxScale");

                int minScale = -1;
                int maxScale = -1;

                try
                {
                    minScale = Convert.ToInt32(minScaleObj);
                }
                catch (Exception ex)
                {
                    String mes = "Ошибка в значении нижней границы масштаба: \n" + ex.Message;
                    return(new ValidationResult(false, mes));
                }
                try
                {
                    maxScale = Convert.ToInt32(maxScaleObj);
                }
                catch (Exception ex)
                {
                    String mes = "Ошибка в значении верхней границы масштаба: \n" + ex.Message;
                    return(new ValidationResult(false, mes));
                }
                if (useBounds)
                {
                    if (minScale < 0)
                    {
                        return(new ValidationResult(false, "Минимальное значение не может быть отрицательным числом"));
                    }
                    if (maxScale < 0)
                    {
                        return(new ValidationResult(false, "Максимальное значение не может быть отрицательным числом"));
                    }
                    if (minScale > maxScale)
                    {
                        return(new ValidationResult(false, "Минимальное значение не может быть больше максимального"));
                    }
                }


                return(ValidationResult.ValidResult);
            }
            else
            {
                return(new ValidationResult(false, "Не выбран объект для отображения"));
            }
        }