mirror of
https://github.com/Esri/offline-editor-js.git
synced 2025-12-15 15:20:05 +00:00
serialization/deserialization: simple and correct
This commit is contained in:
parent
bee248312b
commit
88752ba1fb
@ -6,10 +6,12 @@ define(["esri/graphic"],function(Graphic)
|
||||
serialize: function(graphic)
|
||||
{
|
||||
var json = graphic.toJson();
|
||||
var str = JSON.stringify(json);
|
||||
console.log("graphic",graphic);
|
||||
// console.log("json", json);
|
||||
// console.log("str", str);
|
||||
var jsonClean = // keep only attributes and geometry, that are the values that get sent to the server by applyEdits()
|
||||
{
|
||||
attributes: json.attributes,
|
||||
geometry: json.geometry
|
||||
}
|
||||
var str = JSON.stringify(jsonClean);
|
||||
return str;
|
||||
},
|
||||
|
||||
@ -17,9 +19,6 @@ define(["esri/graphic"],function(Graphic)
|
||||
{
|
||||
var json = JSON.parse(str);
|
||||
var graphic = new Graphic(json);
|
||||
// console.log("str", str);
|
||||
// console.log("json",json);
|
||||
console.log("graphic",graphic);
|
||||
return graphic;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
"http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||||
<title>Jasmine Spec Runner - Graphics Store</title>
|
||||
|
||||
<link rel="shortcut icon" type="image/png" href="../vendor/jasmine-1.3.1/jasmine_favicon.png">
|
||||
@ -30,14 +31,14 @@
|
||||
var g_graphicsStore;
|
||||
|
||||
require(["esri/map",
|
||||
"esri/layers/GraphicsLayer", "esri/graphic", "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleMarkerSymbol", "esri/SpatialReference",
|
||||
"esri/geometry",
|
||||
"esri/layers/GraphicsLayer", "esri/graphic", "esri/symbols/SimpleFillSymbol", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol",
|
||||
"esri/SpatialReference","esri/geometry",
|
||||
"edit/graphicsStore",
|
||||
"dojo/dom", "dojo/on", "dojo/query",
|
||||
"dojo/dom-construct", "dojo/domReady!"],
|
||||
function(Map,
|
||||
GraphicsLayer, Graphic, SimpleFillSymbol, SimpleMarkerSymbol, SpatialReference,
|
||||
geometry,
|
||||
GraphicsLayer, Graphic, SimpleFillSymbol, SimpleMarkerSymbol, SimpleLineSymbol,
|
||||
SpatialReference, geometry,
|
||||
graphicsStore,
|
||||
dom, on, query,
|
||||
domConstruct)
|
||||
@ -68,9 +69,28 @@
|
||||
});
|
||||
|
||||
// some symbols
|
||||
g_test.pointSymbol = new SimpleMarkerSymbol();
|
||||
g_test.pointSymbol = new SimpleMarkerSymbol({"color": [255,255,255,64],
|
||||
"size": 12, "angle": -30,
|
||||
"xoffset": 0, "yoffset": 0,
|
||||
"type": "esriSMS", "style": "esriSMSCircle",
|
||||
"outline": { "color": [0,0,0,255], "width": 1, "type": "esriSLS", "style": "esriSLSSolid"}
|
||||
});
|
||||
|
||||
g_test.pointFeature = new Graphic( g_test.point, g_test.pointSymbol, {"name": "the name of the feature", "objectid":2} );
|
||||
g_test.lineSymbol = new SimpleLineSymbol({
|
||||
"type": "esriSLS", "style": "esriSLSDot",
|
||||
"color": [115,76,0,255],"width": 1
|
||||
});
|
||||
|
||||
g_test.polygonSymbol = new SimpleFillSymbol({
|
||||
"type": "esriSFS",
|
||||
"style": "esriSFSSolid",
|
||||
"color": [115,76,0,255],
|
||||
"outline": { "type": "esriSLS", "style": "esriSLSSolid", "color": [110,110,110,255], "width": 1 }
|
||||
});
|
||||
|
||||
g_test.pointFeature = new Graphic( g_test.point, g_test.pointSymbol, {"name": "the name of the feature", "objectid":2});
|
||||
g_test.lineFeature = new Graphic( g_test.line, g_test.lineSymbol, {"nombre": "España","objectid":5});
|
||||
g_test.polygonFeature = new Graphic( g_test.polygon, g_test.polygonSymbol, {"nombre": "España","timestamp": new Date().getTime(), "objectid":5});
|
||||
|
||||
console.log(g_test);
|
||||
}
|
||||
|
||||
@ -2,51 +2,180 @@
|
||||
|
||||
describe("Serialize/Deserialize Graphics", function()
|
||||
{
|
||||
it("validate geometry objects", function()
|
||||
describe("Sanity Check", function()
|
||||
{
|
||||
// sanity checks on test data
|
||||
expect(typeof(g_test)).toBe("object");
|
||||
it("validate geometry objects", function()
|
||||
{
|
||||
// sanity checks on test data
|
||||
expect(typeof(g_test)).toBe("object");
|
||||
|
||||
// geometry
|
||||
expect(typeof(g_test.point)).toBe("object");
|
||||
expect(g_test.point.declaredClass).toBe("esri.geometry.Point");
|
||||
expect(g_test.point.type).toBe("point");
|
||||
expect(g_test.point.spatialReference.wkid).toEqual(4326);
|
||||
// geometry
|
||||
expect(typeof(g_test.point)).toBe("object");
|
||||
expect(g_test.point.declaredClass).toBe("esri.geometry.Point");
|
||||
expect(g_test.point.type).toBe("point");
|
||||
expect(g_test.point.spatialReference.wkid).toEqual(4326);
|
||||
|
||||
expect(typeof(g_test.line)).toBe("object");
|
||||
expect(g_test.line.declaredClass).toBe("esri.geometry.Polyline");
|
||||
expect(g_test.line.type).toBe("polyline");
|
||||
expect(g_test.line.spatialReference.wkid).toEqual(4326);
|
||||
expect(typeof(g_test.line)).toBe("object");
|
||||
expect(g_test.line.declaredClass).toBe("esri.geometry.Polyline");
|
||||
expect(g_test.line.type).toBe("polyline");
|
||||
expect(g_test.line.spatialReference.wkid).toEqual(4326);
|
||||
|
||||
expect(typeof(g_test.polygon)).toBe("object");
|
||||
expect(g_test.polygon.declaredClass).toBe("esri.geometry.Polygon");
|
||||
expect(g_test.polygon.type).toBe("polygon");
|
||||
expect(g_test.polygon.spatialReference.wkid).toEqual(4326);
|
||||
expect(typeof(g_test.polygon)).toBe("object");
|
||||
expect(g_test.polygon.declaredClass).toBe("esri.geometry.Polygon");
|
||||
expect(g_test.polygon.type).toBe("polygon");
|
||||
expect(g_test.polygon.spatialReference.wkid).toEqual(4326);
|
||||
});
|
||||
|
||||
// symbols
|
||||
expect(typeof(g_test.pointSymbol)).toBe("object");
|
||||
expect(g_test.pointSymbol.declaredClass).toBe("esri.symbol.SimpleMarkerSymbol");
|
||||
expect(g_test.pointSymbol.style).toBe("circle");
|
||||
it("validate symbols", function()
|
||||
{
|
||||
// symbols
|
||||
expect(typeof(g_test.pointSymbol)).toBe("object");
|
||||
expect(g_test.pointSymbol.declaredClass).toBe("esri.symbol.SimpleMarkerSymbol");
|
||||
expect(g_test.pointSymbol.style).toBe("circle");
|
||||
|
||||
// features
|
||||
expect(typeof(g_test.pointFeature)).toBe("object");
|
||||
expect(g_test.pointFeature.declaredClass).toBe("esri.Graphic");
|
||||
expect(g_test.pointFeature.geometry).toEqual(g_test.point);
|
||||
expect(g_test.pointFeature.symbol).toEqual(g_test.pointSymbol);
|
||||
expect(typeof(g_test.pointFeature.attributes)).toBe("object");
|
||||
expect(typeof(g_test.lineSymbol)).toBe("object");
|
||||
expect(g_test.lineSymbol.declaredClass).toBe("esri.symbol.SimpleLineSymbol");
|
||||
expect(g_test.lineSymbol.style).toBe("dot");
|
||||
|
||||
expect(typeof(g_test.polygonSymbol)).toBe("object");
|
||||
expect(g_test.polygonSymbol.declaredClass).toBe("esri.symbol.SimpleFillSymbol");
|
||||
expect(g_test.polygonSymbol.style).toBe("solid");
|
||||
});
|
||||
|
||||
it("validate features", function()
|
||||
{
|
||||
// features
|
||||
expect(typeof(g_test.pointFeature)).toBe("object");
|
||||
expect(g_test.pointFeature.declaredClass).toBe("esri.Graphic");
|
||||
expect(g_test.pointFeature.geometry).toEqual(g_test.point);
|
||||
expect(g_test.pointFeature.symbol).toEqual(g_test.pointSymbol);
|
||||
expect(typeof(g_test.pointFeature.attributes)).toBe("object");
|
||||
|
||||
expect(typeof(g_test.lineFeature)).toBe("object");
|
||||
expect(g_test.lineFeature.declaredClass).toBe("esri.Graphic");
|
||||
expect(g_test.lineFeature.geometry).toEqual(g_test.line);
|
||||
expect(g_test.lineFeature.symbol).toEqual(g_test.lineSymbol);
|
||||
expect(typeof(g_test.lineFeature.attributes)).toBe("object");
|
||||
|
||||
expect(typeof(g_test.polygonFeature)).toBe("object");
|
||||
expect(g_test.polygonFeature.declaredClass).toBe("esri.Graphic");
|
||||
expect(g_test.polygonFeature.geometry).toEqual(g_test.polygon);
|
||||
expect(g_test.polygonFeature.symbol).toEqual(g_test.polygonSymbol);
|
||||
expect(typeof(g_test.polygonFeature.attributes)).toBe("object");
|
||||
});
|
||||
});
|
||||
|
||||
var str;
|
||||
|
||||
it("serialize graphic - point", function()
|
||||
describe("Serialize/Deserialize Point", function()
|
||||
{
|
||||
str = g_graphicsStore.serialize(g_test.pointFeature);
|
||||
expect(typeof(str)).toBe("string");
|
||||
var str, graphic;
|
||||
|
||||
it("serialize", function()
|
||||
{
|
||||
str = g_graphicsStore.serialize(g_test.pointFeature);
|
||||
expect(typeof(str)).toBe("string");
|
||||
});
|
||||
|
||||
it("deserialize", function()
|
||||
{
|
||||
graphic = g_graphicsStore.deserialize(str);
|
||||
expect(typeof(graphic)).toBe("object");
|
||||
expect(graphic.declaredClass).toEqual("esri.Graphic");
|
||||
});
|
||||
|
||||
it("deserialize - attributes", function()
|
||||
{
|
||||
expect(graphic.attributes).toEqual(g_test.pointFeature.attributes);
|
||||
});
|
||||
|
||||
it("deserialize - geometry", function()
|
||||
{
|
||||
expect(graphic.geometry).toEqual(g_test.pointFeature.geometry);
|
||||
});
|
||||
|
||||
it("deserialize - symbol should be null", function()
|
||||
{
|
||||
expect(graphic.symbol).toBeNull();
|
||||
});
|
||||
|
||||
it("deserialize - infoTemplate should be null", function()
|
||||
{
|
||||
expect(graphic.infoTemplate).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it("deserialize graphic - point", function()
|
||||
describe("Serialize/Deserialize Polyline", function()
|
||||
{
|
||||
var graphic = g_graphicsStore.deserialize(str);
|
||||
expect(graphic).toEqual(g_test.pointFeature);
|
||||
var str, graphic;
|
||||
|
||||
it("serialize", function()
|
||||
{
|
||||
str = g_graphicsStore.serialize(g_test.lineFeature);
|
||||
expect(typeof(str)).toBe("string");
|
||||
});
|
||||
|
||||
it("deserialize", function()
|
||||
{
|
||||
graphic = g_graphicsStore.deserialize(str);
|
||||
expect(typeof(graphic)).toBe("object");
|
||||
expect(graphic.declaredClass).toEqual("esri.Graphic");
|
||||
});
|
||||
|
||||
it("deserialize - attributes", function()
|
||||
{
|
||||
expect(graphic.attributes).toEqual(g_test.lineFeature.attributes);
|
||||
});
|
||||
|
||||
it("deserialize - geometry", function()
|
||||
{
|
||||
expect(graphic.geometry).toEqual(g_test.lineFeature.geometry);
|
||||
});
|
||||
|
||||
it("deserialize - symbol should be null", function()
|
||||
{
|
||||
expect(graphic.symbol).toBeNull();
|
||||
});
|
||||
|
||||
it("deserialize - infoTemplate should be null", function()
|
||||
{
|
||||
expect(graphic.infoTemplate).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Serialize/Deserialize Polygon", function()
|
||||
{
|
||||
var str, graphic;
|
||||
|
||||
it("serialize", function()
|
||||
{
|
||||
str = g_graphicsStore.serialize(g_test.polygonFeature);
|
||||
expect(typeof(str)).toBe("string");
|
||||
});
|
||||
|
||||
it("deserialize", function()
|
||||
{
|
||||
graphic = g_graphicsStore.deserialize(str);
|
||||
expect(typeof(graphic)).toBe("object");
|
||||
expect(graphic.declaredClass).toEqual("esri.Graphic");
|
||||
});
|
||||
|
||||
it("deserialize - attributes", function()
|
||||
{
|
||||
expect(graphic.attributes).toEqual(g_test.polygonFeature.attributes);
|
||||
});
|
||||
|
||||
it("deserialize - geometry", function()
|
||||
{
|
||||
expect(graphic.geometry).toEqual(g_test.polygonFeature.geometry);
|
||||
});
|
||||
|
||||
it("deserialize - symbol should be null", function()
|
||||
{
|
||||
expect(graphic.symbol).toBeNull();
|
||||
});
|
||||
|
||||
it("deserialize - infoTemplate should be null", function()
|
||||
{
|
||||
expect(graphic.infoTemplate).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user