Show part of RadMap not the whole world

1 Answer 77 Views
Map
Ammar
Top achievements
Rank 1
Iron
Ammar asked on 28 Sep 2021, 04:41 PM | edited on 30 Sep 2021, 02:11 PM

Hi there,

Is it possible to display part of the world in a radMap by providing coordinates (X1, Y1) to (X2, Y2)  rather than showing the whole world  ?

 

example in the attached file. So the user should not be able to see more than the displayed area. User is able to zoom in but cannot zoom out to see more parts of the earth. Any suggestions?

 

1 Answer, 1 is accepted

Sort by
0
Stoyan
Telerik team
answered on 01 Oct 2021, 12:42 PM

Hello Ammar,

Currently we do not support this kind of functionality out of the box. 

However, I can offer the following - you can inherit RadMap and RadMapElement classes and override Zoom and Pan. This way you can control when to Zoom&Pan and when not to.

I am including and example, but you must define your own custom logic for skipping Pan and Zoom. Keep in mind that a Zoom operation will call Pan as well. PanOffset also depends on the zoom level. Furthermore since you are inheriting from RadMapElement you can override other useful methods as well. BringIntoView is an useful method to center and zoom your viewport in a certain rectangle. You can call this to set your initial map position and then use the overridden methods.

    public class RadMap2 : RadMap
    {
        protected override RadMapElement CreateMapElement()
        {
            return new RadMapElement2();
        }
    }

    public class RadMapElement2 : RadMapElement
    {
        public bool SkipPanZoom { get; set; }

        public override void Pan(long x, long y)
        {
            // This is an example condition
            // Keep in mind that the Pan values are different for different zoom levels and you will need to scale them accordingly
            if (SkipPanZoom && (x > -18200 || x < - 18800 || y < -11900 || y > -11600))
            {
                return;
            }

            base.Pan(x, y);
        }

        public override void Zoom(int zoomLevel, bool animate, Point center)
        {
            // This is an example zoom condition
            if (SkipPanZoom && zoomLevel <= 6)
            {
                return;
            }

            base.Zoom(zoomLevel, animate, center);
        }
    }

Now you can define your radMap1 with the new RadMap2 and use the BringIntoView as follows:

            RadMap2 radMap1 = new RadMap2();
            radMap1.BringIntoView(new Telerik.WinControls.UI.Map.RectangleG());
            (radMap1.MapElement as RadMapElement2).SkipPanZoom = true;

Here you will have to define your specific RectangleG. SkipPanZoom property is just for illustration purposes,m you can have your own custom logic. The same applies for the logic in the overridden Pan and Zoom methods.

I hope this will help you with your task.

Kind Regards,
Stoyan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Map
Asked by
Ammar
Top achievements
Rank 1
Iron
Answers by
Stoyan
Telerik team
Share this question
or