Select to view content in your preferred language

does someone know why my rectangle update always crashes?

436
1
03-20-2019 01:17 AM
WwLl
by
Emerging Contributor

i can draw a rectangle, but when i click on him and want to update the size or move it the whole page crashes. 

when i start the update state i get the Error: Uncaught TypeError: Cannot read property 'geometry' of undefined.

And i dont know why

var bibiPunkteView; //für highlight
view.whenLayerView(bibiPunkte)
.then(function (layerView) {
console.log(layerView);
bibiPunkteView = layerView;
})
.catch(function (error) {
console.error(error);
});

//-----Popup-Fenster-------------------------------------------------------------------------------
view.when(function () {

view.on("pointer-move", showCoordinates); //Anzeigen wenn sich maus bewegt

bibiBasemap.when(function () {
view.goTo(bibiBasemap.fullExtent); //auf Bibi

});

//-----Rectangle-Draw---------------------------------------------------------------------------
const polygonSymbol = {
type: "simple-fill",
color: [255, 0, 0, 0.1],
style: "solid",
outline: {
color: "black",
width: 1
}
};

const sketchViewModel = new SketchViewModel({
view: view,
layer: graphicslayer,
polygonSymbol
});

var rectanglebutton = document.getElementById("rectangle-button");
rectanglebutton.onclick = function () {
sketchViewModel.create("rectangle");
graphicslayer.removeAll(event.graphic);
if (highlight) {
highlight.remove();
}
};

sketchViewModel.on("create", function (event) {
if (event.state == "complete") {
drawCompleted(event.graphic)
}
if (event.state == "start") {
if (highlight) {
highlight.remove();
}

}

sketchViewModel.on("update", function (event) {
if (event.state == "start" || event.state == "complete") {

if (highlight) {
highlight.remove();
}

drawCompleted(event.graphic);

}

});

});
function drawCompleted(graphic) {
//graphicslayer.removeAll(event.graphic);
selectFeatures(graphic);
}
//-----Rectangle-Draw------------------------------------------------------------------------------

//-----Query---------------------------------------------------------------------------------------
var highlight;

function selectFeatures(graphic) {
var query = new Query({
geometry: graphic.geometry,
spatialRelationship: "esriSpatialRelIntersects", //Abfrage mit Intersect
outFields: ["*"],
returnGeometry: true //damit ich sie darstellen kann
});

bibiPunkte.queryFeatures(query).then(function (results) {

if (highlight) { //wenn Punkte davor schon angeziegt werden, wenn nicht dann unnötig
highlight.remove();
}
highlight = bibiPunkteView.highlight(results.features);
console.log(results.features);

var pointsymbol = { //Für die Punkte die im Bereich sind
type: "simple-marker",
style: "circle",
color: "blue",
size: "6px",
};

var resulttable = window.opener.document.getElementById("tbody"); //aus Auskunft holen

while (resulttable.firstChild) resulttable.removeChild(resulttable.firstChild); //leeren des tbody

array.forEach(results.features, function (feature) { //um alle Punkte auszugeben
console.log(feature.geometry);

var graphic1 = new Graphic({ //das sind die Punkte
geometry: feature.geometry,
symbol: pointsymbol
});

graphicslayer.add(graphic1);

var trObject = domConstruct.create("tr", null, resulttable); //eine Zeile erstellen
var checkbox = new CheckBox({
name: "checkbox",
value: feature.attributes.ID,
checked: false
});

domConstruct.create("td", { innerHTML: feature.attributes.OBJECTID }, trObject); //Daten für Zeile
domConstruct.create("td", { innerHTML: feature.attributes.ID }, trObject);
domConstruct.create("td", { innerHTML: feature.geometry.x.toFixed() }, trObject);
domConstruct.create("td", { innerHTML: feature.geometry.y.toFixed() }, trObject);
domConstruct.create("td", { innerHTML: feature.attributes.URL }, trObject);
var check = domConstruct.toDom("<td>"+checkbox.domNode.innerHTML+"</td>");//HTML rausgeholt für checkbox
domConstruct.place(check, trObject); //amit checkbox darstellen
});

// var resultOBJECTID = results.features[0].attributes.OBJECTID;
// window.opener.document.getElementById("OBJECTID").value = resultOBJECTID;
});
}
//-----Query---------------------------------------------------------------------------------------

});
//-----Popup-Fenster-----------------------------------------------------------------------------------
0 Kudos
1 Reply
JonathanUihlein
Esri Regular Contributor

Hi there.

I'm having trouble recreating your issue in a test app, there's a bit too much missing code. 

Can you provide a working example of your issue using something like jsbin?

Thanks very much.