Commit 03835f579ddca3b5ea4d65fcbf8137fa4504f8bc

Authored by Edmar Moretti
1 parent a527e229

JSONP no serviço json.php

ferramentas/recline/default.php
... ... @@ -12,13 +12,14 @@
12 12 <link href="../../pacotes/knightlab/recline/vendor/leaflet.markercluster/MarkerCluster.css" rel="stylesheet">
13 13 <link href="../../pacotes/knightlab/recline/vendor/leaflet.markercluster/MarkerCluster.Default.css" rel="stylesheet">
14 14 <link rel="stylesheet" href="../../pacotes/knightlab/recline/vendor/slickgrid/2.2/slick.grid.css">
  15 + <link rel="stylesheet" href="../../pacotes/knightlab/recline/vendor/timeline/css/timeline.css">
15 16  
16 17 <!-- recline css -->
17 18 <link href="../../pacotes/knightlab/recline/css/map.css" rel="stylesheet">
18   -
19 19 <link href="../../pacotes/knightlab/recline/css/multiview.css" rel="stylesheet">
20 20 <link href="../../pacotes/knightlab/recline/css/slickgrid.css"rel="stylesheet">
21 21 <link href="../../pacotes/knightlab/recline/css/flot.css" rel="stylesheet">
  22 + <link rel="stylesheet" href="../../pacotes/knightlab/recline/css/timeline.css">
22 23  
23 24 <!-- Vendor JS - general dependencies -->
24 25 <script src="../../pacotes/knightlab/recline/vendor/jquery/1.7.1/jquery.js" type="text/javascript"></script>
... ... @@ -34,6 +35,8 @@
34 35 <script type="text/javascript" src="../../pacotes/knightlab/recline/vendor/flot/jquery.flot.js"></script>
35 36 <script type="text/javascript" src="../../pacotes/knightlab/recline/vendor/flot/jquery.flot.time.js"></script>
36 37 <script type="text/javascript" src="../../pacotes/knightlab/recline/vendor/moment/2.0.0/moment.js"></script>
  38 + <script type="text/javascript" src="../../pacotes/knightlab/recline/vendor/timeline/js/timeline.js"></script>
  39 +
37 40 <script src="../../pacotes/knightlab/recline/vendor/slickgrid/2.2/jquery-ui-1.8.16.custom.min.js"></script>
38 41 <script src="../../pacotes/knightlab/recline/vendor/slickgrid/2.2/jquery.event.drag-2.2.js"></script>
39 42 <script src="../../pacotes/knightlab/recline/vendor/slickgrid/2.2/jquery.event.drop-2.2.js"></script>
... ... @@ -63,45 +66,38 @@
63 66 <div class="data-explorer-here"></div>
64 67 <div style="clear: both;"></div>
65 68  
  69 +
66 70 <script>
67   - jQuery(function($) {
68   - window.multiView = null;
69   - window.explorerDiv = $('.data-explorer-here');
  71 +//define como variavel global
  72 +var dadosJ;
  73 +returnData = function(dataFromJsonp){
  74 + dadosJ = dataFromJsonp;
  75 + jQuery(function($) {
  76 + window.multiView = null;
  77 + window.explorerDiv = $('.data-explorer-here');
70 78  
71   - // create the demo dataset
72   - var dataset = createDataset();
73   - // now create the multiview
74   - // this is rather more elaborate than the minimum as we configure the
75   - // MultiView in various ways (see function below)
76   - window.multiview = createMultiView(dataset);
  79 + // create the demo dataset
  80 + var dataset = createDataset(dadosJ);
  81 + // now create the multiview
  82 + // this is rather more elaborate than the minimum as we configure the
  83 + // MultiView in various ways (see function below)
  84 + window.multiview = createMultiView(dataset);
77 85  
78   - // last, we'll demonstrate binding to changes in the dataset
79   - // this will print out a summary of each change onto the page in the
80   - // changelog section
81   - dataset.records.bind('all', function(name, obj) {
82   - var $info = $('<div />');
83   - $info.html(name + ': ' + JSON.stringify(obj.toJSON()));
84   - $('.changelog').append($info);
85   - $('.changelog').show();
86   - });
87   -});
  86 + // last, we'll demonstrate binding to changes in the dataset
  87 + // this will print out a summary of each change onto the page in the
  88 + // changelog section
  89 + dataset.records.bind('all', function(name, obj) {
  90 + var $info = $('<div />');
  91 + $info.html(name + ': ' + JSON.stringify(obj.toJSON()));
  92 + $('.changelog').append($info);
  93 + $('.changelog').show();
  94 + });
  95 + });
  96 +};
