Ejemplo n.º 1
0
        private void getPicture(GMapMarker marker)
        {
            MarkerTag  tag       = (MarkerTag)marker.Tag;
            Bitmap     bitmap    = ColorTable.getBitmap("Red", tag.Size);
            GMapMarker newMarker = new GMarkerGoogle(marker.Position, bitmap);

            newMarker.LocalPosition = marker.LocalPosition;
            newMarker.Offset        = marker.Offset;
            selectedMarkersOverlay.Markers.Add(newMarker);
            gMap.Overlays.Add(selectedMarkersOverlay);
            GMapMarker[] selectedMarkers = selectedMarkersOverlay.Markers.ToArray <GMapMarker>();
            mOverlayDict.Add("selected", selectedMarkers);

            if (tag.Path != null)
            {
                try
                {
                    if (pictureBox.Image != null)
                    {
                        pictureBox.Image.Dispose();
                    }
                    lbPhoto.Text     = tag.PhotoName;
                    pictureBox.Image = Image.FromFile(tag.Path);
                }
                catch (FileNotFoundException ex)
                {
                    lbPhoto.Text = ex.Message;
                }
            }
            else
            {
                string       bucket = "central-waikato";
                string       url    = "https://centralwaikato2019.s3.ap-southeast-2.amazonaws.com/" + tag.PhotoName + ".jpg";
                var          buffer = new byte[1024 * 8]; // 8k buffer.
                MemoryStream data   = new MemoryStream();
                int          offset = 0;
                try
                {
                    var request   = (HttpWebRequest)WebRequest.Create(url);
                    var response  = request.GetResponse();
                    int bytesRead = 0;
                    using (var responseStream = response.GetResponseStream())
                    {
                        while ((bytesRead = responseStream.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            data.Write(buffer, 0, bytesRead);
                            offset += bytesRead;
                        }
                    }
                    image = Image.FromStream(data);
                    data.Close();
                    lbPhoto.Text     = tag.ToString();
                    pictureBox.Image = image;
                }
                catch (WebException ex)
                {
                    lbPhoto.Text = ex.Message;
                }
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Called when layer is intially bulit when importing raw data (database/files etc)
 /// Iterates through the record dictionary and assigns a marker tag to each record which contains information
 /// about icon size, color etc. Then creates a new google marker adds bitmap, coordinate information and marker tag.
 /// </summary>
 /// <param name="overlay - the intial overlay that markers will be added to"></param>
 /// <returns>the GPOverlay containing the markers</returns>
 private GMapOverlay buildMarkers(GMapOverlay overlay, string color)
 {
     if (mRecordDict != null)
     {
         int    id     = 0;
         Bitmap bitmap = ColorTable.getBitmap(color, 4);
         foreach (KeyValuePair <string, Record> record in mRecordDict)
         {
             MarkerTag tag = new MarkerTag(color, id);
             tag.PhotoName = record.Value.PhotoName;
             tag.Path      = record.Value.Path;
             tag.Size      = 4;
             tag.PhotoName = record.Key;
             tag.Record    = record.Value;
             //tag.Bitmap = bitmap;
             Double     lat    = record.Value.Latitude;
             Double     lon    = record.Value.Longitude;
             GMapMarker marker = new GMarkerGoogle(new PointLatLng(lat, lon), bitmap);
             marker.Tag = tag;
             marker     = setToolTip(marker);
             overlay.Markers.Add(marker);
             id++;
         }
     }
     overlay.IsVisibile = true;
     return(overlay);
 }
Ejemplo n.º 3
0
        private GMapMarker setToolTip(GMapMarker marker)
        {
            MarkerTag tag = (MarkerTag)marker.Tag;

            marker.ToolTipText        = '\n' + tag.ToString();
            marker.ToolTip.Fill       = Brushes.White;
            marker.ToolTip.Foreground = Brushes.Black;
            marker.ToolTip.Stroke     = Pens.Black;
            //marker.ToolTip.TextPadding = new Size(20, 20);
            marker.ToolTipMode = MarkerTooltipMode.OnMouseOver;
            return(marker);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Clears marker selection from map
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void gMap_MouseClick(object sender, MouseEventArgs e)
 {
     if (mouseInBounds && e.Button == MouseButtons.Left)
     {
         if (currentMarker != null)
         {
             selectedMarkersOverlay.Clear();
             MarkerTag currentTag = (MarkerTag)currentMarker.Tag;
             currentTag.IsSelected = false;
             mOverlayDict.Remove("selected");
             currentMarker = null;
         }
     }
 }
Ejemplo n.º 5
0
        private void gMap_OnMarkerClick(GMapMarker marker, MouseEventArgs e)
        {
            MarkerTag tag = (MarkerTag)marker.Tag;

            if (currentMarker == null)
            {
                currentMarker = marker;
                MarkerTag currentTag = (MarkerTag)currentMarker.Tag;
                currentTag.IsSelected = true;
                getPicture(currentMarker);
            }
            else
            {
                if (tag == null)
                {
                    selectedMarkersOverlay.Clear();
                    gMap.Overlays.Remove(selectedMarkersOverlay);
                    mOverlayDict.Remove("selected");
                }
                else
                {
                    if (tag.IsSelected == true) //deselects marker
                    {
                        selectedMarkersOverlay.Clear();
                        gMap.Overlays.Remove(selectedMarkersOverlay);
                        mOverlayDict.Remove("selected");
                        tag.IsSelected = false;
                        currentMarker  = null;
                    }
                    else
                    {
                        selectedMarkersOverlay.Clear(); //selects a new marker
                        gMap.Overlays.Remove(selectedMarkersOverlay);
                        mOverlayDict.Remove("selected");
                        currentMarker = marker;
                        MarkerTag currentTag = (MarkerTag)currentMarker.Tag;
                        currentTag.IsSelected = true;
                        getPicture(currentMarker);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public async Task <GMapOverlay> readGeoTag(BlockingCollection <string> fileQueue, string folderPath, string layer, string color)
        {
            int mQueueSize = fileQueue.Count;

            string[]    files   = Directory.GetFiles(folderPath);
            GMapOverlay overlay = new GMapOverlay(layer);

            progressForm = new ProgressForm("Importing Photos...");
            progressForm.Show();
            progressForm.BringToFront();
            progressForm.cancel += cancelImport;
            cts = new CancellationTokenSource();
            var token = cts.Token;

            geoTagCount = 0;
            id          = 0;

            int    length = files.Length;
            Bitmap bitmap = ColorTable.getBitmap(color, 4);
            Dictionary <string, Record> recordDict = new Dictionary <string, Record>();
            var progressHandler1 = new Progress <int>(value =>
            {
                progressForm.ProgressValue = value;
                progressForm.Message       = "Import in progress, please wait... " + value.ToString() + "% completed\n" +
                                             geoTagCount + " of " + mQueueSize + " photos geotagged";
            });
            var progressValue = progressHandler1 as IProgress <int>;
            await Task.Factory.StartNew(() =>
            {
                try
                {
                    while (fileQueue.Count != 0)
                    {
                        if (token.IsCancellationRequested)
                        {
                            token.ThrowIfCancellationRequested();
                        }
                        Parallel.Invoke(
                            () =>
                        {
                            ThreadInfo threadInfo      = new ThreadInfo();
                            threadInfo.Length          = mQueueSize;
                            threadInfo.ProgressHandler = progressHandler1;
                            threadInfo.File            = fileQueue.Take();

                            Record r = null;
                            r        = readData(threadInfo);

                            MarkerTag tag     = new MarkerTag(color, id);
                            GMapMarker marker = new GMarkerGoogle(new PointLatLng(r.Latitude, r.Longitude), bitmap);
                            marker.Tag        = tag;
                            tag.Size          = 4;
                            tag.PhotoName     = r.PhotoName;
                            tag.Path          = Path.GetFullPath(r.Path);
                            overlay.Markers.Add(marker);
                        });
                    }
                }
                catch (OperationCanceledException)
                {
                    cts.Dispose();
                }
            }, cts.Token);

            progressForm.Close();
            return(overlay);
        }
Ejemplo n.º 7
0
        public void importShapeCallback(string path, string layer, Color color)
        {
            Bitmap      bitmap  = null;
            ShapeReader shape   = new ShapeReader(path);
            GMapOverlay overlay = new GMapOverlay(layer);

            gMap.Overlays.Add(overlay);
            shape.errorHandler += errorHandlerCallback;
            shape.read();
            ESRIShapeFile s = shape.getShape();

            if (s.ShapeType == 3 || s.ShapeType == 13)
            {
                GMapRoute   line_layer;
                PolyLineZ[] polyLines = s.PolyLineZ;
                foreach (PolyLineZ polyLine in polyLines)
                {
                    PointLatLng[] points = polyLine.points;
                    line_layer        = new GMapRoute(points, "lines"); //TODO get carriage number
                    line_layer.Stroke = new Pen(color, 1);
                    overlay.Routes.Add(line_layer);
                }
            }
            else if (s.ShapeType == 1)
            {
                ShapeFile.Point[] points = s.Point;
                bitmap = ColorTable.getBitmap(ColorTable.ColorCrossDict, color.Name, 4);
                int id = 0;
                foreach (ShapeFile.Point point in points)
                {
                    PointLatLng pointLatLng = new PointLatLng(point.y, point.x);
                    MarkerTag   tag         = new MarkerTag(color.Name, id);
                    tag.Dictionary = ColorTable.ColorCrossDict;
                    GMapMarker marker = new GMarkerGoogle(pointLatLng, bitmap);
                    marker.Tag = tag;
                    overlay.Markers.Add(marker);
                    id++;
                }
                GMapMarker[] markersArr = overlay.Markers.ToArray <GMapMarker>();
                mOverlayDict.Add(layer, markersArr);
            }
            else if (s.ShapeType == 8)
            {
                MultiPoint[] points = s.MultiPoint;
                bitmap = ColorTable.getBitmap(ColorTable.ColorCrossDict, color.Name, 4);
                int id = 0;
                foreach (MultiPoint point in points)
                {
                    PointLatLng[] pointsLatLng = point.points;
                    foreach (PointLatLng p in pointsLatLng)
                    {
                        MarkerTag tag = new MarkerTag(color.Name, id);
                        tag.Dictionary = ColorTable.ColorCrossDict;
                        GMapMarker marker = new GMarkerGoogle(p, bitmap);
                        marker.Tag = tag;
                        overlay.Markers.Add(marker);
                        id++;
                    }
                }
                GMapMarker[] markersArr = overlay.Markers.ToArray <GMapMarker>();
                mOverlayDict.Add(layer, markersArr);
            }
            addListItem(ColorTable.ColorCrossDict, overlay, color.Name);
            //if (bitmap != null)
            //{
            //    imageList.Images.Add(bitmap);
            //}
            //ListViewItem layerItem = new ListViewItem(overlay.Id, layerCount);
            //layerCount++;

            //layerItem.Text = overlay.Id;
            //layerItem.Checked = true;
            //mOverlay = overlay;
            //listLayers.SmallImageList = imageList;
            //listLayers.Items.Add(layerItem);
            ////addListItem(ColorTable.ColorCrossDict, overlay, color.Name);
            //overlay.IsVisibile = true;
            //mOverlay.IsVisibile = true;
            ////shape.readDBF();
        }
Ejemplo n.º 8
0
        private void rebuildMarkers(GMapOverlay overlay, int size)
        {
            overlay.Markers.Clear();
            try
            {
                GMapMarker[] markers = mOverlayDict[overlay.Id];
                MarkerTag    tag     = (MarkerTag)markers[0].Tag;
                if (tag == null)
                {
                    Bitmap       redBitmap  = ColorTable.getBitmap("Red", size);
                    GMapMarker[] redMarkers = mOverlayDict["selected"];
                    int          redCount   = redMarkers.Length;
                    for (int j = 0; j < redCount; j += 1)
                    {
                        GMapMarker newMarker = new GMarkerGoogle(redMarkers[j].Position, redBitmap);
                        overlay.Markers.Add(newMarker);
                    }
                }
                else
                {
                    markers = mOverlayDict[overlay.Id];
                    int count = markers.Length;
                    int step;
                    if (count > 5000)
                    {
                        step = getStep(size);
                    }
                    else
                    {
                        step = 1;
                    }
                    //Bitmap bitmap = ColorTable.getBitmap(tag.Color, size);

                    Dictionary <string, string> dict = tag.Dictionary;
                    Bitmap bitmap = null;
                    if (dict == null)
                    {
                        bitmap = ColorTable.getBitmap(tag.Color, size);
                    }
                    else
                    {
                        bitmap = ColorTable.getBitmap(dict, tag.Color, size);
                    }
                    for (int i = 0; i < count; i += step)
                    {
                        tag      = (MarkerTag)markers[i].Tag;
                        tag.Size = size;
                        GMapMarker newMarker = new GMarkerGoogle(markers[i].Position, bitmap);

                        if (markers[i].Tag != null)
                        {
                            newMarker.Tag = markers[i].Tag;
                        }
                        //setToolTip(newMarker);
                        overlay.Markers.Add(newMarker);
                    }
                }
            } catch (KeyNotFoundException ex)
            {
            }
        }