[OpenLayers-Users] Help with OpenLayer + Google Maps

hekuran S. Doli hekuran.doli at logisticsplus-ks.com
Mon Nov 16 13:19:12 EST 2009


Thank you very much Pedro, I had to set the internal and external projection for the vector and its working perfect now. 


----- Original Message ----- 
From: "Pedro Baracho" <pedropbaracho at gmail.com> 
To: "hekuran S. Doli" <hekuran.doli at logisticsplus-ks.com> 
Sent: Monday, November 16, 2009 5:58:12 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna 
Subject: Re: [OpenLayers-Users] Help with OpenLayer + Google Maps 

what are the projections of your point? I don't think they are on EPSG:900913 as your code states. They are most likely on EPSG:4326 (longitude and latitudes). So you should change your vector_layer projection to EPSG:4326. 

I also suggest you to do this: 
1- Add a displayProjection option to your map variable. 

map = new OpenLayers.Map('map', {displayProjection: new OpenLayers.Projection("EPSG:4326")}); 

2- Add a div for OpenLayers.Control.MousePosition at the bottom of your map: 

<div id="location"></div> 

3- Add OpenLayers.Control.MousePosition 

map.addControl(new OpenLayers.Control.MousePosition({element: $('location')})); 


This way you will actually see the coordinates where your mouse is pointing on the projection you want. 

Another thing. OpenLayers only have built-in support to EPSG:4326 and 900913. So any other projections besides those, you will have to add Proj4JS too. 

Cheers 


On Mon, Nov 16, 2009 at 3:42 PM, hekuran S. Doli < hekuran.doli at logisticsplus-ks.com > wrote: 




Dear Pedro, 

Thank you very very much. Now everything works fine but one the only thing is that the coordinates of the point are pointing elsewhere. Could this be because of projection type? Because the given coordinates should put the point somewhare in Ballkans (Kosovo more exact). 

This is what we have so far: 


var featurecollection = 
{ 
"type":"Feature", 
"id":"OpenLayers.Feature.Vector_173", 
"properties":{}, 
"geometry":{"type":"Point", "coordinates":[21.159739, 42.656138]} 
}; 




var geojson_format = new OpenLayers.Format.GeoJSON(); 
var vector_layer = new OpenLayers.Layer.Vector("title", {projection: new OpenLayers.Projection("EPSG:900913")}); 

map.addLayer(vector_layer); 
vector_layer.addFeatures(geojson_format.read(featurecollection)); 




----- Original Message ----- 
From: "Pedro Baracho" < pedropbaracho at gmail.com > 
To: "hekuran S. Doli" < hekuran.doli at logisticsplus-ks.com > 
Cc: users at openlayers.org 



Sent: Monday, November 16, 2009 5:14:12 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna 
Subject: Re: [OpenLayers-Users] Help with OpenLayer + Google Maps 

I would also add these options to the map if I were you. 

var options = { 
maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34), 
numZoomLevels:18, 
maxResolution:156543.0339, 
units:'m', 
projection: "EPSG:900913", 
displayProjection: new OpenLayers.Projection("EPSG:4326") 
}; 

var map = new OpenLayers.Map("map", options); 


On Mon, Nov 16, 2009 at 1:51 PM, Pedro Baracho < pedropbaracho at gmail.com > wrote: 


var center = new OpenLayers.LonLat(21.159739, 42.656138); 
map.setCenter(center.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913")), 10) 





On Mon, Nov 16, 2009 at 1:45 PM, hekuran S. Doli < hekuran.doli at logisticsplus-ks.com > wrote: 




Dear Pedro, 

Thanks a lot for your prompt reply. 

I implemented your suggestion but now the map does not move and the same coordinates point elsewhere. I published the updated example at http://www.logisticsplus-ks.com/testmap/ 

Regards, 
Hekuran 





----- Original Message ----- 
From: "Pedro Baracho" < pedropbaracho at gmail.com > 
To: "hekuran S. Doli" < hekuran.doli at logisticsplus-ks.com > 
Cc: users at openlayers.org 
Sent: Monday, November 16, 2009 3:30:27 PM GMT +01:00 Amsterdam / Berlin / Bern / Rome / Stockholm / Vienna 
Subject: Re: [OpenLayers-Users] Help with OpenLayer + Google Maps 

I mispelled projection parameter. 

it is lowerCase: 

{projection: new OpenLayers.Projection("EPSG:4326")} 


On Mon, Nov 16, 2009 at 12:28 PM, Pedro Baracho < pedropbaracho at gmail.com > wrote: 



var gmap = new OpenLayers.Layer.Google( 
"Google Streets", // the default 
{"sphericalMercator": true ,numZoomLevels: 20} 
); 

var vector_layer = new OpenLayers.Layer.Vector("title", {Projection: new OpenLayers.Projection("EPSG:4326")}); 





On Mon, Nov 16, 2009 at 1:20 PM, hekuran S. Doli < hekuran.doli at logisticsplus-ks.com > wrote: 







I'm using google map as layer in openlayer. I'm trying to add an point in the map as in example http://www.logisticsplus-ks.com/testmap/ . I'm successfully adding the point in the map but when I move the map the point changes the position. So it does not stay at the coordinates that I give it. 

By the way the functions works perfectly with openstreet map, but not with google maps. 

In the following is the code that I'm using: 

<script type="text/javascript"> 
var map; 



function init() { 
map = new OpenLayers.Map('map'); 
map.addControl(new OpenLayers.Control.LayerSwitcher()); 

var gmap = new OpenLayers.Layer.Google( 
"Google Streets", // the default 
{numZoomLevels: 20} 
); 

map.addLayers([gmap]); 

map.setCenter(new OpenLayers.LonLat(21.159739, 42.656138), 10); 
} 
var featurecollection = {"type":"Feature", "id":"OpenLayers.Feature.Vector_173", "properties":{}, "geometry":{"type":"Point", "coordinates":[21.159739, 42.656138]}}; 
function addGeoJson() { 
var geojson_format = new OpenLayers.Format.GeoJSON(); 
var vector_layer = new OpenLayers.Layer.Vector(); 
map.addLayer(vector_layer); 
//vector_layer.addFeatures(geojson_format.read(featurecollection)); 
vector_layer.addFeatures(geojson_format.read(featurecollection)); 
} 
</script> 

Any help would be appreciable. 
Thanks in advance, 
Hekuran 



_______________________________________________ 
Users mailing list 
Users at openlayers.org 
http://openlayers.org/mailman/listinfo/users 






-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/openlayers-users/attachments/20091116/61b4afba/attachment.html


More information about the Users mailing list