This is a migrated thread and some comments may be shown as answers.

Map Coordinates

2 Answers 164 Views
Map
This is a migrated thread and some comments may be shown as answers.
Marcello
Top achievements
Rank 1
Iron
Marcello asked on 09 Feb 2021, 04:10 PM

Hi,

I have some doubts about coordinates.

How to get pixel cordinates of a lat, lng point?

I tried locationToView and locationToLayer without success ..

Here a script example:

 

$("#map").kendoMap({
            zoom: 3,
            center: [45, 10],
            layers: [{
                type: "tile",
                urlTemplate: "http://a.tile.openstreetmap.org/#= zoom #/#= x #/#= y #.png",
                attribution: "© OpenStreetMap"
            }],
            markers: [{
                location: [45, 10],
                shape: "pinTarget"
            }],
            pan: function (e) {
                 
                console.log('What are now marker pixel coordinates?')
                 
            }
        });

2 Answers, 1 is accepted

Sort by
0
Georgi
Telerik team
answered on 11 Feb 2021, 11:49 AM

Hello Marcello,

The markers are absolute positioned, thus, you can get their top/left values directly from their html element.

e.g.

//top
markerElement.style.top

//left

markerElement.style.left

The above will give you the coordinates in pixels of the marker relatively to the layer's element top left corner.

I hope this helps.

Regards,
Georgi
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Marcello
Top achievements
Rank 1
Iron
answered on 11 Feb 2021, 11:55 AM

Thanks Georgi,

but the marker element was only an example.

I found an answer by my self:

var loc = map.locationToView([lat, lng]);
loc.x -= map.scroller.scrollLeft;
loc.y -= map.scroller.scrollTop;

marc.

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