Quantcast
Channel: GMap.NET - Great Maps for Windows Forms & Presentation
Viewing all 3384 articles
Browse latest View live

New Post: Smooth Movement

$
0
0
I want to create a smooth animated drag effect just like Google Maps (if you know what I am talking about).

I warped GMapControl class and successfully implemented smooth zoom by overriding the OnMouseWheel method and applying a DoubleAnimation using exponential easing on the Zoom property every time the wheel is turned.

In order to implement smooth drag like Google I created MapOffset property, which on every value change will call Offset function from the MapControl class with the new offset point. Creating the MapOffset granted me the ability to animate map movement.

__The problem is that Offset function only accept integer values which is not accurate enough for making smooth animations.__

Is there another way to create a smooth drag?
publicclass SmoothMap : GMapControl
{
        publicstaticreadonly DependencyProperty MapOffsetProperty = DependencyProperty.Register("MapOffset", 
                     typeof(Point), typeof(SmoothMap), new FrameworkPropertyMetadata(new  
                     PropertyChangedCallback(OnM_OffsetPropertyChanged)));

        private Storyboard movementSb;
        private PointAnimation movementAnimation;

        public SmoothMap()
        {
            movementSb = new Storyboard();
            movementAnimation = new PointAnimation();
            movementAnimation.From = new Point(0, 0);
            movementAnimation.Duration = new Duration(TimeSpan.FromSeconds(1));
            movementAnimation.FillBehavior = FillBehavior.HoldEnd;
            ExponentialEase ease = new ExponentialEase();
            ease.EasingMode = EasingMode.EaseOut; 
            ease.Exponent = 6;
            movementAnimation.EasingFunction = ease;

            movementSb.Children.Add(movementAnimation);

            Storyboard.SetTarget(movementAnimation, this);
            Storyboard.SetTargetProperty(movementAnimation, new PropertyPath(MapOffsetProperty));
         }

        privatestaticvoid OnMapOffsetPropertyChanged(DependencyObject source,                                                                                                      DependencyPropertyChangedEventArgs e)
        {
            SmoothMap sm = source as SmoothMap;
            Point p = (Point)e.NewValue;

            sm.Offset((int)p.X, (int)p.Y);
        }

        privateconstint OffsetConstant = 3;
        bool isDragging = false;
        Queue<Tuple<Point, int>> lastPos = new Queue<Tuple<Point, int>>();
        protectedoverridevoid OnMouseMove(System.Windows.Input.MouseEventArgs e)
        {
            base.OnMouseMove(e);

            if(e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
            {
                isDragging = true;
                lastPos.Enqueue(new Tuple<Point, int>(e.GetPosition(this), e.Timestamp));
                if (lastPos.Count == 10)
                {
                    lastPos.Dequeue();
                }
            }
            elseif(e.LeftButton == System.Windows.Input.MouseButtonState.Released && isDragging)
            {
                Tuple<Point, int> first = lastPos.First();
                Tuple<Point, int> last = lastPos.Last();

                if (e.Timestamp - last.Item2 < 200)
                {
                    long deltaT = last.Item2 - first.Item2;
                    double deltaX = (last.Item1.X - first.Item1.X);
                    double deltaY = (last.Item1.Y - first.Item1.Y);

                    double velocity_X = deltaX / (double)deltaT;
                    double velocity_Y = deltaY / (double)deltaT;

                    movementSb.Stop();

                    Debug.WriteLine("To: " + velocity_X);

                    movementAnimation.To = new Point(velocity_X * OffsetConstant , velocity_Y * OffsetConstant );

                    lastPos.Clear();
                    isDragging = false;

                    movementSb.Begin();
                }   
            }
        }
}
What basically I am doing in order to have a smooth drag when the user releases the mouse, is saving the last mouse movement by saving the last 10 move messages. After that I calculate the speed of the movement and using the speed in the animation.

New Post: Route travel time for Open StreetMap provider

$
0
0
Hi,
Unlike the Google Maps provider, there is no travel time returned from the Open StreetMap routing provider.

Can this be added in, perhaps as part of the Name property as in Google Maps provider?

The traveltime data is returned via kml, and I have managed to add it to the Tag property in OpenStreetMapProvider.cs, e.g.:

//kml/Document/traveltime
var timeNode = xmldoc.SelectSingleNode("/sm:kml/sm:Document/sm:traveltime", xmlnsManager);
Tag = timeNode.InnerText;

Thanks,
Jim.

New Post: Polygon with inner polygons

$
0
0
Hi,

What should graphicsPath be?

Br
Bjorn Kallin

New Post: markers rotation-bearing

$
0
0
Hi,
Sorry to reopen this thread....but iam new to this GMap....can anyone answer me......I tried the radioman code....but null exception at overlay.control.bearing is coming. how to overcome that....
thanks in advance...

New Post: Data binding the visibility of Markers

$
0
0
In my WPF MVVM application, I'd like to databind the visibility of markers.

Right now, in my CustomerViewModel, I'm creating a ObservableCollections of MarkerViewModels on the fly, like
        /// <summary>
        /// Gets the g map markers.
        /// </summary>
        public ObservableCollection<GMapMarker> GMapMarkers {
            get {
                // if this.gMapMarkers is null generate the markers
                return new ObservableCollection<GMapMarker>(this.Markers.Where(m => !m.IsHidden).Select(m => m.GmMarker));
            }
        }
A property of my MarkerViewModel is IsHidden, which determines the visibly and is queried using LINQ. GmMarker is the actual GmapMarker.

GMapMarkers is bound to the GMapControl's ItemsSource.

While this works exactly as supposed it causes a redraw of every marker when in fact just a single marker should be hidden, which seriously degrades performance when a huge list of markers is displayed.

Is there a way to show/hide markers in a more MVVM-ish way using data binding?

Thanks,
Tom

New Post: Force image redraw

$
0
0
Hello,

I was able to add an image as a marker to my map following the Cloud.Demo code. The problem is when I want to change the image the new image is not redrawn until I zoom the map. I have tried to use:
newgmap.Invalidate()
newgmap.Refresh()
newgmap.Update()
None of these will actually redraw the image. The only way I can get the image to appear properly is to zoom. I've looked at the source code for zoom and there are internal force render functions which are not accessible. The problem with zoom is that if I wanted to change the image at a very fast pace (> 1 times a second) it flickers the map. I do not want that effect. Is there a function that forces the image to redraw so that it will appear properly on the map?

Thank you.

New Post: Force image redraw

$
0
0
map.Refresh() is instant, map.Invalidate() is async

New Post: Google Maps change?

$
0
0
Hello,

I've been using the GMAP.net solution for quite some time now, and it seems that as of this morning, every project in which we used GMAP.net has started throwing 404 errors. Here is an example of a URL that throws an error:

http://maps.google.com/maps?f=q&output=dragdir&doflg=p&hl=en&mra=ls&q=&saddr=@40.637666,-73.947676&daddr=@40.655961,-73.950774

If your try to navigate to this URL, you'll receive a 404... unless you remove the output=dragdir parameter.

Does anyone know if google recently removed the ability to receive json in this manner? Are there any plans for a work around here if so?

Thanks for any help anyone can give me.

Scott

New Post: Google Maps change?

$
0
0
Good morning

Just wanted to put our voice to this issue also.

We're experiencing exactly the same problem as Scott.

We call GMaps.Instance.GetRouteBetweenPoints.

This problem has crippled our app.

Thanks

Dean

New Post: Google Maps change?

$
0
0
i guess you need to switch to direction api: GMapProviders.GoogleMap.GetDirections

New Post: Google Maps change?

New Post: Running off cached info

$
0
0
What if I actually had like 3TB of cached map data? How would I run GMap.NET completely off of that?

New Post: Offline Maps, Labview

$
0
0
Hi

I am completely new to mapping and wondered if someone could advise me if I am on the right track. I have to plot a track on a map using historical gps co-ordinates and without depending on an internet connection at replay time. We use Labview and one discussion pointed to this forum. I have no background in .NET but think that Labview can be integrated in some manner with .NET.

Am I in the right area for offline mapping or should I be looking elsewhere. I have read through the Wikia documentation and searched for a starting point.

Any help would be appreciated. Thanks

Robert

New Post: Running off cached info

$
0
0
Also, how is the program reading from the cache provider? Is there code somewhere I need to include? How does it know where the cache is and where to put the read in data?

New Post: Running off cached info

$
0
0
Ok last question. Is there a tutorial somewhere on using the existing cache providers?

New Post: Problem with Bing Maps Tiles

$
0
0
Well this is weird... I encountered the problem when I was on my laptop in a different network.
At home I tried the Hot Build: Application GMap.NET Build-76d7772bd36e-20150519.zip uploaded May 19 and now both is working.
Any ideas why this was happening?

New Post: Running off cached info

New Post: Problem with Bing Maps Tiles

$
0
0
it's possible network timeout, you can increase it: GMapProvider.TimeoutMs = 10 * 1000; //10s

New Post: Offline Maps, Labview

$
0
0
some people managed to integrate it in labview, never tried myself, but it works

New Post: GetDirections Usage Limit

Viewing all 3384 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>