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"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute"
>
<mx:Script>
<![CDATA[
import com.esri.ags.geometry.MapPoint;
private function clickHandler() : void
{
mapPointRO.save( new MapPoint( 45, 45 ));
}
]]>
</mx:Script>
<mx:RemoteObject id="mapPointRO" destination="mapPoint"/>
<mx:Button label="Save" click="clickHandler()"/>
</mx:Application>

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

<destination id="mapPoint">
<properties>
<source>com.esri.remoteobject.MapPointRO</source>
<scope>application</scope>
</properties>
</destination>

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.

Comments

Peter 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!

Popular posts from this blog

How to use Esri Flex API on Android and iPhone

Weighted Map Feature Clustering With Attributes

Augmented Reality, iPhone and ArcGIS Server