I am stuck how to convert lat,long to bbox using WGS-84. Is there a formula or function code you could share.
e.g. lon=-79.80617638166511
lat=43.17565342984143
bbox?
<SPAN class=""> </SPAN><SPAN class=""></SPAN>
Raju,
My code snippet above is for a map click function where the event object passed is the map click event.
Here is a function to convert a lat lon to an extent.
<SPAN class="keyword token">function</SPAN> <SPAN class="token function">onSelDrawEnd</SPAN><SPAN class="punctuation token">(</SPAN>lat<SPAN class="punctuation token">,</SPAN> lon<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> mapPnt <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Point</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="token function">parseFloat</SPAN><SPAN class="punctuation token">(</SPAN>lon<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="token function">parseFloat</SPAN><SPAN class="punctuation token">(</SPAN>lat<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> scrPnt <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">toScreen</SPAN><SPAN class="punctuation token">(</SPAN>mapPnt<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//Expand the point by 5 pixels</SPAN> <SPAN class="keyword token">var</SPAN> xMin <SPAN class="operator token">=</SPAN> scrPnt <SPAN class="punctuation token">.</SPAN>x <SPAN class="operator token">-</SPAN> <SPAN class="number token">2.5</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//value in pixels</SPAN> <SPAN class="keyword token">var</SPAN> yMin <SPAN class="operator token">=</SPAN> scrPnt <SPAN class="punctuation token">.</SPAN>y <SPAN class="operator token">-</SPAN> <SPAN class="number token">2.5</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//value in pixels</SPAN> <SPAN class="keyword token">var</SPAN> xMax <SPAN class="operator token">=</SPAN> scrPnt <SPAN class="punctuation token">.</SPAN>x <SPAN class="operator token">+</SPAN> <SPAN class="number token">2.5</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//value in pixels</SPAN> <SPAN class="keyword token">var</SPAN> yMax <SPAN class="operator token">=</SPAN> scrPnt <SPAN class="punctuation token">.</SPAN>y <SPAN class="operator token">+</SPAN> <SPAN class="number token">2.5</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//value in pixels</SPAN> <SPAN class="keyword token">var</SPAN> mp1 <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">toMap</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Point</SPAN><SPAN class="punctuation token">(</SPAN>xMin<SPAN class="punctuation token">,</SPAN> yMin<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> mp2 <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN><SPAN class="token function">toMap</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Point</SPAN><SPAN class="punctuation token">(</SPAN>xMax<SPAN class="punctuation token">,</SPAN> yMax<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">var</SPAN> ext <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">Extent</SPAN><SPAN class="punctuation token">(</SPAN>mp1<SPAN class="punctuation token">.</SPAN>x<SPAN class="punctuation token">,</SPAN> mp1<SPAN class="punctuation token">.</SPAN>y<SPAN class="punctuation token">,</SPAN> mp2<SPAN class="punctuation token">.</SPAN>x<SPAN class="punctuation token">,</SPAN> mp2<SPAN class="punctuation token">.</SPAN>y<SPAN class="punctuation token">,</SPAN> <SPAN class="keyword token">new</SPAN> <SPAN class="token class-name">SpatialReference</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN> wkid<SPAN class="punctuation token">:</SPAN><SPAN class="number token">4326</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">return</SPAN> Polygon<SPAN class="punctuation token">.</SPAN><SPAN class="token function">fromExtent</SPAN><SPAN class="punctuation token">(</SPAN>ext<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
You working in 3.x or 4.x?
Thanks Rob for your response. Could you kindly provide an example for set of pixels toScreen and toMap. I have a deadline to meet.
Normally I would be adding/subtracting values with a set number of pixels using toScreen and toMap.
Thanks Rob for always being helpful. I am using simple math to get bbox from lat,long. It is not accurate for closest zoom scale.
var minxx = lon - 0.08999; var maxxx = lon + 0.08999; var minyy = lat - 0.08999; var maxyy = lat - 0.08999;
console.log("weblink/bbox?" + "xmin=" + minxx + "&ymin=" + minyy + "&xmax=" + maxxx + "&ymax=" + maxyy).
I have WGS-84 projection. Do I have to add condition for each scale. e.g.
If (scale =11)
elseif (scale =19)
var minxx = lon - ??; var maxxx = lon + ??; var minyy = lat - ??; var maxyy = lat - ??;
To get a bounding box from a single point you just need to do some math to add and subtract for that point to get the minx, miny, maxx and maxy for the extent class constructor.
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.