forked from NoashX/NoashX.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queryable.html
176 lines (156 loc) · 7.04 KB
/
queryable.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
<!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>Broken Query Example</title>
<link rel="stylesheet" href="http://js.arcgis.com/3.9/js/dojo/dijit/themes/tundra/tundra.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.9/js/dojo/dojox/grid/resources/Grid.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.9/js/dojo/dojox/grid/resources/tundraGrid.css">
<link rel="stylesheet" href="http://js.arcgis.com/3.9/js/esri/css/esri.css">
<style>
html, body, #mapDiv {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
body {
background-color:#777;
overflow:hidden;
font-family: "Trebuchet MS";
}
#header {
background-color:#444;
color:orange;
font-size:15pt;
text-align:center;
font-weight:bold;
}
#footer {
background-color:#444;
color:orange;
font-size:10pt;
text-align:center;
}
</style>
<script>dojoConfig = { parseOnLoad:true };</script>
<script src="http://js.arcgis.com/3.9/"></script>
<script language="Javascript">
var map, wellFeatureLayer, toolbar, grid, store;
require([
"esri/map",
"esri/layers/FeatureLayer", "esri/layers/ArcGISDynamicMapServiceLayer",
"esri/tasks/query", "esri/tasks/QueryTask", "esri/tasks/RelationshipQuery",
"esri/toolbars/draw",
"dojox/grid/DataGrid", "dojo/data/ItemFileReadStore",
"esri/layers/ImageParameters",
"dojo/on", "esri/geometry/Extent",
"esri/symbols/SimpleMarkerSymbol",
"esri/InfoTemplate",
"dijit/layout/BorderContainer", "dijit/layout/ContentPane", "dojo/domReady!"
], function(
Map,
FeatureLayer, DynamicMapServiceLayer,
Query, QueryTask, RelationshipQuery,
Draw,
DataGrid, ItemFileReadStore,
ImageParameters,
On, Extent,
SimpleMarkerSymbol,
InfoTemplate
) {
map = new Map("mapDiv", {
basemap: "satellite",
center: [-97.395, 37.537],
zoom: 11
});
var imageParams = new ImageParameters();
imageParams.layerIds = [0,1];
imageParams.layerOption = ImageParameters.LAYER_OPTION_SHOW;
var dynamicLayer = new DynamicMapServiceLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer", {imageParameters:imageParams});
map.addLayer(dynamicLayer);
var selectionSymbol = new SimpleMarkerSymbol().setColor("red");
wellFeatureLayer = new FeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSPetro/MapServer/0", {
mode: FeatureLayer.MODE_SELECTION,
infoTemplate: new InfoTemplate("Well: ${API_WELL_N}","${*}")
});
wellFeatureLayer.setSelectionSymbol(selectionSymbol);
//dojo.connect(wellFeatureLayer, "onSelectionComplete", findRelatedRecords); //returns array of objects
wellFeatureLayer.on("selection-complete", findRelatedRecords); //returns object, with a parameter that is an array of objects
map.addLayer(wellFeatureLayer);
//dojo.connect(map, "onClick", findWells); //old style of events
map.on("click", findWells);
//function findRelatedRecords(features) {
function findRelatedRecords(features) {
var relatedTopsQuery = new RelationshipQuery();
relatedTopsQuery.outFields = ["*"];
relatedTopsQuery.relationshipId = 3;
//relatedTopsQuery.objectIds = [features[0].attributes.OBJECTID];
relatedTopsQuery.objectIds = [features.features[0].attributes.OBJECTID];
wellFeatureLayer.queryRelatedFeatures(relatedTopsQuery, function(relatedRecords) {
console.log("related recs: ", relatedRecords);
//if ( ! relatedRecords.hasOwnProperty(features[0].attributes.OBJECTID) ) {
if ( ! relatedRecords.hasOwnProperty(features.features[0].attributes.OBJECTID) ) {
//console.log("No related records for ObjectID: ", features[0].attributes.OBJECTID);
console.log("No related records for ObjectID: ", features.features[0].attributes.OBJECTID);
return;
}
//var fset = relatedRecords[features[0].attributes.OBJECTID];
var fset = relatedRecords[features.features[0].attributes.OBJECTID];
//var items = dojo.map(fset.features, function(feature) {
var items = dojo.map(fset.features, function(feature) {
return feature.attributes;
});
//Create data object to be used in store
var data = {
identifier: "OBJECTID", //This field needs to have unique values
label: "OBJECTID", //Name field for display. Not pertinent to a grid but may be used elsewhere.
items: items
};
//Create data store and bind to grid.
store = new ItemFileReadStore({ data:data });
grid.setStore(store);
grid.setQuery({ OBJECTID: '*' });
});
}
function findWells(evt) {
grid.setStore(null);
var selectionQuery = new Query();
var tol = map.extent.getWidth()/map.width * 5;
var x = evt.mapPoint.x;
var y = evt.mapPoint.y;
var queryExtent = new Extent(x-tol,y-tol,x+tol,y+tol,evt.mapPoint.spatialReference);
selectionQuery.geometry = queryExtent;
wellFeatureLayer.selectFeatures(selectionQuery,FeatureLayer.SELECTION_NEW);
}
});
</script>
</head>
<body class="tundra">
<!--TOPMOST LAYOUT CONTAINER-->
<div id="mainWindow" data-dojo-type="dijit.layout.BorderContainer" data-dojo-props="design:'headline',gutters:false" style="width:100%; height:100%;">
<!--HEADER SECTION-->
<div id="header" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'top'" style="height:75px;">
Click on a well to select the well and select the related well log information for that well.
</div>
<!--CENTER SECTION-->
<!--CENTER CONTAINER-->
<div id="mapDiv" data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'center'" style="margin:5px;">
</div>
<!--RIGHT CONTAINER-->
<div data-dojo-type="dijit.layout.ContentPane" data-dojo-props="region:'right'" style="width:400px;margin:5px;background-color:whitesmoke;">
<table data-dojo-type="dojox.grid.DataGrid" jsid="grid" id="grid" data-dojo-props="rowsPerPage:'5', rowSelector:'20px'" style="height:300px; width:200px">
<thead>
<tr>
<th field="OBJECTID">ID</th>
<th field="ELEVATION">Elevation</th>
<th field="FORMATION">Formation</th>
<th field="TOP">Top</th>
</tr>
</thead>
</table>
</div>
</div>
</body>
</html>