I have added vector layer to map:

    vactorTest = new OpenLayers.Layer.Vector("Editable Features", {
strategies: [new OpenLayers.Strategy.BBOX(), saveStrategy],
projection: new OpenLayers.Projection("EPSG:900913"),
protocol: new OpenLayers.Protocol.WFS({
    srsName: "EPSG:900913",
url: "http://localhost:8080/geoserver/wfs",
featureType: "ROADS",
featureNS: "http://localhost:8080/MIA",
featurePrefix: "MIA",
geometryName: "GEOM",
version: "1.1.0"


And then, added polygon draw control:

var drawPolygon = new OpenLayers.Control.DrawFeature(
vactorTest, OpenLayers.Handler.Polygon,
title: "Draw Polygon",
displayClass: "olControlDrawFeaturePolygon",
multi: true

with drawn polygon I want to filter layer:

    "CQL_FILTER": mergeFilter

I use within filter:

WITHIN(GEOM, POLYGON((4693721.49445 672633.89194, 4560244.10812 322255.75282, 4703732.29843 422363.79257, 4693721.49445 672633.89194)))

target layer is in Georgia, and if I draw polygon near Italy then, filter works.

How can I change vector projection like my layer to get right result?


You can serialize your data. To reproject the data when converting, you should pass the internal and external projection to the format class, then use that format to write out your data.

var format = new OpenLayers.Format.GeoJSON({
  'internalProjection': new OpenLayers.Projection("EPSG:900913"),
  'externalProjection': new OpenLayers.Projection("EPSG:4326")
var jsonstring = format.write(vector_layer.features);

or you can transform your features on your vector layer as,

var proj = new OpenLayers.Projection("EPSG:4326");
var point = new OpenLayers.LonLat(-71, 42);
map.setCenter(point.transform(proj, map.getProjectionObject()));
  • where I have to add this code? Thanks – Lazonaden May 12 '12 at 12:27
  • the first code for adding new features to map with different projection, the second code is transforming your feature the new projection. You can add them when adding features to your map... Both of codes will take you the same conclusion. – Aragon May 12 '12 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.