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