[OpenLayers-Dev] [OpenLayers-Users] Bug in OL 2.13.1 OpenLayers.Geometry.clone()?

Robert Sanson Robert.Sanson at asurequality.com
Sun Mar 29 13:24:24 PDT 2015


Hi

I have a Web mapping app built with OL 2.13.1

Vector data is read in from a database source as WKT. I have to transform from a source projection to a map projection once read into a vector feature, before adding to a vector layer, and then transform back to the source projection when writing out new features or edits back to the database.

On writing I get a problem when I clone a feature, reproject it and then try to write out the WKT:

var wkt_out;
var tmpgeom = feature.geometry.clone();
tmpgeom .transform(mapproj, srcproj);
wkt_out = wkt_format.write(tmpgeom );

I get an error: 

'CLASS_NAME' is null or not an object
WKT.js


Looking in WKT.js it appears the clone is not copying the type of geometry?

/**
     * Method: extractGeometry
     * Entry point to construct the WKT for a single Geometry object.
     *
     * Parameters:
     * geometry - {<OpenLayers.Geometry.Geometry>}
     *
     * Returns:
     * {String} A WKT string of representing the geometry
     */
    extractGeometry: function(geometry) {
        var type = geometry.CLASS_NAME.split('.')[2].toLowerCase();
        if (!this.extract[type]) {
            return null;
        }
        if (this.internalProjection && this.externalProjection) {
            geometry = geometry.clone();
            geometry.transform(this.internalProjection, this.externalProjection);
        }                       
        var wktType = type == 'collection' ? 'GEOMETRYCOLLECTION' : type.toUpperCase();
        var data = wktType + '(' + this.extract[type].apply(this, [geometry]) + ')';
        return data;
    }

If I write out the WKT of the feature from the vector layer before transforming, then read it in to a new feature (avoiding the use of clone), then transform it and then write out the WKT it works:

var wkt_out = wkt_format.write(feature);
var tmpgeom = wkt_format.read(wkt_out);
tmpgeom.geometry.transform(mapproj,srcproj);
wkt_out = wkt_format.write(tmpgeom);

Many thanks,

Robert Sanson




This email and any attachments are confidential and intended solely for the addressee(s). If you are not the intended recipient, please notify us immediately and then delete this email from your system.

This message has been scanned for Malware and Viruses by Websense Hosted Security.
www.websense.com 
_______________________________________________
Users mailing list
Users at lists.osgeo.org 
http://lists.osgeo.org/mailman/listinfo/openlayers-users



More information about the Dev mailing list