var attInspector = new AttributeInspector({ layerInfos:layerInfos }, "attributesDiv"); attInspector.on("attribute-change", function(evt) { var feature = evt.feature; //keep all fields the same from the input feature.attributes[evt.fieldName] = evt.fieldValue; //override the USER_ field with the userId from the credentials object feature.attributes.USER_ = esri.id.credentials[0].userId; //apply attribute update feature.getLayer().applyEdits(null, [feature], null); //refresh to show the 'behind the scenes' edit attInspector.refresh(); });
on(editLayer, 'update', function (evt) { populateNumber(); }); }); function populateNumber(){ var input = document.getElementById('dijit_form_TextBox_0'); if(input.value.length == 0) input.value = "Empty";
require([ "esri/map", "esri/tasks/GeometryService", "esri/toolbars/edit", "esri/graphic", "esri/Color", "esri/dijit/HomeButton", "esri/dijit/BasemapGallery", "esri/dijit/LocateButton", "esri/dijit/Geocoder", "esri/layers/ArcGISDynamicMapServiceLayer", "esri/layers/FeatureLayer", "esri/symbols/SimpleMarkerSymbol", "esri/symbols/SimpleLineSymbol", "esri/dijit/editing/Editor", "esri/dijit/editing/TemplatePicker", "esri/config", "dojo/i18n!esri/nls/jsapi", "dojo/on", "dojo/_base/array", "dojo/parser", "dojo/keys", "dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!" ], function( Map, GeometryService, Edit, Graphic, Color, HomeButton, BasemapGallery, LocateButton, Geocoder, ArcGISDynamicMapServiceLayer, FeatureLayer, SimpleMarkerSymbol, SimpleLineSymbol, Editor, TemplatePicker, esriConfig, jsapiBundle, on, arrayUtils, parser, keys ) { parser.parse(); //This service is for development and testing purposes only. We recommend that you create your own geometry service for use within your applications. esriConfig.defaults.geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); map = new Map("map", { basemap: "streets", center: [-98.185272, 26.282376], logo: false, sliderStyle: 'large', zoom: 9, }); var home = new HomeButton({ map: map }, "HomeButton"); home.startup(); geoLocate = new LocateButton({ map: map }, "LocateButton"); geoLocate.startup(); var geocoder = new Geocoder({ arcgisGeocoder: false, autoComplete: true, zoomScale:1000, geocoders: [ { url: "http://maps.lrgvdc911.org:6080/arcgis/rest/services/Public_Outreach/SDE_ADDRESS_POINTS_130917_Create2/GeocodeServer", name: "LRGVDC ", placeholder: "Locate", outFields: "*", singleLineFieldName: "SingleLine" }], map: map }, "search"); geocoder.on('select', function (candidate) { for(var i = 0; i< 20; i++) { var geom = candidate.result.feature.geometry; var symbol = new SimpleMarkerSymbol(); symbol.setStyle(SimpleMarkerSymbol.STYLE_CIRCLE); symbol.setColor(new Color([155, 0, 61, 0.75])); var graphic = new Graphic(geom, symbol); map.graphics.clear(); map.graphics.add(graphic); } }) geocoder.on('clear', function(){ map.graphics.clear(); }) var basemapGallery = new BasemapGallery({ showArcGISBasemaps: true, map: map }, "basemapGallery"); basemapGallery.startup(); basemapGallery.on("error", function(msg) { console.log("basemap gallery error: ", msg); }); map.on("layers-add-result", initEditor); //add boundaries and place names var dynamic = new ArcGISDynamicMapServiceLayer("http://maps.lrgvdc911.org:6080/arcgis/rest/services/STEAR/STEAR_DYNAMIC/MapServer"); map.addLayer(dynamic); var events = new FeatureLayer("http://maps.lrgvdc911.org:6080/arcgis/rest/services/Public_Outreach/EVENTS/FeatureServer/0",{ mode: FeatureLayer.MODE_ONDEMAND, outFields: ['EVENT_NAME', 'date','address', 'psap'] }); map.addLayers([events]); function initEditor(evt) { var templateLayers = arrayUtils.map(evt.layers, function(result){ return result.layer; }); var templatePicker = new TemplatePicker({ featureLayers: templateLayers, grouping: true, rows: "auto", columns: 1 }, "draggable"); templatePicker.startup(); var layers = arrayUtils.map(evt.layers, function(result) { return { featureLayer: result.layer }; }); var settings = { map: map, templatePicker: templatePicker, layerInfos: layers, toolbarVisible: true, createOptions: { polylineDrawTools:[ Editor.CREATE_TOOL_FREEHAND_POLYLINE ], polygonDrawTools: [ Editor.CREATE_TOOL_FREEHAND_POLYGON, Editor.CREATE_TOOL_CIRCLE, Editor.CREATE_TOOL_TRIANGLE, Editor.CREATE_TOOL_RECTANGLE ] }, toolbarOptions: { reshapeVisible: true } }; var params = {settings: settings}; var myEditor = new Editor(params,'editorDiv'); //define snapping options var symbol = new SimpleMarkerSymbol( SimpleMarkerSymbol.STYLE_CROSS, 15, new SimpleLineSymbol( SimpleLineSymbol.STYLE_SOLID, new Color([255, 0, 0, 0.5]), 5 ), null ); map.enableSnapping({ snapPointSymbol: symbol, tolerance: 20, snapKey: keys.ALT }); myEditor.startup(); } });
Hi, Hector. I would love to see that code! I am struggling w/ the same problem as above.
Hey Matthew what code do you need.
I have to code to autoPopulate a field.
Do you have teamviewer?
No, I don’t unfortunately.
Yes, it's the code to auto-populate a field.
This is what I did.
here is my email if you need more help hchapa@lrgvdc911.org
Email me and I give you my work number so you can see what I did.
Hector, you solution worked great! Thanks a lot.
The only thing that tripped me up was the placement of the code. In my case, the .connect functions were not firing until I moved them out of initEditor(evt) function. I put the onBeforeApplyEdits hook just before the .addLayers calls, and it worked perfectly.
Thanks again!
I am glad I could help. I have develop many applications and I created libraries for many of the questions I ask and I have solved. Please email me I provided my contact information I am glad to help in the future.
Can someone clarify inside of the sample provided where Hector's code goes? This would be hugely helpful!
Thanks!
I am adding a updated version of the code using AMD for anyone that is interested using. The one I provided was Legacy Dojo using dojo.connects.
I just wrote this five minutes ago. With this one you don't have to worry were the listener goes inside the function. This is a working exmaple.
The way it works once you click on the map to add a point then before apply edits executes and in there you tell javascript to edit a particular field automatic. It auto populates that field. Look for the listener that say before-apply-edits and I apply it to a particular attribute.
My Contact information:
email: hchapa@lrgvdc911.org
phone: 956-682-3481 ext. 143
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
<title>Edit rivers and waterbodies</title>
<link rel="stylesheet" href="https://js.arcgis.com/3.16/dijit/themes/claro/claro.css">
<link rel="stylesheet" href="https://js.arcgis.com/3.16/esri/css/esri.css">
<style>
html,body{height:100%;width:100%;margin:0;overflow:hidden;}
#map{
padding:0;
}
#header{
font-size: 1.1em;
font-family: sans-serif;
padding-left: 1em;
padding-top:4px;
color:#660000;
.templatePicker {
border: none;
.dj_ie .infowindow .window .top .right .user .content { position: relative; }
.dj_ie .simpleInfoWindow .content { position: relative; }
</style>
<script src="https://js.arcgis.com/3.16/"></script>
<script>
var map;
require([
"esri/map",
"esri/tasks/GeometryService",
"esri/layers/ArcGISTiledMapServiceLayer",
"esri/layers/FeatureLayer",
"esri/Color",
"esri/symbols/SimpleMarkerSymbol",
"esri/symbols/SimpleLineSymbol",
"esri/dijit/editing/Editor",
"esri/dijit/editing/TemplatePicker",
"esri/config",
"dojo/i18n!esri/nls/jsapi",
"dojo/_base/array", "dojo/parser", "dojo/keys",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane",
"dojo/domReady!"
], function(
Map, GeometryService,
ArcGISTiledMapServiceLayer, FeatureLayer,
Color, SimpleMarkerSymbol, SimpleLineSymbol,
Editor, TemplatePicker,
esriConfig, jsapiBundle,
arrayUtils, parser, keys
) {
parser.parse();
// snapping is enabled for this sample - change the tooltip to reflect this
jsapiBundle.toolbars.draw.start = jsapiBundle.toolbars.draw.start + "<br>Press <b>ALT</b> to enable snapping";
// refer to "Using the Proxy Page" for more information: https://developers.arcgis.com/javascript/3/jshelp/ags_proxy.html
esriConfig.defaults.io.proxyUrl = "/proxy/";
//This service is for development and testing purposes only. We recommend that you create your own geometry service for use within your applications.
esriConfig.defaults.geometryService = new GeometryService("https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
map = new Map("map", {
basemap: "satellite",
center: [-96.541, 38.351],
zoom: 14,
slider: false
});
map.on("layers-add-result", initEditor);
//add boundaries and place names
var labels = new ArcGISTiledMapServiceLayer("https://server.arcgisonline.com/ArcGIS/rest/services/Reference/World_Boundaries_and_Places/MapServer");
map.addLayer(labels);
var responsePoints = new FeatureLayer("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/0", {
mode: FeatureLayer.MODE_ONDEMAND,
outFields: ['*']
var responsePolys = new FeatureLayer("https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire/FeatureServer/2", {
map.addLayers([responsePolys, responsePoints]);
responsePoints.on("before-apply-edits", function(evt){
console.log(evt);
if(evt.adds[0])
{
//Here you choose which attribute to update...
evt.adds[0].attributes.description = "Testing this one out works fine";
function initEditor(evt) {
var templateLayers = arrayUtils.map(evt.layers, function(result){
return result.layer;
var templatePicker = new TemplatePicker({
featureLayers: templateLayers,
grouping: true,
rows: "auto",
columns: 3
}, "templateDiv");
templatePicker.startup();
var layers = arrayUtils.map(evt.layers, function(result) {
return { featureLayer: result.layer };
var settings = {
map: map,
templatePicker: templatePicker,
layerInfos: layers,
toolbarVisible: true,
createOptions: {
polylineDrawTools:[ Editor.CREATE_TOOL_FREEHAND_POLYLINE ],
polygonDrawTools: [ Editor.CREATE_TOOL_FREEHAND_POLYGON,
Editor.CREATE_TOOL_CIRCLE,
Editor.CREATE_TOOL_TRIANGLE,
Editor.CREATE_TOOL_RECTANGLE
]
},
toolbarOptions: {
reshapeVisible: true
};
var params = { settings: settings };
var myEditor = new Editor(params, 'editorDiv');
//define snapping options
var symbol = new SimpleMarkerSymbol(
SimpleMarkerSymbol.STYLE_CROSS,
15,
new SimpleLineSymbol(
SimpleLineSymbol.STYLE_SOLID,
new Color([255, 0, 0, 0.5]),
5
),
null
);
map.enableSnapping({
snapPointSymbol: symbol,
tolerance: 20,
snapKey: keys.ALT
myEditor.startup();
</script>
</head>
<body class="claro">
<div id="main" data-dojo-type="dijit/layout/BorderContainer" data-dojo-props="design:'headline'" style="height:width:100%;height:100%;">
<div data-dojo-type="dijit/layout/ContentPane" id="header" data-dojo-props="region:'top'">
Edit Hydrography
</div>
<div data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'left'" style="width: 300px;overflow:hidden;">
<div id="templateDiv"></div>
<div id="editorDiv"></div>
<div data-dojo-type="dijit/layout/ContentPane" id="map" data-dojo-props="region:'center'"></div>
</body>
</html>
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.