2

I first coded using Markers (with success) then realizing it was no more recommended (especially for clustering).

Having read the examples given in Openlayers doc and this question, I've created my Vectors, added some style etc...

But, they are all put in around the LngLat(0,0) instead of their proper coordinates.

You could see below their geometry properties are ok. I don't know what I'm missing there.

sreenshot

Community
  • 1
  • 1
apneadiving
  • 114,565
  • 26
  • 219
  • 213

2 Answers2

5

The problem is that while Google Maps projection is EPSG:900913, coordinates of your vector features are in EPSG:4326.

So you have to either specify coordinates in Google Maps projection or use OpenLayers to transform coordinates on the client side. Here's how you do it:

feature.geometry.transform(new OpenLayers.Projection("EPSG:4326"), new OpenLayers.Projection("EPSG:900913"))

Once you transformed features you can add layer to the map and it should display features correctly.

igorti
  • 3,828
  • 3
  • 22
  • 29
1

What coordinate projection are you using? I assume by the name of your layer that you're using a Google Maps base layer.

Google Maps uses a spherical mercator projection and OpenLayers uses EPSG:4326 by default. OpenLayers has APIs that let you transform your coordinates between various projections so that all of your layers play nicely together.

With some more details about your layers I can provide some code to demonstrate this.

Joe Holloway
  • 28,320
  • 15
  • 82
  • 92
  • Thanks for your help. I must (with shame) admit I've no idea what projection I'm using: I can't really figure out the openlayers' big picture :/ I'm coding to extend a Rails plugin displaying stuff on a Google Map. I'd like to give users the choice of choosing openlayers. You could find the specific openlayers code here: https://github.com/apneadiving/Google-Maps-for-Rails/blob/playground/public/javascripts/gmaps4rails.openlayers.js Thanks in advance for your expertise. – apneadiving Jul 10 '11 at 08:06
  • Thanks for your help, igorti just answered, +1 anyway – apneadiving Jul 10 '11 at 14:54
  • No prob, actually I probably could have provided that same code snippet last night, but I didn't want to make too many assumptions. – Joe Holloway Jul 10 '11 at 15:03
  • :) tell me if I'd rather post a new question but do you know how to have a nice clutering in openlayers such as: http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerclusterer/1.0/examples/simple_example.html – apneadiving Jul 10 '11 at 15:10
  • just opened a real question here: http://stackoverflow.com/questions/6641919/openlayers-nice-marker-clustering – apneadiving Jul 10 '11 at 15:22