Hi all,

WKT.write method accepts a single feature OR an array of features which then
returns as a GEOMETRYCOLLECTION.

There is a case that a single feature may hold a geometry collection class.

Here is my changes for the write method - I know that this is not the best
way to resolve this case but this is the shortest code insertion - all
feedback is welcome:

write:function(features){
                        var 
collection,geometry,type,data,isCollection,isSubCollection;
                        if(features.constructor==Array){
                                collection=features;
                                isCollection=true;
                        }
                        else{
                                
type=features.geometry.CLASS_NAME.split('.')[2].toLowerCase();
                                if (type == 'collection') {
                                        collection = 
features.geometry.components;
                                        isCollection=true;
                                        isSubCollection=true;
                                }
                                else {
                                        collection=[features];
                                        isCollection=false;
                                }
                        }
                        var pieces=[];
                        if(isCollection){
                                pieces.push('GEOMETRYCOLLECTION(');
                        }
                        for(var i=0,len=collection.length;i<len;++i){
                                if(isCollection&&i>0){
                                        pieces.push(',');
                                }
                                if (isSubCollection) geometry=collection[i]; 
else
geometry=collection[i].geometry;
                                
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);
                                }
                                data=this.extract[type].apply(this,[geometry]);
                                pieces.push(type.toUpperCase()+'('+data+')');
                        }
                        if(isCollection){
                                pieces.push(')');
                        }
                        return pieces.join('');
                }, 
-- 
View this message in context: 
http://n2.nabble.com/OpenLayers-Format-WKT-write-tp3497030p3497030.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.
_______________________________________________
Users mailing list
[email protected]
http://openlayers.org/mailman/listinfo/users

Reply via email to