Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6108195
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:16:14+00:00 2026-05-23T14:16:14+00:00

I have 2 OpenLayers.LonLat objects, and I want to determine the distance in pixels

  • 0

I have 2 OpenLayers.LonLat objects, and I want to determine the distance in pixels for the current zoom between the 2. I’m using OpenLayers.Layer.getViewPortPxFromLonLat() to determine the x and y of the points and then subtract to see the difference between the 2, but the values that I get are very small for points that are 2000km apart.

Here is my code:

        var center_lonlat = new OpenLayers.LonLat(geometry.lon, geometry.lat);
        var center_px = layer.getViewPortPxFromLonLat(center_lonlat);

        var radius_m = parseFloat(feature.attributes["radius"]);
        var radius_lonlat = OpenLayers.Util.destinationVincenty(center_lonlat, 0, radius_m);
        var radius_px = layer.getViewPortPxFromLonLat(radius_lonlat);

        var radius = radius_px.y - center_px.y;

I’m trying here to draw a circle, giving that I receive a center point and a radius in meters. The LonLat object seems to be ok.

Am I doing something wrong ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:16:14+00:00Added an answer on May 23, 2026 at 2:16 pm

    I found the issue: destinationVincenty() need and returns coordinates in wgs84 where my map was using spherical mercator projection.

    I hope I got correctly the answer, because projections make me dizzy and never really understood them :(. I was looking in the console to the numbers for my coordinates and the coordinates from the map.getExtent() that is used to calculate the getViewPortPxFromLonLat() and I realised they are not in the right order of magnitude, and then it hit me.

    So, the code is now:

            var spherical_mercator = new OpenLayers.Projection("EPSG:900913");
            var wgs84 = new OpenLayers.Projection("EPSG:4326");
    
            var map = feature.layer.map;
            var geometry = feature.geometry;
            var center_lonlat = new OpenLayers.LonLat(geometry.y, geometry.x);
            var center_px = map.getViewPortPxFromLonLat(center_lonlat);
    
            var radius_m = parseFloat(feature.attributes["radius"]);
            var radius_lonlat = OpenLayers.Util.destinationVincenty(center_lonlat.clone().transform(spherical_mercator, wgs84), 0, radius_m).transform(wgs84, spherical_mercator);
            var radius_px = map.getViewPortPxFromLonLat(radius_lonlat);
    
            var radius = Math.abs(radius_px.y - center_px.y);
    

    Measured the circles with the OpenLayers.Control.ScaleLine, and the size is dead on 😀

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

TLDR : I have an Openlayers map with a layer called 'track' I want
I have an OpenLayers map with a TMS layer. For each zoom change, my
I have an application with a map-client using OpenLayers . I want to use
i'm using openlayers and geoExt. what i have is this: var options = {
I am using Openlayers to my application. i have succeeded in showing marker when
I would have an openlayers vector layer with features scattered all over the map.
I have an application using OpenLayers , Extjs and GeoExt . My application runs
I'm using Patrick Wied's OpenLayers Heatmap layer, but only for locations in the UK.
I have been looking for how to determine coordinates of the points which consist
I have created a small test page using Sencha Touch , OpenLayers and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.