public static int MapExtractedFishingTrack(FishingTripAndGearRetrievalTracks th, out List <int> handles)
 {
     handles = new List <int>();
     if (th != null && th.GearRetrievalTracks.Count > 0 && ShapefileFactory.ExtractFishingTrackLine)
     {
         var sf = ShapefileFactory.FishingTrackLine(th);
         if (sf != null)
         {
             return(MapLayersHandler.AddLayer(sf, "Extracted fishng track", uniqueLayer: true, layerKey: sf.Key));
         }
     }
     return(-1);
 }
 public static FishingTripAndGearRetrievalTracks MapTrackCTX(CTXFileSummaryView ctx)
 {
     if (ctx.TrackpointsCount != null && ctx.TrackpointsCount > 0)
     {
         var result = ShapefileFactory.CreateTripAndHaulsFromCTX(ctx);
         if (result != null)
         {
             MapLayersHandler.AddLayer(result.TripShapefile, "CTX track", uniqueLayer: true, layerKey: result.TripShapefile.Key, rejectIfExisting: true);
         }
         return(result);
     }
     return(null);
 }
 public static FishingTripAndGearRetrievalTracks MapTrackGPX(GPXFile gpxfile)
 {
     if (gpxfile.Tracks.Count > 0)
     {
         var result = ShapefileFactory.CreateTripAndHaulsFromGPX(gpxfile);
         if (result != null)
         {
             MapLayersHandler.AddLayer(result.TripShapefile, "GPX track", uniqueLayer: true, layerKey: result.TripShapefile.Key, rejectIfExisting: true);
         }
         return(result);
     }
     return(null);
 }
Example #4
0
        private void MaplayersHandler_LayerRead(MapLayersHandler s, LayerEventArg e)
        {
            MapLayerCollection.Insert(0, s.CurrentMapLayer);

            if (LayerRead != null)
            {
                var item = MaplayersHandler.MapLayerDictionary[e.LayerHandle];


                LayerEventArg lp = new LayerEventArg(item.Handle, item.Name, item.Visible, item.VisibleInLayersUI, item.LayerType);
                LayerRead(this, lp);
            }
        }
 protected virtual void Dispose(bool disposing)
 {
     if (!_disposed)
     {
         if (disposing)
         {
         }
         _mapLayersHandler = null;
         _currentMapLayer  = null;
         _axMap            = null;
         _disposed         = true;
     }
 }
 public static int MapExtractedFishingTrack(out List <int> handles)
 {
     handles = new List <int>();
     if (ShapefileFactory.ExtractFishingTrackLine)
     {
         var sf = ShapefileFactory.FishingTrackLine();
         if (sf != null)
         {
             //return MapLayersHandler.AddLayer(sf, "Extracted fishng track", uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);
             return(MapLayersHandler.AddLayer(sf, "Extracted fishng track", uniqueLayer: true, layerKey: sf.Key));
         }
     }
     return(-1);
 }
Example #7
0
        public static int MapGPX(GPXFile gpxFile, out int shpIndex, out List <int> handles, bool showInMap = true)
        {
            shpIndex = -1;
            handles  = new List <int>();
            var utils       = new MapWinGIS.Utils();
            var shpfileName = "";

            if (showInMap)
            {
                if (gpxFile != null)
                {
                    Shapefile sf = null;
                    if (gpxFile.TrackCount > 0)
                    {
                        //sf = ShapefileFactory.TrackFromGPX(gpxFile,out shpIndex);
                        sf          = ShapefileFactory.TrackFromGPX(gpxFile, out handles);
                        shpfileName = "GPX tracks";
                    }
                    else if (gpxFile.WaypointCount > 0)
                    {
                        sf          = ShapefileFactory.NamedPointsFromGPX(gpxFile, out handles);
                        shpfileName = "GPX waypoints";
                    }
                    //MapWindowForm.Title =$"Number of layers:{MapControl.NumLayers}";
                    MapLayersHandler.AddLayer(sf, shpfileName, uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);

                    if (gpxFile.TrackCount > 0)
                    {
                        GPXTracksLayer = MapLayersHandler.CurrentMapLayer;
                    }
                    else if (gpxFile.WaypointCount > 0)
                    {
                        GPXWaypointsLayer = MapLayersHandler.CurrentMapLayer;
                    }

                    return(MapLayersHandler.CurrentMapLayer.Handle);
                }
                else
                {
                    return(-1);
                }
            }
            else
            {
                var ly = MapLayersHandler.get_MapLayer(gpxFile.FileName);
                MapLayersHandler.RemoveLayer(ly.Handle);
                return(-1);
            }
        }
 public static bool AddLGUBoundary(out string feedBack)
 {
     if (Directory.Exists($@"{LayersFolder}\LGUBoundary"))
     {
         var files = Directory.GetFiles($@"{LayersFolder}\LGUBoundary", "*.shp");
         if (files.Length >= 0)
         {
             var result = MapLayersHandler.FileOpenHandler(files[0], "LGU boundary", layerkey: "lgu_boundary");
             feedBack = result.errMsg;
             return(result.success);
         }
     }
     feedBack = "Folder for LGU boundary not found";
     return(false);
 }
        public static bool SetBoundaryShapefile()
        {
            var boundaryFolder = $@"{LayersFolder}\BSCBoundaryLine";

            if (Directory.Exists(boundaryFolder))
            {
                var boundarySF = Directory.GetFiles(boundaryFolder, "*.shp");
                if (boundarySF.Length == 1)
                {
                    MapLayersHandler.FileOpenHandler(boundarySF[0], "BSC boundary", layerkey: "bsc_boundary");
                    BSCBoundaryShapefile = (Shapefile)MapLayersHandler.CurrentMapLayer.LayerObject;
                    return(true);
                }
            }
            return(false);
        }
        public static bool AddExtractedTracksLayer(bool readFromDatabase = false)
        {
            bool proceed = true;

            if (readFromDatabase)
            {
                proceed = Entities.ExtractedFishingTrackViewModel.LoadTrackDataFromDatabase();
            }
            if (proceed && Entities.ExtractedFishingTrackViewModel.Count() > 0)
            {
                var sf = ShapefileFactory.FishingTrackLines();
                ExtractedTracksShapefile             = sf;
                sf.SelectionAppearance               = tkSelectionAppearance.saDrawingOptions;
                sf.DefaultDrawingOptions.LineColor   = new Utils().ColorByName(tkMapColor.Salmon);
                sf.SelectionDrawingOptions.LineWidth = 4f;
                return(MapLayersHandler.AddLayer(sf, "Fishing tracks", layerKey: sf.Key, uniqueLayer: true) >= 0);
            }
            return(false);
        }
