I have done something like that but it didn&#39;t fill in any form component... Check it out: <a href="http://pastebin.com/m6336e5e6">http://pastebin.com/m6336e5e6</a><br>If you want to use it, you will have to replace the alert with the code that fills in your form.<br>

<br>Btw, all projections on this example are EPSG:4326.<br><br><br><div class="gmail_quote">On Fri, Nov 13, 2009 at 4:56 PM, Scott Lewis <span dir="ltr">&lt;<a href="mailto:scott.lewis@nsidc.org">scott.lewis@nsidc.org</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Ah, sorry about that, I misunderstood the problem you were having!<br>
<div><div></div><div class="h5"><br>
J. Cliff Dyer wrote:<br>
&gt; Thanks.  That&#39;s definitely a cleaner setup, but it didn&#39;t really solve<br>
&gt; the problem I was having.  Before the box would look like it was being<br>
&gt; drawn properly, but then the persistent copy would be vertically offset.<br>
&gt; Now it&#39;s offset from the time I start drawing.  Which is an improvement,<br>
&gt; because at least it will be easier for users to draw the box they want.<br>
&gt; Here&#39;s a screenshot to show what I mean:<br>
&gt;<br>
&gt; <a href="http://imgur.com/5cJ4H" target="_blank">http://imgur.com/5cJ4H</a><br>
&gt;<br>
&gt; The Box was drawn exactly from Cape Fear to Cape Hatteras, marked with<br>
&gt; little black dots on the screenshot.  However, the box itself starts<br>
&gt; drawing a bit above the location of the cursor.  It seems the further I<br>
&gt; get from the top of the display, the further displaced the box is.  It<br>
&gt; is impossible to get closer than ~2cm from the bottom of the map.  There<br>
&gt; also seems to be a very slight horizontal displacement.<br>
&gt;<br>
&gt; Any thoughts on what might cause this displacement?  At this point, no<br>
&gt; transformation is being done--at least not in any of my code.<br>
&gt;<br>
&gt; Cheers,<br>
&gt; Cliff<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Fri, 2009-11-13 at 09:58 -0700, Scott Lewis wrote:<br>
&gt;&gt; I did something like this using one of the examples on the OpenLayers<br>
&gt;&gt; site, modified slightly.  Here&#39;s what I used:<br>
&gt;&gt;<br>
&gt;&gt; boxControl = new OpenLayers.Control();<br>
&gt;&gt; OpenLayers.Util.extend(boxControl, {<br>
&gt;&gt;    draw: function() {<br>
&gt;&gt;      this.box = new OpenLayers.Handler.RegularPolygon(boxControl,<br>
&gt;&gt; {&quot;done&quot;: this.notice}, {sides:4, irregular:true, persist:true});<br>
&gt;&gt;      this.box.activate();<br>
&gt;&gt;    },<br>
&gt;&gt;<br>
&gt;&gt;    notice: function(geom) {<br>
&gt;&gt;      // whatever you want it to do after the box has been drawn<br>
&gt;&gt;    }<br>
&gt;&gt; });<br>
&gt;&gt;<br>
&gt;&gt; // then add the boxControl to the map<br>
&gt;&gt;<br>
&gt;&gt; This works pretty nicely.  Note that &quot;geom&quot; will be in the same<br>
&gt;&gt; projection as the map, so if you want the output to be in another<br>
&gt;&gt; projection (like a latitude/longitude display) you will have to go<br>
&gt;&gt; through the geometry and transform the points.  Also, you may have to go<br>
&gt;&gt; through the geometry to determine which point is which (it doesn&#39;t<br>
&gt;&gt; always start with the upper-left corner, and it&#39;s not always clockwise<br>
&gt;&gt; or counter-clockwise).  If interested, I can post some of the functions<br>
&gt;&gt; I do for that.<br>
&gt;&gt;<br>
&gt;&gt; I hope this helps,<br>
&gt;&gt;<br>
&gt;&gt; Scott Lewis<br>
&gt;&gt; NSIDC<br>
&gt;&gt;<br>
&gt;&gt; J. Cliff Dyer wrote:<br>
&gt;&gt;&gt; I&#39;m trying to draw a box on a map, have it persist until another box<br>
&gt;&gt;&gt; gets drawn, and submit the coordinates of the box to a form.  I&#39;m doing<br>
&gt;&gt;&gt; this to allow the user to search for objects within a given area.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; I&#39;m doing this by using an OpenLayers.Handler.Box tool in a custom<br>
&gt;&gt;&gt; OpenLayers.Control, which then uses to the &quot;done&quot; callback of the draw<br>
&gt;&gt;&gt; method to create (or recreate) an OpenLayers.Feature.Vector and populate<br>
&gt;&gt;&gt; (or repopulate) a search form.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; My immediate problem is that the persistent box is not in quite the same<br>
&gt;&gt;&gt; location as the box the user just drew.  I suspect this has something to<br>
&gt;&gt;&gt; do with projections, but since I never explicitly set projections, I&#39;m<br>
&gt;&gt;&gt; not sure where the error sneaked in.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; More generally, I&#39;m not sure I&#39;m taking the optimal route from the<br>
&gt;&gt;&gt; bounds passed to the callback to the Vector feature.  Currently, I do<br>
&gt;&gt;&gt; the following:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;   1) Take the incoming OpenLayers.Bounds object,<br>
&gt;&gt;&gt;   2) Get an OpenLayers.Pixel from the the corners<br>
&gt;&gt;&gt;   3) Get the coordinates of each pixel using map.getLonLatFromPixel<br>
&gt;&gt;&gt;   4) Create a new OpenLayers.Bounds<br>
&gt;&gt;&gt;   5) Extend it to my new coordinates<br>
&gt;&gt;&gt;   6) Convert it to a geometry<br>
&gt;&gt;&gt;   7) Convert it to an OpenLayers.Feature.Vector<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Then I take the coordinates from step 3) and populate a form with them,<br>
&gt;&gt;&gt; which I then submit to my application server side.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; The code for this is pasted here: <a href="http://pastebin.com/m300c24a5" target="_blank">http://pastebin.com/m300c24a5</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Any pointers on how to do this more cleanly would be much appreciated.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Cheers,<br>
&gt;&gt;&gt; Cliff<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; _______________________________________________<br>
&gt;&gt;&gt; Users mailing list<br>
&gt;&gt;&gt; <a href="mailto:Users@openlayers.org">Users@openlayers.org</a><br>
&gt;&gt;&gt; <a href="http://openlayers.org/mailman/listinfo/users" target="_blank">http://openlayers.org/mailman/listinfo/users</a><br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; Users mailing list<br>
&gt; <a href="mailto:Users@openlayers.org">Users@openlayers.org</a><br>
&gt; <a href="http://openlayers.org/mailman/listinfo/users" target="_blank">http://openlayers.org/mailman/listinfo/users</a><br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@openlayers.org">Users@openlayers.org</a><br>
<a href="http://openlayers.org/mailman/listinfo/users" target="_blank">http://openlayers.org/mailman/listinfo/users</a><br>
</div></div></blockquote></div><br>