Wednesday 30 December 2015

geoserver - Changing vector projection in OpenLayers


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"
})
});


map.addLayer(vactorTest);

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:


testLayer.mergeNewParams({
"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?



Answer



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()));

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...