apneadiving
apneadiving

Reputation: 115541

OpenLayers: Why are my Vectors Features Markers misplaced?

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

Upvotes: 2

Views: 1638

Answers (2)

igorti
igorti

Reputation: 3856

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.

Upvotes: 5

Joe Holloway
Joe Holloway

Reputation: 28968

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.

Upvotes: 1

Related Questions