-
Notifications
You must be signed in to change notification settings - Fork 0
/
arcgis_feature.php
279 lines (209 loc) · 7.73 KB
/
arcgis_feature.php
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title> CRR </title>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<!-- CSS -->
<link type="text/css" rel="stylesheet" href="stylesheet.css"/>
<!-- JQuery -->
<script src="jquery-3.0.0.js" ></script>
<!-- API GisCloud -->
<script type="text/javascript" src="arcgis.js" ></script>
<link rel="stylesheet" href="https://js.arcgis.com/4.1/esri/css/main.css">
</head>
<body id="body">
<h2> População do Brasil - 2015</h2>
<div id="viewDiv" ></div>
<script> // Script para adicionar mapa
// faz a requisição do mapa
//"esri/widgets/Search",
require([
"esri/Map",
"esri/views/MapView",
"esri/widgets/Search",
"esri/layers/FeatureLayer",
"dojo/domReady!"
], function(Map, MapView, Search, FeatureLayer){
var map = new Map({
basemap: "gray" // streets, topo, satellite, gray, osm, terrain
});
var view = new MapView({
container: "viewDiv", // Reference to the scene div created in step 5
map: map, // Reference to the map object created before the scene
zoom: 5, // Sets the zoom level based on level of detail (LOD)
center: [-55, -15] // Sets the center point of view with lon/lat
});
// points to a hosted Feature Layer in ArcGIS Online
var fl = new FeatureLayer({
portalItem: { // autocasts as esri/portal/PortalItem
//id: "2f88bfd20e8c43019956c46e75084931"
}
});
map.add(fl); // adds the layer to the map
// adiciona botao de pesquisa no mapa
var searchWidget = new Search({ view: view });
view.ui.add(searchWidget, "top-right");
searchWidget.startup();
});
</script>
<br/><br/>
<div class="divSearch" >
<form id="inputData" action="municipios_2014.php">
<input class="button" type="submit" value="2014" />
<input class="button_disable"type="submit" value="2015" disabled="true" />
</form>
<br><br>
<input id="inputSearch" maxlength="54" type="text" name="text" size="42" placeholder="Por exempo: São Paulo, MG, 2109056">
<button class="button" id="buttonSearch" type="button" onclick="btnSearch()">Pesquisar</button>
<button class="button" id="buttonAll" type="button" onclick="connect()">Todos os resultados</button>
</div>
<br/><br/>
<script type="text/javascript">
// variaveis globais
var flag = 1; // verificar se o usuário está realizando a mesma busca
var content = ""; // conteúdo digitado pelo usuário para pesquisa
connect();
function connect(){
if( flag != 0 ){
flag = 0;
$.ajax({
url:'municipios_2015_bd.php',
complete: function (response) {
fncMunicipios(response.responseText);
},
error: function () {
alert('Error');
}
});
}
}
function fncMunicipios(response){
// verifica se tabela ja exista e limpa
var d = document.getElementById("div");
var cont = document.body.contains(d);
if( cont == false ){
var div = document.createElement("div");
div.setAttribute('id','div');
}else{
var div = document.getElementById("div");
div.innerHTML = "" ;
}
var res = response.split("#");
var sz = res.length;
var i=0;
var columns = 4;
var qtd = (sz-1)/columns;
if( qtd>0 ){
// cria elementos html
var table = document.createElement("table");
var tbody = document.createElement("tbody");
var center = document.createElement("center");
var br = document.createElement("p");
// atribui id aos elementos criados
center.setAttribute('id', 'center');
table.setAttribute('id','table');
// Tópicos da tabela
var tr = document.createElement("tr");
tr.setAttribute('id', 'tr');
var th = document.createElement("th");
th.appendChild(document.createTextNode( "Código IBGE" ));
tr.appendChild(th);
var th = document.createElement("th");
th.appendChild(document.createTextNode( "Município" ));
tr.appendChild(th);
var th = document.createElement("th");
th.appendChild(document.createTextNode( "Estado" ));
tr.appendChild(th);
var th = document.createElement("th");
th.appendChild(document.createTextNode( "População" ));
tr.appendChild(th);
tbody.appendChild(tr);
// monta a tabela html
while( i<(sz-2) ){
var tr = document.createElement("tr");
var td = document.createElement("td");
td.appendChild(document.createTextNode( res[i] ));
tr.appendChild(td);
i++;
var td = document.createElement("td");
td.appendChild(document.createTextNode( res[i] ));
tr.appendChild(td);
i++;
var td = document.createElement("td");
td.appendChild(document.createTextNode( res[i] ));
tr.appendChild(td);
i++;
var td = document.createElement("td");
td.appendChild(document.createTextNode( res[i] ));
tr.appendChild(td);
i++;
tbody.appendChild(tr);
}
table.appendChild(tbody);
div.appendChild(table);
center.appendChild(div);
center.appendChild(br);
document.body.appendChild(center);
// total de resultados
div.appendChild(br);
var p = document.createElement("p");
//p.setAttribute('id','para');
p.appendChild( document.createTextNode("Total de resultados: " + qtd) );
div.appendChild(p);
// Data dos dados
var p = document.createElement("p");
p.appendChild( document.createTextNode("Dados de 2015") );
div.appendChild(p);
}else{
var div = document.getElementById("div");
var p = document.createElement("p");
p.appendChild( document.createTextNode("Nenhum resultado encontrado") );
div.appendChild(p);
}
}
</script>
<script type="text/javascript"> // Script para pesquisar com enter
$(document).ready(function(){
$('#inputSearch').keypress(function(e){
if(e.keyCode==13)
$('#buttonSearch').click();
});
});
</script>
<script type="text/javascript">
function btnSearch(){ // funcao pesquisar
var inputSearch = document.getElementById("inputSearch");
if( flag!=1 || content!=inputSearch.value ){
flag = 1;
if( inputSearch.value != "" ){
// atualiza o placeholder
var msg = "Por exempo: São Paulo, MG, 2109056";
inputSearch.placeholder = msg;
// elimina espaços antes e depois, se houver
var value = (inputSearch.value).trim();
$.ajax({
url:'municipios_2015_search.php',
method: "post",
data: {text: value},
complete: function (response) {
fncMunicipios(response.responseText);
},
error: function () {
alert('Error');
}
});
}else{
// atualiza o placeholder se usuario ñao digitar nada
var msg = "Digite algo para pesquisar";
inputSearch.placeholder = msg;
}
}
// atualiza content
content = inputSearch.value;
}
</script>
</body>
</html>