Example #11
0
        public static int MapTripWaypoints(List <TripWaypoint> waypoints, out int shpIndex, out List <int> handles, GPS gps, string filename, bool showInMap = true)
        {
            shpIndex = -1;
            handles  = new List <int>();
            var utils       = new MapWinGIS.Utils();
            var shpfileName = "";

            if (showInMap)
            {
                if (waypoints.Count > 0)
                {
                    Shapefile sf = null;
                    sf          = ShapefileFactory.PointsFromWayPointList(waypoints, out handles, gps.DeviceName, filename);
                    shpfileName = "Trip waypoints";
                    int h = MapLayersHandler.AddLayer(sf, shpfileName, uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);
                }
            }
            return(MapLayersHandler.CurrentMapLayer.Handle);
        }
Example #12
0
        private void MaplayersHandler_LayerRemoved(MapLayersHandler s, LayerEventArg e)
        {
            int index = 0;

            while (index < MapLayerCollection.Count)
            {
                if (MapLayerCollection[index].Handle == e.LayerHandle)
                {
                    MapLayerCollection.RemoveAt(index);

                    if (LayerRemoved != null)
                    {
                        LayerEventArg lp = new LayerEventArg(e.LayerHandle, layerRemoved: true);
                        LayerRemoved(this, lp);
                    }
                    break;
                }
                index++;
            }
        }
