Eric, you're faster. Catched them all while I tested...<br><br>Esteban, esta es la función init() resultante, por si la quieres aprovechar:<br><br> function init() {<br> var g = new OpenLayers.Projection("EPSG:4326");<br>
var p = new OpenLayers.Projection("EPSG:900913");<br><br> var options = {<br> projection: p,<br> displayProjection: g,<br> units: "m",<br>
maxResolution: 156543.0339,<br> maxExtent: new OpenLayers.Bounds(-20037508, -20037508,<br> 20037508, 20037508.34)<br> };<br> map = new OpenLayers.Map('map', options);<br>
<br> var layergoogle = new OpenLayers.Layer.Google("Google Normal",<br> {type: G_NORMAL_MAP, 'sphericalMercator': true});<br> var vectores = new OpenLayers.Layer.Vector("Vector Features");<br>
map.addLayers([layergoogle, vectores]);<br><br> //line near Barcelona, spain, for example<br> var p1 = new OpenLayers.Geometry.Point(2, 41);<br> var p2 = new OpenLayers.Geometry.Point(41, 2);<br>
var lineString = new OpenLayers.Geometry.LineString([p1,p2]).transform(g, p);<br> var lineFeature = new OpenLayers.Feature.Vector(lineString, null, null); <br> vectores.addFeatures([lineFeature]);<br>
<br> var lonLat = new OpenLayers.LonLat(2, 41).transform(g, p);<br> map.setCenter(lonLat, 7);<br> }<br><br><br><div class="gmail_quote">2008/6/6 Eric Lemoine <<a href="mailto:eric.c2c@gmail.com">eric.c2c@gmail.com</a>>:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">2008/6/6 Esteban olm <<a href="mailto:esteban.olm@gmail.com">esteban.olm@gmail.com</a>>:<br>
<div class="Ih2E3d">> Hello,<br>
><br>
> I need help! I can not understand why I can not see a line in openlayers.<br>
> If I don't use projections, I can see it, but then the line is not properly<br>
> drawn in Firefox (but yes in Explorer).<br>
> I know that problem is a projection problem (I have read a lot in Internet),<br>
> I know Google use Mercator, but I don't know how to solve it.<br>
><br>
> Please help !! There is something I can not find.<br>
> Here is the entire HTML page from what I think is the best approximation<br>
> (but it doesn't draw the line):<br>
<br>
</div>See my comments in the code.<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
<br>
> ----------------------------------------------------------------------------------------------------------------------<br>
> <html><br>
> <head><br>
> <title>prueba</title><br>
><br>
> <!-- this google key is fo <a href="HTTP://LOCALHOST" target="_blank">HTTP://LOCALHOST</a>, so it should go in your PC<br>
> --><br>
> <script<br>
> src="<a href="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAAdktgbP3W_jzENycyyxYmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQAmpwRv0-s77497-2GnWVaa_ulwA" target="_blank">http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAAdktgbP3W_jzENycyyxYmhT2yXp_ZAY8_ufC3CFXhHIE1NvwkxQAmpwRv0-s77497-2GnWVaa_ulwA</a>"<br>
> type="text/javascript"></script><br>
> <script src="<a href="http://openlayers.org/dev/OpenLayers.js" target="_blank">http://openlayers.org/dev/OpenLayers.js</a>"></script><br>
><br>
> <script type="text/javascript"><br>
> var lat=42.508;<br>
> var lon=1.118;<br>
> var map; //complex object of type OpenLayers.Map<br>
><br>
> function init() {<br>
><br>
> //Initialise the 'map' object<br>
> map = new OpenLayers.Map ("map", {<br>
> controls:[<br>
> new OpenLayers.Control.Navigation(),<br>
> new OpenLayers.Control.PanZoomBar(),<br>
> new OpenLayers.Control.Attribution()],<br>
> maxExtent: new<br>
> OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34),<br>
> maxResolution: 156543.0399,<br>
> units: 'm',<br>
> projection: new OpenLayers.Projection("EPSG:900913")<br>
> } );<br>
> var layergoogle = new OpenLayers.Layer.Google("Google Normal",<br>
> { type: G_NORMAL_MAP },<br>
> {<br>
> 'sphericalMercator': true,<br>
> 'projection': new OpenLayers.Projection("EPSG:900913")<br>
> }<br>
<br>
</div></div>Place the 'type' and 'sphericalMercator' properties in the same<br>
object. Remove the 'projection' property.<br>
<br>
{<br>
'type': G_NORMAL_MAP,<br>
'sphericalMercator': true<br>
}<br>
<div class="Ih2E3d"><br>
> );<br>
> var vectores = new OpenLayers.Layer.Vector ("Vector Features",<br>
> { 'projection': new OpenLayers.Projection("EPSG:4326"),<br>
> 'displayProjection': new<br>
> OpenLayers.Projection("EPSG:900913")<br>
> }<br>
> );<br>
<br>
</div>You do not need any options for the vector layer:<br>
<br>
var vectores = new OpenLayers.Layer.Vector ("Vector Features");<br>
<div class="Ih2E3d"><br>
<br>
> map.addLayer(layergoogle);<br>
> map.addLayer(vectores);<br>
><br>
> //line near Barcelona, spain, for example<br>
> var p1 = new OpenLayers.Geometry.Point(2, 41);<br>
> var p2 = new OpenLayers.Geometry.Point(41, 2);<br>
> var points = [p1,p2];<br>
> var lineString = new OpenLayers.Geometry.LineString(points);<br>
<br>
</div>Reproject your line string before creating the feature with it:<br>
<br>
lineString.transform(<br>
<div class="Ih2E3d"> new OpenLayers.Projection("EPSG:4326"),<br>
</div><div class="Ih2E3d"> new OpenLayers.Projection("EPSG:900913")<br>
);<br>
<br>
</div><div class="Ih2E3d">> var lineFeature = new OpenLayers.Feature.Vector(lineString,<br>
> null, null);<br>
> features = [lineFeature];<br>
> vectores.addFeatures( [features] );<br>
><br>
> var lonLat = new OpenLayers.LonLat(2, 41)<br>
<br>
</div>Either pass mercator coordinates to the LonLat constructor or<br>
reproject it before passing to setCenter:<br>
<br>
lonLat.transform(<br>
<div class="Ih2E3d"> new OpenLayers.Projection("EPSG:4326"),<br>
</div><div class="Ih2E3d"> new OpenLayers.Projection("EPSG:900913")<br>
);<br>
<br>
</div><div class="Ih2E3d">> map.setCenter(lonLat, 7);<br>
> }<br>
> </script><br>
> </head><br>
> <body onload="init();"><br>
> <div style="width:500px; height:300px" id="map"></div><br>
> </body><br>
> </html><br>
<br>
</div>Hope this helps,<br>
<br>
Note that I haven't tested anything so there might still be errors lurking.<br>
<font color="#888888">--<br>
Eric<br>
_______________________________________________<br>
Dev mailing list<br>
<a href="mailto:Dev@openlayers.org">Dev@openlayers.org</a><br>
<a href="http://openlayers.org/mailman/listinfo/dev" target="_blank">http://openlayers.org/mailman/listinfo/dev</a><br>
</font></blockquote></div><br>