var file = dom.byId("uploadFile").files[0]; //where "uploadFile" is the id of your html file input var reader = new FileReader(); var fileContent = reader.readAsText(file); alert(fileContent);
<input id="uploadFile" data-dojo-id="uploadFile" type="file"/> <input type="button" data-dojo-id="uploadButton" type="dijit/form/Button" value="Load..." onClick="loadFile()"/>
function loadFile() { require(["dojo/dom", "dojo/request/xhr"], function(dom, xhr){ xhr.post("<url to your server script>", { data: { filePath : dom.byId("uploadFile").value } }).then(<callbackfunction>); }
function exportData() { require(["dojo/json", "dojo/_base/array", "dojo/request/iframe"], function(JSON, array, iframe){ var exportData = []; array.forEach(map.graphics.graphics, function(g) { exportData.push(g); }); var jsonString = JSON.stringify(exportData); iframe.post("<url to your server script>", { data : { records : jsonString }, timeout : 10000 }); }); }
function exportGraphics(){ var graphicList = []; $.each(map.graphics.graphics, function(index, graphic){ var graphicStr = JSON.stringify(graphic.toJson()); graphicList.push(graphicStr); }); $.generateFile({ filename : 'graphics.txt', content : graphicList, script : 'download.php' }); }
Based on what I learned so far this can not be done by JavaScript alone.
function exportToWord() { //exports the addresses of the parcels in the graphics file to a text file //on the users desktop and then opens it with the Word label template. if (!dojo.isIE) { alert("Exporting to Word only works with Internet Explorer"); return false; } //note this will give them a warning about ActiveX object running var wshshell = new ActiveXObject("wscript.shell"); var strDesktop = wshshell.SpecialFolders("Desktop"); var fso = new ActiveXObject("Scripting.FileSystemObject"); var bolOwner = false; //text file for property locations fProps = fso.CreateTextFile(strDesktop + "\\plist.txt", true); fProps.WriteLine("NAME;ADDRESS;ZIP"); var graphic; for (var i = 0, il = map.graphics.graphics.length; i < il; i++) { graphic = map.graphics.graphics; if (graphic.attributes) { fProps.WriteLine(graphic.attributes["OWNER1"] + ";" + graphic.attributes["ADDRESS1"] + ";" + graphic.attributes["ZIPCODE"]); } } fProps.Close(); //now open the word label template which contains VBA to dump the olist.txt into a new doc var w = new ActiveXObject('Word.Application'); w.Visible = true; w.Documents.Open("C:\\TEMP\\Plabeltest.docm"); }
It will be a great point to start, though what I need is the ability to save the graphics to a external file that can be shared among users. would you share the code?:)
function addToMap(geometry) { //drawToolbar.deactivate(); a = dijit.byId("tslider").value; c = hexToRgb(graphicColour, a); fullcolour = new dojo.Color(c); // fillStyle = dijit.byId('fillSelect').attr('value'); var psize = dijit.byId("font.size").value; psize = psize.replace("pt", ""); switch (geometry.type) { case "point": var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, psize, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([255, 0, 0]), 1), new dojo.Color(graphicColour)); if (drawtype == 'Text') { fullcolour = new dojo.Color([0, 0, 0, 255]); var font = new esri.symbol.Font(dijit.byId("font.size").value, esri.symbol.Font.STYLE_NORMAL, esri.symbol.Font.VARIANT_NORMAL, esri.symbol.Font.WEIGHT_NORMAL, "verdana"); var symbol = new esri.symbol.TextSymbol(dijit.byId("usertext").value, font, fullcolour).setAngle(0).setOffset(0, 0).setAlign(esri.symbol.TextSymbol.ALIGN_START).setDecoration(esri.symbol.TextSymbol.DECORATION_NONE).setRotated(false).setKerning(true); } break; case "polyline": var symbol = new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, fullcolour, dijit.byId("line.size").value); break; case "polygon": var symbol = new esri.symbol.SimpleFillSymbol(dijit.byId('fillSelect').attr('value'), new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([0, 0, 0]), dijit.byId("line.size").value), fullcolour); break; } console.debug(symbol) var graphic = new esri.Graphic(geometry, symbol); // store to local storage graphic added var now = new Date(); var n = now.getTime(); GraphicName = "storedGraphic" + n; window.localStorage.setItem(GraphicName, dojo.toJson(graphic.toJson())); graphic.setAttributes({ newID: GraphicName }); userGraphics.add(graphic); //enableID(); }
//graphics stored in local srtorage and display it. for (var i = 0; i < localStorage.length; i++) { var n = "SavedGraphic" + i; var key = localStorage.key(i); //we use local storage for other things, so only read in storedgraphics if (Left(key, 8) == 'storedGr') { saved = dojo.fromJson(localStorage.getItem(localStorage.key(i))); var graphic = new esri.Graphic(saved); graphic.setAttributes({ "ID": n, "LSNo": i }); userGraphics.add(graphic); } }
function createToolbarAndContextMenu(map) { map.enableSnapping({ snapKey: dojo.keys.copyKey }); // Create and setup editing tools editToolbar = new esri.toolbars.Edit(map); dojo.connect(editToolbar, "onDeactivate", function(tool, graphic, info) { //we need to remove the version in local storage as we will be saving a new version //if Graphics has newID it has been added this session //If not it has been loaded from localstorage //if from LS the attribute LSNo will equal the index no in localstorage if (graphic.attributes.newID) { localStorage.removeItem(graphic.attributes.newID); } else { localStorage.removeItem(localStorage.key(graphic.attributes.LSNo)); } //save a new version with name time stamped so it can be referred to in future edits/deletes this session var now = new Date(); var n = now.getTime(); GraphicName = "storedGraphic" + n; window.localStorage.setItem(GraphicName, dojo.toJson(graphic.toJson())); }); dojo.connect(map, "onClick", function(evt) { editToolbar.deactivate(); }); createMapMenu(); createGraphicsMenu(); }
function createGraphicsMenu() { // Creates right-click context menu for GRAPHICS ctxMenuForGraphics = new dijit.Menu({}); ctxMenuForGraphics.addChild(new dijit.MenuItem({ label: "Edit", onClick: function() { if (selected.geometry.type !== "point") { editToolbar.activate(esri.toolbars.Edit.EDIT_VERTICES, selected); } else { alert("Not implemented"); } } })); ctxMenuForGraphics.addChild(new dijit.MenuItem({ label: "Move", onClick: function() { editToolbar.activate(esri.toolbars.Edit.MOVE, selected); } })); ctxMenuForGraphics.addChild(new dijit.MenuItem({ label: "Rotate/Scale", onClick: function() { if (selected.geometry.type !== "point") { editToolbar.activate(esri.toolbars.Edit.ROTATE | esri.toolbars.Edit.SCALE, selected); } else { alert("Not implemented"); } } })); ctxMenuForGraphics.addChild(new dijit.MenuSeparator()); ctxMenuForGraphics.addChild(new dijit.MenuItem({ label: "Delete", onClick: function() { userGraphics.remove(selected); if (selected.attributes.newID) { localStorage.removeItem(selected.attributes.newID); } else { localStorage.removeItem(localStorage.key(selected.attributes.LSNo)); } } })); ctxMenuForGraphics.startup(); dojo.connect(userGraphics, "onMouseOver", function(evt) { // We'll use this "selected" graphic to enable editing tools // on this graphic when the user click on one of the tools // listed in the menu. selected = evt.graphic; // Let's bind to the graphic underneath the mouse cursor ctxMenuForGraphics.bindDomNode(evt.graphic.getDojoShape().getNode()); }); dojo.connect(userGraphics, "onMouseOut", function(evt) { ctxMenuForGraphics.unBindDomNode(evt.graphic.getDojoShape().getNode()); }); }
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.