[OpenLayers-Users] Geometry.Collection (LineString) GetCentroid - fake?

BrainDrain paulborodaev at gmail.com
Wed Feb 17 03:18:37 EST 2010


Hi.
I use this function to locate geometry on map
OpenLayers.Map.prototype.locate = function(geometry, panOnly) {
		var bounds = geometry.getBounds();
		//this.zoomToExtent(bounds);
		//this.zoomToScale(scale);
		if ((this.getExtent().containsBounds(bounds) ||
this.getZoomForExtent(bounds) > this.zoom) || panOnly) {
			//wrong for complex LineStrings (points to the center of the extent - not
center of the geometry)
                        //this.panTo(bounds.getCenterLonLat());
 
                        //incorrect with current implemetation of
Geometry.Collection GetCentroid 
			//this.panTo(WEM.Util.point2ll(geometry.getCentroid()));
									
			var parser = new OpenLayers.Format.WKT();
                        //this works - BUT! I need to send all geometry WKT
to the server
                        //server (MapServer mapscript c# via webservice
webmetod) getCentroid works perfectly
			application.server.MapParser.GetCentroid(parser.write(geometry),
function(geometryWKT, scope) {
				scope.panTo(WEM.Util.point2ll(parser.read(geometryWKT).geometry));
			}, null, this);			
		}
		else {
			var zoom = this.zoom;
			this.zoomToExtent(bounds);
			this.zoomTo(zoom);
		}
};

What's this (for ex. for LineString)???
/**
     * APIMethod: getCentroid
     *
     * Returns:
     * {<OpenLayers.Geometry.Point>} The centroid of the collection
     */
    getCentroid: function() {
        return this.components.length && this.components[0].getCentroid();
//just great)))(((!
    }

Currently I can:
 - pass only featureId to the server (not all geometry text)
 - get centroid forcibly on server on querying features and then use it
 - compress geometry WKT with JavaScript lib (deflate) and decompress on
server as I do it on update feature....
But I want correct getCentroid implemetation
-- 
View this message in context: http://n2.nabble.com/Geometry-Collection-LineString-GetCentroid-fake-tp4584888p4584888.html
Sent from the OpenLayers Users mailing list archive at Nabble.com.



More information about the Users mailing list