Sweet. Glad I could help<div><br></div><div>Steve<br><br><div class="gmail_quote">2012/4/21 Imóveis Nacionais <span dir="ltr"><<a href="mailto:imoveisnacionais@gmail.com">imoveisnacionais@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
great, it works! just if(!firsttime) must be replaced by if(firsttime) ;-)<br>
thanks a lot<br>
alex<br>
<div><div></div><div class="h5"><br>
On 4/21/12, Steve Nelson <<a href="mailto:snelson@webapper.com">snelson@webapper.com</a>> wrote:<br>
> Dragging is a tiny bit more complex, but the logic is essentially the same.<br>
> This is totally untested, but maybe it'll get you going in the right<br>
> direction. I added some inline comments. Give it a whirl.<br>
><br>
><br>
> var firstClickMercator;<br>
> OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {<br>
><br>
> defaultHandlerOptions: {<br>
> 'single': true,<br>
> 'double': false,<br>
> 'pixelTolerance': 0,<br>
> 'stopSingle': false,<br>
> 'stopDouble': false<br>
> },<br>
> handleRightClicks:true,<br>
> initialize: function(options) {<br>
> this.handlerOptions = OpenLayers.Util.extend(<br>
> {}, this.defaultHandlerOptions<br>
> );<br>
> OpenLayers.Control.prototype.initialize.apply(<br>
> this, arguments<br>
> );<br>
> this.handler = new OpenLayers.Handler.Click(<br>
> this, {<br>
> 'click': this.singleClick<br>
> }, this.handlerOptions<br>
> );<br>
> },<br>
> singleClick: function(e) {<br>
> //You want to convert the xy coordinate in the e variable to a LonLat<br>
> var clickLonLat=map.getLonLatFromPixel(e.xy)<br>
> //Projections confuse the hell out of me. But what I've learned is you<br>
> probably want to transform to a Mercator projection<br>
> var clickLonLatMercator=clickLonLat.transform(map.getProjectionObject(),new<br>
> OpenLayers.Projection("EPSG:4326"));<br>
> if (!firstClick){<br>
> //If this is the first store it into a global variable:<br>
> firstClickMercator=clickLonLatMercator<br>
> }else{<br>
> //if the global variable firstClick already exists, calculate the distance<br>
> in KM<br>
> var<br>
> distanceInKM=OpenLayers.Util.distVincenty(firstClickMercator,clickLonLatMercator)<br>
> //you'll have to output it where you want, this should display the value<br>
> in the google chrome console:<br>
> console.log(distanceInKM)<br>
> //reset the global variable to null.<br>
> firstClick=null;<br>
> }<br>
> },<br>
><br>
> });<br>
><br>
><br>
> //Define the global map:<br>
> var map = new OpenLayers.Map("map")<br>
><br>
> //Add the click control to the map<br>
> var click = new OpenLayers.Control.Click();<br>
> map.addControl(click);<br>
> click.activate();<br>
><br>
><br>
><br>
> On Fri, Apr 20, 2012 at 10:41 AM, alexe100<br>
> <<a href="mailto:imoveisnacionais@gmail.com">imoveisnacionais@gmail.com</a>>wrote:<br>
><br>
>> Hi all , i am new here and in GEO* purposes...<br>
>> I am doing a web based application where i need to show some markers, that<br>
>> it aldready working.<br>
>> Now I need to give the oortunity to the user of drag a line on the map and<br>
>> while dragging see the distance in kms in a label box (html external obj)<br>
>> I saw already the openlayer example for distance but it has various<br>
>> options<br>
>> (and that make me confusing because i am a beginner). I did not found a<br>
>> (very) simple example doing this.<br>
>> Please, could you tell me how to do this. A littl example would be very<br>
>> appreciated.<br>
>><br>
>> Thanks a lot<br>
>><br>
>> Alex<br>
>><br>
>> --<br>
>> View this message in context:<br>
>> <a href="http://osgeo-org.1560.n6.nabble.com/Drag-Line-Distance-in-KMs-tp4902194p4902194.html" target="_blank">http://osgeo-org.1560.n6.nabble.com/Drag-Line-Distance-in-KMs-tp4902194p4902194.html</a><br>
>> Sent from the OpenLayers Users mailing list archive at Nabble.com.<br>
>> _______________________________________________<br>
>> Users mailing list<br>
>> <a href="mailto:Users@lists.osgeo.org">Users@lists.osgeo.org</a><br>
>> <a href="http://lists.osgeo.org/mailman/listinfo/openlayers-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/openlayers-users</a><br>
>><br>
><br>
</div></div></blockquote></div><br></div>