I am trying to get the area of a polygon and divide that by 16.94 ft^2. I have plugged in a Template I found. I am missing something. I am trying to get the template and my original code to talk. That way when I draw a polygon the area is outputted along with the original function of finding the average of the point values within.
UPDATE:The error I keep getting is: "TypeError: Cannot read property '0' of undefinedmessage: "Cannot read property '0' of undefined"stack: (...)get stack: function () { [native code] }set stack: function () { [native code] }proto: Error "TypeError: Cannot read property '0' of undefined"
define(['dojo/_base/declare','dijit/_WidgetBase','dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin','esri/toolbars/draw','esri/InfoTemplate','esri/layers/FeatureLayer','esri/symbols/SimpleMarkerSymbol','esri/symbols/SimpleLineSymbol','esri/Color','esri/tasks/query','dijit/form/Button','dojo/_base/lang','dojo/on','dojo/_base/array','dojo/dom','dojo/text!./Select/templates/Select.html',"esri/graphicsUtils", "esri/tasks/GeometryService","esri/tasks/AreasAndLengthsParameters",'xstyle/css!./Select/css/Select.css' ,"esri/geometry/Extent", "esri/SpatialReference", "esri/symbols/SimpleFillSymbol", "esri/units", "esri/geometry/webMercatorUtils", "esri/geometry/geodesicUtils", "esri/geometry/Polyline", "esri/dijit/Scalebar", "dojo/json", "esri/config", "esri/map", "esri/graphic", "esri/geometry/Geometry"], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, Draw, InfoTemplate, FeatureLayer, SimpleMarkerSymbol, SimpleLineSymbol, Color, Query, Button, lang, on, arrayUtil, dom, SelectTemplate, graphicsUtils, GeometryService,AreasAndLengthsParameters, css,Extent, SpatialReference, SimpleFillSymbol, Units, webMercatorUtils, geodesicUtils, Polyline, Scalebar, json, esriConfig, Map, Graphic, Geometry) { return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { widgetsInTemplate: true, templateString: SelectTemplate, selectTools: null, postCreate: function () { this.selectTools = new Draw(this.map); this.selectQuery = new Query(); on(this.selectTools, "DrawEnd", lang.hitch(this, function (geometry) { this.selectTools.deactivate(); this.selectQuery.geometry = geometry; this.featureLayer.selectFeatures(this.selectQuery, FeatureLayer.SELECTION_NEW); }));this.fieldsSelectionSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([0,0,0]), 1),new Color([0,0,0,0.5])); var content = "Status: ${STATUS}" + "
Cumulative Gas: ${CUMM_GAS} MCF" + "
Total Acres: ${APPROXACRE}" + "
Avg. Field Depth: ${AVG_DEPTH} meters"; var infoTemplate = new InfoTemplate("${grid_code}", content); this.map.on("load", function () { var tb = new Draw(map); tb.on("selection-complete", lang.hitch(map, getAreaAndLength)); tb.activate(Draw.FREEHAND_POLYGON); }); var geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.on("selection-complete", outputAreaAndLength); function getAreaAndLength(event) { var map = this, geometry = event.geometry; var graphic = map.graphics.add(new Graphic(geometry, new SimpleFillSymbol())); var geom = webMercatorUtils.webMercatorToGeographic(geometry); var areas = geodesicUtils.geodesicAreas([geom], Units.ACRES); var polyline = new Polyline(geom.spatialReference); polyline.paths = geom.rings; var lengths = geodesicUtils.geodesicLengths([polyline], Units.FEET); dom.byId("area").innerHTML = areas[0].toFixed(3) + " acres"; dom.byId("length").innerHTML = lengths[0].toFixed(3) + " feet"; //setup the parameters for the areas and lengths operation var areasAndLengthParams = new AreasAndLengthsParameters(); areasAndLengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_FOOT; areasAndLengthParams.areaUnit = esri.tasks.GeometryService.UNIT_ACRES; geometryService.simplify([geometry], function (simplifiedGeometries) { areasAndLengthParams.polygons = simplifiedGeometries; geometryService.areasAndLengths(areasAndLengthParams); }); } function outputAreaAndLength(event) { var result = event.result; console.log(json.stringify(result)); dom.byId("area").innerHTML += "
Server: " + result.areas[0].toFixed(3) + " acres"; dom.byId("length").innerHTML += "
Server: " + result.lengths[0].toFixed(3) + " feet"; } var infoTemplate = new InfoTemplate(this.title, content); this.featureLayer = new FeatureLayer(this.featureLayerURL, { mode: FeatureLayer.MODE_SELECTION, infoTemplate: infoTemplate, outFields: ["*"] }); this.featureLayer.setDefinitionExpression(this.defExpress); this.featureLayer.setSelectionSymbol(this.fieldsSelectionSymbol); this.featureLayer.on("selection-complete", lang.hitch(this, 'avgGasProduction')); var clearMsg = this.clearSelectMsg; this.featureLayer.on("selection-clear", function () { dom.byId('messages').innerHTML = "" + clearMsg + ""; }); this.map.addLayer(this.featureLayer); }, select: function () { this.selectTools.activate(Draw.FREEHAND_POLYGON); }, clearSelection: function () { this.featureLayer.clearSelection(); }, avgGasProduction: function (event) { var productionSum = 0, productionAvg = 0; var sumField = this.fieldToSum; arrayUtil.forEach(event.features, function (feature) { productionSum += feature.attributes[sumField]; }); if (event.features && event.features.length > 0) { productionAvg = Math.round(productionSum / event.features.length) } dom.byId('messages').innerHTML = "" + this.selectSumMsgPrefix + " " + productionAvg + " " + this.selectSumUnits + ". "; this.map.infoWindow.setTitle("Average Solar Potential") this.map.infoWindow.setContent("Selected Area Potential: " + productionAvg + " KWh/(m^2). "); var gExt = graphicsUtils.graphicsExtent(event.features); this.map.infoWindow.show(gExt.getCenter()); dom.byId("area").innerHTML = areas[0].toFixed(3) + " acres"; } });});
أكثر...
UPDATE:The error I keep getting is: "TypeError: Cannot read property '0' of undefinedmessage: "Cannot read property '0' of undefined"stack: (...)get stack: function () { [native code] }set stack: function () { [native code] }proto: Error "TypeError: Cannot read property '0' of undefined"
define(['dojo/_base/declare','dijit/_WidgetBase','dijit/_TemplatedMixin','dijit/_WidgetsInTemplateMixin','esri/toolbars/draw','esri/InfoTemplate','esri/layers/FeatureLayer','esri/symbols/SimpleMarkerSymbol','esri/symbols/SimpleLineSymbol','esri/Color','esri/tasks/query','dijit/form/Button','dojo/_base/lang','dojo/on','dojo/_base/array','dojo/dom','dojo/text!./Select/templates/Select.html',"esri/graphicsUtils", "esri/tasks/GeometryService","esri/tasks/AreasAndLengthsParameters",'xstyle/css!./Select/css/Select.css' ,"esri/geometry/Extent", "esri/SpatialReference", "esri/symbols/SimpleFillSymbol", "esri/units", "esri/geometry/webMercatorUtils", "esri/geometry/geodesicUtils", "esri/geometry/Polyline", "esri/dijit/Scalebar", "dojo/json", "esri/config", "esri/map", "esri/graphic", "esri/geometry/Geometry"], function (declare, _WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin, Draw, InfoTemplate, FeatureLayer, SimpleMarkerSymbol, SimpleLineSymbol, Color, Query, Button, lang, on, arrayUtil, dom, SelectTemplate, graphicsUtils, GeometryService,AreasAndLengthsParameters, css,Extent, SpatialReference, SimpleFillSymbol, Units, webMercatorUtils, geodesicUtils, Polyline, Scalebar, json, esriConfig, Map, Graphic, Geometry) { return declare([_WidgetBase, _TemplatedMixin, _WidgetsInTemplateMixin], { widgetsInTemplate: true, templateString: SelectTemplate, selectTools: null, postCreate: function () { this.selectTools = new Draw(this.map); this.selectQuery = new Query(); on(this.selectTools, "DrawEnd", lang.hitch(this, function (geometry) { this.selectTools.deactivate(); this.selectQuery.geometry = geometry; this.featureLayer.selectFeatures(this.selectQuery, FeatureLayer.SELECTION_NEW); }));this.fieldsSelectionSymbol = new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_CIRCLE, 10,new SimpleLineSymbol(SimpleLineSymbol.STYLE_SOLID,new Color([0,0,0]), 1),new Color([0,0,0,0.5])); var content = "Status: ${STATUS}" + "
Cumulative Gas: ${CUMM_GAS} MCF" + "
Total Acres: ${APPROXACRE}" + "
Avg. Field Depth: ${AVG_DEPTH} meters"; var infoTemplate = new InfoTemplate("${grid_code}", content); this.map.on("load", function () { var tb = new Draw(map); tb.on("selection-complete", lang.hitch(map, getAreaAndLength)); tb.activate(Draw.FREEHAND_POLYGON); }); var geometryService = new GeometryService("http://tasks.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer"); geometryService.on("selection-complete", outputAreaAndLength); function getAreaAndLength(event) { var map = this, geometry = event.geometry; var graphic = map.graphics.add(new Graphic(geometry, new SimpleFillSymbol())); var geom = webMercatorUtils.webMercatorToGeographic(geometry); var areas = geodesicUtils.geodesicAreas([geom], Units.ACRES); var polyline = new Polyline(geom.spatialReference); polyline.paths = geom.rings; var lengths = geodesicUtils.geodesicLengths([polyline], Units.FEET); dom.byId("area").innerHTML = areas[0].toFixed(3) + " acres"; dom.byId("length").innerHTML = lengths[0].toFixed(3) + " feet"; //setup the parameters for the areas and lengths operation var areasAndLengthParams = new AreasAndLengthsParameters(); areasAndLengthParams.lengthUnit = esri.tasks.GeometryService.UNIT_FOOT; areasAndLengthParams.areaUnit = esri.tasks.GeometryService.UNIT_ACRES; geometryService.simplify([geometry], function (simplifiedGeometries) { areasAndLengthParams.polygons = simplifiedGeometries; geometryService.areasAndLengths(areasAndLengthParams); }); } function outputAreaAndLength(event) { var result = event.result; console.log(json.stringify(result)); dom.byId("area").innerHTML += "
Server: " + result.areas[0].toFixed(3) + " acres"; dom.byId("length").innerHTML += "
Server: " + result.lengths[0].toFixed(3) + " feet"; } var infoTemplate = new InfoTemplate(this.title, content); this.featureLayer = new FeatureLayer(this.featureLayerURL, { mode: FeatureLayer.MODE_SELECTION, infoTemplate: infoTemplate, outFields: ["*"] }); this.featureLayer.setDefinitionExpression(this.defExpress); this.featureLayer.setSelectionSymbol(this.fieldsSelectionSymbol); this.featureLayer.on("selection-complete", lang.hitch(this, 'avgGasProduction')); var clearMsg = this.clearSelectMsg; this.featureLayer.on("selection-clear", function () { dom.byId('messages').innerHTML = "" + clearMsg + ""; }); this.map.addLayer(this.featureLayer); }, select: function () { this.selectTools.activate(Draw.FREEHAND_POLYGON); }, clearSelection: function () { this.featureLayer.clearSelection(); }, avgGasProduction: function (event) { var productionSum = 0, productionAvg = 0; var sumField = this.fieldToSum; arrayUtil.forEach(event.features, function (feature) { productionSum += feature.attributes[sumField]; }); if (event.features && event.features.length > 0) { productionAvg = Math.round(productionSum / event.features.length) } dom.byId('messages').innerHTML = "" + this.selectSumMsgPrefix + " " + productionAvg + " " + this.selectSumUnits + ". "; this.map.infoWindow.setTitle("Average Solar Potential") this.map.infoWindow.setContent("Selected Area Potential: " + productionAvg + " KWh/(m^2). "); var gExt = graphicsUtils.graphicsExtent(event.features); this.map.infoWindow.show(gExt.getCenter()); dom.byId("area").innerHTML = areas[0].toFixed(3) + " acres"; } });});
أكثر...