Solved! Go to Solution.
Graphic oldGraphic = getGraphic(graphicUid); Graphic newGraphic = new Graphic(myNewGeometry, oldGraphic.getSymbol(), oldGraphic.getAttributes()); privateGraphicsList.remove(oldGraphic); privateGraphicsList.add(newGraphic);
int[] uids = myLayer.getGraphicIDs(); Graphic[] layerGraphics = new Graphic[uids.length]; for (int i = 0, i < uids.length; i++) { layerGraphics = myLayer.getGraphic(uid); // sometimes this is null even though you just got the uids }
public void somethingIsWrong() { Point point = new Point(577068, 6056541); // spat ref. wkid 3346 Symbol greenSymbol = new SimpleMarkerSymbol(Color.GREEN, 20, STYLE.DIAMOND); Graphic graphic = new Graphic(point, greenSymbol); Graphic customGraphic = new CustomGraphic(point, greenSymbol); try { Log.d(TAG, " graphic --> " + Graphic.toJson(graphic)); Log.d(TAG, " customGraphic --> " + Graphic.toJson(customGraphic)); } catch (Exception e) { throw new RuntimeException(e); } } public static class CustomGraphic extends Graphic { private static final SpatialReference SR_WKID_3346 = SpatialReference.create(3346); public CustomGraphic(Geometry geometry, Symbol symbol) { super(geometry, symbol); } @Override public SpatialReference getSpatialReference() { return SR_WKID_3346; } }
03-01 04:36:03.716: D/DEBUG(21551): graphic --> {} 03-01 04:36:03.736: D/DEBUG(21551): customGraphic --> {"geometry":{"x":577068.0,"y":6056541.0,"spatialReference":{"wkid":2600,"latestWkid":3346}}}
public static boolean writeCachedFeatureSet(FeatureSet featureSet, File cacheFile) { cacheFile.getParentFile().mkdirs(); try { FileOutputStream fos = new FileOutputStream(cacheFile); BufferedOutputStream bos = new BufferedOutputStream(fos); ObjectOutputStream output = new ObjectOutputStream(bos); output.writeObject(featureSet); output.close(); return true; } catch (Exception e) { // handle exception } return false; } public static FeatureSet readCachedFeatureSet(File cacheFile) { try { FileInputStream fis = new FileInputStream(cacheFile); BufferedInputStream bis = new BufferedInputStream(fis); ObjectInputStream input = new ObjectInputStream(bis); FeatureSet featureSet = (FeatureSet) input.readObject(); input.close(); return featureSet; } catch (Exception e) { // handle exception } return null; }
Can I ask what you intend to do with the JSON? If your purpose it to cache the graphics to local storage, you will find that your performance hit will be significant as the number of graphics grows large. An exponentially faster solution for local caching is something like this.