New to the forum. I also posted this question on Stackoverflow, not sure it is the same forum.

I am trying to build a Vt of 360 degree panopictures with OSM map using Leaflet.

I would need a function which, given the LatLng coord of a point, returns the pixel coordinates x, y of that point relative to the origin pixel (to the top left corner of the map container) when moving (i.e panning/dragging) the map and when zooming the map. For example: when the map does not move, x=30, when panning the map x changes following the actual map move accordingly.

  • 1
    Sometimes documentation can be helpful. See latLngToLayerPoint(<LatLng> latlng) method in leafletjs.com/reference-1.5.0.html#map – TomazicM Aug 28 '19 at 14:20
  • I tried that function but it returns x, y coords of a LatLng point at a fixed view, i.e. when panning the map the x, y values remain the same. I would need a function which returns x, y coord of the point as the map moves. – scuola Aug 28 '19 at 17:02
  • Did you read x,y coordinates within event function for map move event? – TomazicM Aug 28 '19 at 17:13
  • I used the function with map.on 'move' event then I "pass" x, y values to layer in the xml file generated by the Krpano viewer but id does not works i.e. the spot remain in the same position moving the map. When I use map.latLngToContainerPoint() and map.on 'move' instead, it works: I cannot figure it out why.... – scuola Aug 28 '19 at 18:27
  • You are right, it looks like I should adhere to my own advice of reading documentation carefully. latLngToLayerPoint method gives pixel coordinates relative to layer origin pixel (and this of course does not change). latLngToContainerPoint method gives pixel oordinates relative to map container, which does change when map is panned. – TomazicM Aug 29 '19 at 18:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.