<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ReadJosn.aspx.cs" Inherits="ReadJosn" %>
<!doctype html>
<html>
<head>
<title>...</title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/2.2/js/dojo/dijit/themes/claro/claro.css">
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=2.2"></script>
<script type="text/javascript" language="Javascript">
dojo.require("esri.map");
dojo.require("esri.layers.FeatureLayer");
dojo.require("esri.layers.graphics");
var map;
function init() {
//var startExtent = new esri.geometry.Extent({ "xmin": -12505511, "ymin": 2230016, "xmax": -3699965, "ymax": 8100380, "spatialReference": { "wkid": 102100 } });
map = new esri.Map("mapDiv");
//create and add new layer
var layer = new esri.layers.ArcGISTiledMapServiceLayer("");
var sketchLayer = "";
map.addLayer(layer);
var jsonFS =
{ "geometry": { "rings": [[[663791.8729519134, 2760558.7151297885], [663791.8729519134, 2760492.5691641634], [667099.1712331766, 2749776.9227328706], [656118.9409393826, 2749247.7550078686], [652547.0587956184, 2755994.6435016454], [663791.8729519134, 2760558.7151297885]]], "spatialReference": { "wkid": 32638, "latestWkid": 32638 } }, "symbol": { "color": [0, 0, 0, 64], "outline": { "color": [0, 0, 0, 255], "width": 1, "type": "esriSLS", "style": "esriSLSSolid" }, "type": "esriSFS", "style": "esriSFSSolid" } }
;
// var temp = eval("(" + jsonFS + ")");
//var sk = new esri.Graphic(eval("(" + jsonFS + ")"));
alert("0");
map.getLayer("sketchLayer").add(new esri.Graphic(eval("(" + jsonFS + ")")));
map.addLayer(new esri.Graphic(eval("(" + jsonFS + ")")));
alert("addLayer" + sk);
//console.log(jsonFS.features);
//var fs = new esri.tasks.FeatureSet(jsonFS);
//var featureCollection = {
// layerDefinition: {
// "geometryType": "esriGeometryPoint",
// "fields": [
// {
// }
// ]
// },
// featureSet: fs
//};
//var jsonfl = new esri.layers.FeatureLayer(featureCollection, {
// mode: esri.layers.FeatureLayer.MODE_SNAPSHOT,
// 'id': 'jsonfl'
//});
//map.addLayer(jsonfl);
}
dojo.ready(init);
</script>
</head>
<body class="claro">
<div id="mapDiv" style="width: 900px; height: 600px; border: 1px solid #000;"></div>
</body>
</html>
no Graphic appear to map any idea ??? Help
//using jquery to loop through the graphics: var jsonval = "{"; $.each(markupGrfLayer.graphics, function (index, grf) { var junk = grf.toJson(); jsonval += "\"" + index + "\":" + dojo.toJson(junk) + ","; }); jsonval = jsonval.substring(0, jsonval.length - 1); //trim comma jsonval += "}";
var jsString = stringFromFile; var val = $.parseJSON(jsString); $.each(val, function (key, value) { var gra = new esri.Graphic(value); markupGrfLayer.add(gra); });
updateData = function(graphic) { var _args, attr, data, geom; attr = graphic.attributes; // JSON methods may not be available in all browsers // I think dojo.toJson(obj).toString() will // do the same thing. geom = JSON.stringify(graphic.geometry.toJson()); data = { "Geometry": geom }; _args = { // my .net service will handle the writing // to sql server url: "api/service/" + attr.id, postData: data, handleAs: "json" }; // I think you'd use xhrRawPost for json data, // I'm not clear on this one. return dojo.xhrRawPost(_args); };
graphics = []; // array that will hold my graphics // results would be the response from // from a REST request via dojo xhr or jquery ajax dojo.forEach(results, function(result) { var g, res_geom, res_obj; // result is JSON, but Geometry is a string field // convert string field to JSON object res_obj = dojo.fromJson(result.Geometry); // convert json to geometry res_geom = esri.geometry.fromJson(res_obj); //create my graphic g = new esri.Graphic(res_geom, symbolHelper.lineSymbol(), { "Id": attribute.Id, "WorkOrderId": attribute.WorkOrderId }); return graphics.push(g); }); // In this case, I update a FeatureLayer, but you can easily just add // graphics to a GraphicsLayer prev_graphics = lineFeatures.graphics; lineFeatures.applyEdits(graphics, null, prev_graphics);
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.