I created a tree and it is populating duplicate records. Here is a screenshot:
The records correspond to the amount of features identified. here is the code:
if (map.getLayer("waterResources").visibleLayers.length > 0) {
//Water
var idWaterTask = new IdentifyTask(urlWaterResources);
var idWaterParams = new IdentifyParameters();
idWaterParams.tolerance = 1.2;
idWaterParams.returnGeometry = false;
//idWaterParams.spatialReference = map.spatialReference;
idWaterParams.layerIds = map.getLayer("waterResources").visibleLayers;
idWaterParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
idWaterParams.mapExtent = map.extent;
idWaterParams.geometry = inPnt;
waterResources = idWaterTask.execute(idWaterParams, function (result) {
for (var i = 0; i < result.length; i++) {
if (result.layerName === "SEO Wells (zoom in for points)") {
var layerName1 = result.layerName;
var layerName2 = result.value;
if (document.getElementById(layerName1 + 'CB').checked === true) {
myData.push({id: layerName1, name: "SEO Well - " + layerName2, parent: 'All', children: true});
//Convert features object into array to pass to for each to process
for (var key in result.feature.attributes) {
if (result.feature.attributes.hasOwnProperty(key)) {
if (key === "OBJECTID" || key === "Shape_Leng" || key === "OBJECTID_1" || key === "Shape") {
} else {
var k = key;
var v = result.feature.attributes[key];
if (k === "Hyperlink" || k === "URL") {
myData.push({id: k + v, name: k + " - " + "<i><u>Click here for more information</u></i>", url: v, children: false, parent: layerName1});
}
else {
myData.push({id: k + v, name: k + " - " + "<i>" + v + "</i>", children: false, parent: layerName1});
}
}
}
}
}
}
Solved! Go to Solution.
solution:
i solved this problem by creating a unique id (line 23):
if (map.getLayer("waterResources").visibleLayers.length > 0) {
//Water
var idWaterTask = new IdentifyTask(urlWaterResources);
var idWaterParams = new IdentifyParameters();
idWaterParams.tolerance = 1.2;
idWaterParams.returnGeometry = true;
//idWaterParams.spatialReference = map.spatialReference;
idWaterParams.layerIds = map.getLayer("waterResources").visibleLayers;
idWaterParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
idWaterParams.mapExtent = map.extent;
idWaterParams.geometry = inPnt;
waterResources = idWaterTask.execute(idWaterParams, function (result) {
if (result.length > 0) {
var LayerNameMain = "Water layers";
myData.push({id: LayerNameMain, name: LayerNameMain, parent: 'All', children: true});
for (var i = 0; i < result.length; i++) {
if (result.layerName === "SEO Wells (zoom in for points)") {
var layerTitle = result.layerName;
var layerName1 = result.layerName + result.value; //unique ID so no duplicates
var layerName2 = result.value;
if (document.getElementById(layerTitle + 'CB').checked === true) {
myData.push({id: layerName1, name: "SEO Well - " + layerName2, parent: LayerNameMain, children: true});
//Convert features object into array to pass to for each to process
for (var key in result.feature.attributes) {
if (result.feature.attributes.hasOwnProperty(key)) {
if (key === "OBJECTID" || key === "Shape_Leng" || key === "OBJECTID_1" || key === "Shape") {
} else {
var k = key;
var v = result.feature.attributes[key];
if (k === "Hyperlink" || k === "URL") {
myData.push({id: k + v, name: k + " - " + "<i><u>Click here for more information</u></i>", url: v, children: false, parent: layerName1});
}
else {
myData.push({id: k + v, name: k + " - " + "<i>" + v + "</i>", children: false, parent: layerName1});
}
}
}
}
}
changeTab();
}
}
}
});
}
solution:
i solved this problem by creating a unique id (line 23):
if (map.getLayer("waterResources").visibleLayers.length > 0) {
//Water
var idWaterTask = new IdentifyTask(urlWaterResources);
var idWaterParams = new IdentifyParameters();
idWaterParams.tolerance = 1.2;
idWaterParams.returnGeometry = true;
//idWaterParams.spatialReference = map.spatialReference;
idWaterParams.layerIds = map.getLayer("waterResources").visibleLayers;
idWaterParams.layerOption = IdentifyParameters.LAYER_OPTION_ALL;
idWaterParams.mapExtent = map.extent;
idWaterParams.geometry = inPnt;
waterResources = idWaterTask.execute(idWaterParams, function (result) {
if (result.length > 0) {
var LayerNameMain = "Water layers";
myData.push({id: LayerNameMain, name: LayerNameMain, parent: 'All', children: true});
for (var i = 0; i < result.length; i++) {
if (result.layerName === "SEO Wells (zoom in for points)") {
var layerTitle = result.layerName;
var layerName1 = result.layerName + result.value; //unique ID so no duplicates
var layerName2 = result.value;
if (document.getElementById(layerTitle + 'CB').checked === true) {
myData.push({id: layerName1, name: "SEO Well - " + layerName2, parent: LayerNameMain, children: true});
//Convert features object into array to pass to for each to process
for (var key in result.feature.attributes) {
if (result.feature.attributes.hasOwnProperty(key)) {
if (key === "OBJECTID" || key === "Shape_Leng" || key === "OBJECTID_1" || key === "Shape") {
} else {
var k = key;
var v = result.feature.attributes[key];
if (k === "Hyperlink" || k === "URL") {
myData.push({id: k + v, name: k + " - " + "<i><u>Click here for more information</u></i>", url: v, children: false, parent: layerName1});
}
else {
myData.push({id: k + v, name: k + " - " + "<i>" + v + "</i>", children: false, parent: layerName1});
}
}
}
}
}
changeTab();
}
}
}
});
}