[OpenLayers-Users] reprojection of vector layer from wgs84 to
sphericalmercator
Mike Adair
madair at dmsolutions.ca
Mon Jan 14 10:09:46 EST 2008
Note that this should work too, and allows you to handle points in
coordinate systems other than EPSG:4326:
- include proj4js in your app via the <script> tag
- then:
preFeatureInsert = function(feature) {
var src = new OpenLayers.Projection('EPSG:4326');
var dest = new OpenLayers.Projection('EPSG:900913');
for (var i = 0; i < feature.geometry.components.length; i++) {
OpenLayers.Projection.transform(feature.geometry.components[i], src, dest);
}
};
You may need to skip transforming the last point in the components if it is a repeat of the first point (for polygons).
Mike
Jachym Cepicky wrote:
> Hi,
>
> Jachym Cepicky píše v Po 14. 01. 2008 v 14:11 +0100:
>
>> [...]
>>
>> Then I tried to redefine preFeatureInsert method of OpenLayers.Layer.Vector, to get coordinates
>> for all features in epsg:900913
>>
>> preFeatureInsert = function(feature) {
>> for (var i = 0; i < feature.geometry.components.length; i++) {
>> var x = feature.geometry.components[i].x;
>> var y = feature.geometry.components[i].y;
>> var ll = kolo.forwardMercator(x,y);
>>
>> x = x * 20037508.34 / 180;
>> y = Math.log(Math.tan((90 + y) * Math.PI / 360)) / (Math.PI / 180);
>>
>> y = y * 20037508.34 / 180;
>>
>> feature.geometry.components[i].x = x;
>> feature.geometry.components[i].y = y;
>>
>> }
>> };
>>
>> // the vector map definition
>>
>> var vector = new OpenLayers.Layer.GML("Vector","gml.xml",
>> {preFeatureInsert:preFeatureInsert});
>>
>>
> this works. the error was somewhere else
>
> j
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Users mailing list
> Users at openlayers.org
> http://openlayers.org/mailman/listinfo/users
>
More information about the Users
mailing list