Example #13
0
        /// <summary>
        /// Constructor and sets up map control events
        /// </summary>
        /// <param name="mapControl"></param>
        /// <param name="layersHandler"></param>
        public MapInterActionHandler(AxMap mapControl, MapLayersHandler layersHandler)
        {
            _mapLayersHandler = layersHandler;
            _mapLayersHandler.CurrentLayer += OnCurrentMapLayer;
            _axMap = mapControl;
            _axMap.MouseUpEvent      += OnMapMouseUp;
            _axMap.MouseDownEvent    += OnMapMouseDown;
            _axMap.SelectBoxFinal    += OnMapSelectBoxFinal;
            _axMap.MouseMoveEvent    += OnMapMouseMove;
            _axMap.DblClick          += OnMapDoubleClick;
            _axMap.SelectionChanged  += OnMapSelectionChanged;
            _axMap.SendMouseDown      = true;
            _axMap.SendMouseMove      = true;
            _axMap.SendSelectBoxFinal = true;
            _axMap.SendMouseUp        = true;
            EnableMapInteraction      = true;

            _axMap.MapCursor  = tkCursor.crsrArrow;
            _axMap.CursorMode = tkCursorMode.cmSelection;
        }
        public static int MapTrip(Trip trip, out int shpIndex, out List <int> handles, bool showInMap = true)
        {
            shpIndex = -1;
            handles  = new List <int>();
            var utils       = new MapWinGIS.Utils();
            var shpfileName = "";

            if (showInMap)
            {
                if (trip.Track.Waypoints.Count > 0)
                {
                    Shapefile   sf    = null;
                    List <Trip> trips = new List <Trip>();
                    trips.Add(trip);
                    sf          = ShapefileFactory.TrackFromTrip(trips, out handles);
                    shpfileName = "Trip tracks";
                    MapLayersHandler.AddLayer(sf, shpfileName, uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true);
                }
            }
            return(MapLayersHandler.CurrentMapLayer.Handle);
        }
        public static int MapWaypointsCTX(CTXFileSummaryView ctx, out List <int> handles)
        {
            handles = new List <int>();
            Shapefile sf = null;

            if (ctx.WaypointsForSet != null && ctx.WaypointsForSet > 0 ||
                ctx.WaypointsForHaul != null && ctx.WaypointsForHaul > 0)
            {
                sf = ShapefileFactory.WaypointsFromCTX(ctx, out handles);
            }

            if (sf != null)
            {
                return(MapLayersHandler.AddLayer(sf, "CTX waypoints", uniqueLayer: true, layerKey: sf.Key, rejectIfExisting: true));
                //return MapLayersHandler.CurrentMapLayer.Handle;
            }
            else
            {
                return(-1);
            }
        }
        private static string InsertCustomSettingToMapState(string xml)
        {
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            var mapstate = doc.GetElementsByTagName("MapState").Item(0);

            var          coastlineLayer = MapLayersHandler.get_MapLayer("Coastline");
            XmlAttribute attr           = doc.CreateAttribute("HasCoastline");

            attr.Value = coastlineLayer != null ? "1" : "0";
            mapstate.Attributes.SetNamedItem(attr);

            if (coastlineLayer != null)
            {
                attr       = doc.CreateAttribute("CoastlineVisible");
                attr.Value = coastlineLayer.Visible ? "1" : "0";
                mapstate.Attributes.SetNamedItem(attr);
            }
            return(doc.OuterXml);
        }
        public static bool AddBSCBoundaryLineShapefile(string inSF, out string feedBack)
        {
            var boundaryFolder = $@"{LayersFolder}\BSCBoundaryLine";

            if (File.Exists(inSF))
            {
                FileInfo fi = new FileInfo(inSF);
                if (fi.Extension == ".shp")
                {
                    if (!Directory.Exists(boundaryFolder))
                    {
                        Directory.CreateDirectory(boundaryFolder);
                    }


                    var sourceDirInfo = new DirectoryInfo(Path.GetDirectoryName(inSF));
                    var listFiles     = Directory.GetFiles(sourceDirInfo.FullName, $"{Path.GetFileNameWithoutExtension(fi.Name)}.*");

                    var files = Directory.GetFiles(boundaryFolder, "*.shp");
                    if (files.Length == 0)
                    {
                        foreach (var item in listFiles)
                        {
                            File.Copy(item, $@"{boundaryFolder}\{Path.GetFileName(item)}");
                        }
                        files = Directory.GetFiles(boundaryFolder, "*.shp");
                        var result = MapLayersHandler.FileOpenHandler(files[0], "BSC boundary", layerkey: "bsc_boundary");
                        BSCBoundaryShapefile = (Shapefile)MapLayersHandler.CurrentMapLayer.LayerObject;
                        feedBack             = result.errMsg;
                        return(result.success);
                    }
                }
            }



            feedBack = "Folder for LGU boundary not found";
            return(false);
        }
        public static bool AddShapefileLayer(string sf, out string feedBack)
        {
            if (File.Exists(sf))
            {
                FileInfo fi = new FileInfo(sf);
                if (fi.Extension == ".shp")
                {
                    DirectoryInfo dirInfo;
                    dirInfo = new DirectoryInfo(Path.GetDirectoryName(sf));
                    var listFiles    = Directory.GetFiles(dirInfo.FullName, $"{Path.GetFileNameWithoutExtension(fi.Name)}.*");
                    var proposedPath = $@"{LayersFolder}\{Path.GetFileNameWithoutExtension(fi.Name)}";
                    if (!Directory.Exists(proposedPath))
                    {
                        dirInfo = Directory.CreateDirectory(proposedPath);
                    }
                    else
                    {
                        dirInfo = new DirectoryInfo(proposedPath);
                    }
                    var files = Directory.GetFiles(dirInfo.FullName, "*.shp");
                    if (files.Length == 0)
                    {
                        foreach (var item in listFiles)
                        {
                            File.Copy(item, $@"{dirInfo.FullName}\{Path.GetFileName(item)}");
                        }
                    }
                    files = Directory.GetFiles(dirInfo.FullName, "*.shp");
                    var result = MapLayersHandler.FileOpenHandler(files[0], $"{fi.Name}", layerkey: $"{fi.Name}");
                    feedBack = result.errMsg;
                    return(result.success);
                }
            }

            feedBack = "Folder for LGU boundary not found";
            return(false);
        }
 public static void RemoveLayerByKey(string key)
 {
     MapLayersHandler?.RemoveLayerByKey(key);
 }
Example #20
0
 public MapLayer(int handle, string name, bool visible, bool visibleInLayersUI, MapLayersHandler parent)
 {
     Handle            = handle;
     Name              = name;
     Visible           = visible;
     VisibleInLayersUI = visibleInLayersUI;
     IsFishingGrid     = false;
     _parent           = parent;
     //ClassificationType = ClassificationType.None;
 }