Tuesday, November 11, 2008

Serializing Geometries To BlazeDS

Was asked if there is a way to serialize the geometries of a Flex client application using for example BlazeDS. And the answer is 'yes'. All geometries are tagged with a [RemoteClass] metadata. Here is the break down (BTW - this is subject to change in the next version):

SpatialReference com.esri.ags.ASSpatialReference
MapPoint com.esri.ags.geometry.ASPoint
Polyline com.esri.ags.geometry.ASPolyline
Polygon com.esri.ags.geometry.ASPolygon

Here is for example the Java side of MapPoint:

package com.esri.ags.geometry;

import com.esri.ags.ASSpatialReference;

public class ASPoint implements IASGeometry
public double x;
public double y;
public ASSpatialReference spatialReference;

The following is a very simple client application that calls a RemoteObject to save a MapPoint instance:

<?xml version="1.0" encoding="utf-8"?>
import com.esri.ags.geometry.MapPoint;
private function clickHandler() : void
mapPointRO.save( new MapPoint( 45, 45 ));
<mx:RemoteObject id="mapPointRO" destination="mapPoint"/>
<mx:Button label="Save" click="clickHandler()"/>

The RemoteObject destination is defined in remoting-config.xml:

<destination id="mapPoint">

And here is the POJO under BlazeDS:

package com.esri.remoteobject;

import com.esri.ags.geometry.ASPoint;

public class MapPointRO
public void save(final ASPoint asPoint)
System.out.println("asPoint.x = " + asPoint.x);
System.out.println("asPoint.y = " + asPoint.y);

You can download all the Java implementations from here.

1 comment:

PMac said...

Interesting... we are serializing geometry using Base64Encoding to a string that we store in a varcharmax fields in a simple SQLServer table. Poor mans GDB. This is for a client who has no GIS but does need to store some polygons. Use the edit/draw tools of flex API 2.0 to create and edit - WCF service to save/fetch from SQL. Works great!