88 97  
89 98 // create standard demo dataset
90   -function createDataset() {
91   - var dataset = new recline.Model.Dataset(
92   - <?php
93   - $format = "gdocs";
94   - include("../../json.php");
95   - /*
96   - $curl = curl_init();
97   - curl_setopt ($curl, CURLOPT_URL, "../../json.php?tema=_lreal&format=recline&");
98   - curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
99   - $result = curl_exec($curl);
100   - curl_close ($curl);
101   - echo $result;
102   - */
103   - ?>
104   - );
  99 +function createDataset(data) {
  100 + var dataset = new recline.Model.Dataset(data);
105 101 return dataset;
106 102 }
107 103  
... ... @@ -172,8 +168,12 @@ var createMultiView = function(dataset, state) {
172 168 return multiView;
173 169 }
174 170  
175   -
176   - </script>
  171 +</script>
  172 + <?php
  173 + //inclui os dados via jsonp
  174 + $url = "../../json.php?tema=".strip_tags($_GET["tema"])."&format=gdocs&jsonp=returnData";
  175 + echo "<script src='$url' ></script>";
  176 + ?>
177 177 </div>
178 178 </body>
179 179 </html>
... ...
json.php
1 1 <?php
  2 +//TODO incluir BBOX na obtencao dos dados
  3 +//TODO gerar dados para id_medida_variavel
2 4 /*
3 5 Title: Gerador de dados JSON
4 6  
... ... @@ -28,13 +30,11 @@ Arquivo: i3geo/ogc.php
28 30  
29 31 Par&acirc;metros:
30 32  
31   -ajuda - (opcional) mostra uma ajuda ao usu&aacute;rio
  33 +tema - nome do tema existente em i3geo/temas ou na pasta temporaria do mapserver
32 34  
33   -tema - (opcional) nome do tema que ser&aacute; mostrado no servi&ccedil;o. Se for definido, o web service conter&aacute; apenas esse tema. O tema &eacute; o nome do mapfile existente em i3geo/temas, mas pode ser especificado um mapfile existente em outra pasta. Nesse caso, deve-se especificar o caminho completo para o arquivo. Se n&atilde;o for definido, ser&atilde;o considerados todos os temas
  35 +format - storymap|gdocs
34 36  
35   -format - (opcional) pode ser utilizado a op&ccedil;&atilde;o &format=application/openlayers para
36   -abrir o mashup do OpenLayers com as camadas definida em temas.
37   -Na gera&ccedil;&atilde;o da legenda pode ser utilizado text/html para gerar no formato html.
  37 +No caso de storymap, o fornecimento dos dados depende dos parametros definidos no METADATA storymap existente no tema
38 38  
39 39 */
40 40 $_GET = array_merge($_GET,$_POST);
... ... @@ -42,13 +42,6 @@ include(dirname(__FILE__).&quot;/ms_configura.php&quot;);
42 42 include(dirname(__FILE__)."/classesphp/pega_variaveis.php");
43 43 include(dirname(__FILE__)."/classesphp/funcoes_gerais.php");
44 44 //
45   -//imprime na tela a ajuda
46   -//
47   -if(isset($ajuda)){
48   - imprimeAjuda();
49   - exit;
50   -}
51   -//
52 45 //pega os enderecos para compor a url de chamada do gerador de web services
53 46 //
54 47 $protocolo = explode("/",$_SERVER['SERVER_PROTOCOL']);
... ... @@ -168,7 +161,7 @@ if($format == &quot;gdocs&quot;){
168 161 gdocs();
169 162 }
170 163 function gdocs(){
171   - global $data, $nomeArq;
  164 + global $data, $nomeArq, $jsonp;
172 165 $items = $data["items"];
173 166 $n = count($items);
174 167 $dados = $data["features"];
... ... @@ -186,8 +179,7 @@ function gdocs(){
186 179 //var_dump($dd["shape"].getcentroid());exit;
187 180 $c = $dd["shape"]->getcentroid();
188 181  
189   - $r["calcx"] = $c->x;
190   - $r["calcy"] = $c->y;
  182 + $r["geo"] = array("lat"=>$c->y,"lon"=>$c->x);
191 183 $records[] = $r;
192 184 }
193 185 $fields = array();
... ... @@ -199,29 +191,28 @@ function gdocs(){
199 191 }
200 192  
201 193 $fields[] = array(
202   - "id"=>"calcx",
203   - "type"=>"number"
204   - );
205   - $fields[] = array(
206   - "id"=>"calcy",
207   - "type"=>"number"
  194 + "id"=>"geo",
  195 + "type"=>"geo"
208 196 );
209 197 $j = array(
210 198 "records"=>$records,
211 199 "fields"=>$fields
212 200 );
213   - //echo "<pre>";var_dump($j);exit;
214 201 $contents = json_encode($j);
215   - //var_dump($contents);exit;
216   - file_put_contents($nomeArq.".json",$contents);
217   - //envia para download
218   - ob_clean();
219   - header("Content-type: application/json");
220   - echo $contents;
  202 + //envia
  203 + if(empty($jsonp)){
  204 + file_put_contents($nomeArq.".json",$contents);
  205 + header("Content-type: application/json");
  206 + echo $contents;
  207 + }
  208 + else{
  209 + file_put_contents($nomeArq.".json",$jsonp."(".$contents.");");
  210 + echo $jsonp."(".$contents.");";
  211 + }
221 212 }
222 213  
223 214 function storymap($par){
224   - global $data, $nomeArq;
  215 + global $data, $nomeArq, $jsonp;
225 216  
226 217 $items = $data["items"];
227 218 $colunaTexto = array_search($par["coltexto"],$items);
... ... @@ -309,24 +300,15 @@ function storymap($par){
309 300 $contents = json_encode($j);
310 301 //var_dump($contents);exit;
311 302 file_put_contents($nomeArq.".json",$contents);
312   - //envia para download
  303 + //envia
313 304 ob_clean();
314   - header("Content-type: application/json");
315   - echo $contents;
316   -}
317   -function ogc_imprimeAjuda(){
318   - echo "<pre><b>Construtor de web services do I3Geo.</b><br><br>";
319   - echo "Esse programa usa os arquivos mapfiles existentes em <br>";
320   - echo "i3geo/temas para gerar web services OGC.<br>";
321   - echo "Para escolher um tema, utilize:<br>";
322   - echo "ogc.php?lista=temas - para listar os temas dispon&iacute;veis<br>";
323   - echo "Para usar esse web service voce pode usar o parametro &tema=,<br>";
324   - echo "ou seja,http://[host]/i3geo/ogc.php?tema=[codigo do tema]<br>";
325   - echo "no lugar do codigo pode ser especificado um arquivo mapfile qualquer. ";
326   - echo "Nesse caso, deve ser digitado o caminho completo no servidor<br><br>";
327   - echo "Utilize o sistema de administracao do i3Geo para configurar quais os temas da pasta i3geo/temas podem ser utilizados.<br><br>";
328   - echo "Utilize o parametro restauramapa para indicar o ID de um mapa salvo no banco <br>";
329   - echo "de dados de administracao para utiliza-lo como um WMS";
  305 + if(empty($jsonp)){
  306 + header("Content-type: application/json");
  307 + echo $contents;
  308 + }
  309 + else{
  310 + echo $jsonp."(".$contents.");";
  311 + }
330 312 }
331 313 function nomeRand($n=10)
332 314 {
... ...
pacotes/knightlab/recline/dist/recline.js
... ... @@ -1065,9 +1065,9 @@ my.Flot = Backbone.View.extend({
1065 1065 <div class="recline-flot"> \
1066 1066 <div class="panel graph" style="display: block;"> \
1067 1067 <div class="js-temp-notice alert alert-warning alert-block"> \
1068   - <h3 class="alert-heading">Hey there!</h3> \
1069   - <p>There\'s no graph here yet because we don\'t know what fields you\'d like to see plotted.</p> \
1070   - <p>Please tell us by <strong>using the menu on the right</strong> and a graph will automatically appear.</p> \
  1068 + <h3 class="alert-heading">Olá!</h3> \
  1069 + <p>Não tem nenhum gráfico aqui ainda. Você precisa definir quais colunas serão utilizadas.</p> \
  1070 + <p>Por favor <strong>utilize as opções ao lado</strong> e o gráfico aparecerá automaticamente.</p> \
1071 1071 </div> \
1072 1072 </div> \
1073 1073 </div> \
... ... @@ -3679,7 +3679,7 @@ my.Timeline = Backbone.View.extend({
3679 3679  
3680 3680 // These are the default (case-insensitive) names of field that are used if found.
3681 3681 // If not found, the user will need to define these fields on initialization
3682   - startFieldNames: ['date','startdate', 'start', 'start-date'],
  3682 + startFieldNames: ['data','date','startdate', 'start', 'start-date'],
3683 3683 endFieldNames: ['end','endDate'],
3684 3684 elementId: '#vmm-timeline-id',
3685 3685  
... ...