Commit b9209692256100b0312880038d1397c9da1f60c7

Authored by Edmar Moretti
1 parent 2ce25ea0

Inclusão da ferramenta de geração de rotas e visualização do mapa do i3geo dentro do mapa do google

ferramentas/googlemaps/index.php
... ... @@ -4,7 +4,7 @@ include_once("../../ms_configura.php");
4 4 <html>
5 5 <head>
6 6 <script src="../../pacotes/cpaint/cpaint2.inc.compressed.js" type="text/javascript"></script>
7   -<script language="JavaScript" type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=<?php echo $googleApiKey; ?>">
  7 +<script language="JavaScript" type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2.x&amp;key=<?php echo $googleApiKey; ?>">
8 8 </script>
9 9 <title></title>
10 10 </head>
... ... @@ -12,6 +12,7 @@ include_once(&quot;../../ms_configura.php&quot;);
12 12 <div id="map" style="width: 440px; height: 340px"></div>
13 13  
14 14 <script type="text/javascript" >
  15 + counterClick = 0
15 16 var m = document.getElementById("map")
16 17 m.style.width = window.parent.objmapa.w / 2
17 18 m.style.height = window.parent.objmapa.h / 2
... ... @@ -77,6 +78,7 @@ include_once(&quot;../../ms_configura.php&quot;);
77 78 botaoI3geo.prototype = new GControl();
78 79 botaoI3geo.prototype.initialize = function(map) {
79 80 var container = document.createElement("div");
  81 +
80 82 var i3geo = document.createElement("div");
81 83 this.setButtonStyle_(i3geo);
82 84 container.appendChild(i3geo);
... ... @@ -84,11 +86,19 @@ include_once(&quot;../../ms_configura.php&quot;);
84 86 GEvent.addDomListener(i3geo, "click", function() {
85 87 ativaI3geo();
86 88 });
  89 +
  90 + var rota = document.createElement("div");
  91 + this.setButtonStyle_(rota);
  92 + container.appendChild(rota);
  93 + rota.appendChild(document.createTextNode("Rota"));
  94 + GEvent.addDomListener(rota, "click", function() {
  95 + ativaI3geoRota();
  96 + });
87 97 map.getContainer().appendChild(container);
88 98 return container;
89 99 }
90 100 botaoI3geo.prototype.getDefaultPosition = function() {
91   - return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(70, 6));
  101 + return new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(50, 50));
92 102 }
93 103 botaoI3geo.prototype.setButtonStyle_ = function(button) {
94 104 button.style.textDecoration = "none";
... ... @@ -180,6 +190,133 @@ include_once(&quot;../../ms_configura.php&quot;);
180 190 map.addOverlay(wmsmap);
181 191 }
182 192 }
  193 + function ativaI3geoRota()
  194 + {
  195 + rotaEvento = GEvent.addListener(map, "click", parametrosRota);
  196 + alert("Clique o ponto de origem da rota");
  197 + counterClick++;
  198 + }
  199 + function parametrosRota(overlay,latlng)
  200 + {
  201 + if(counterClick == 1)
  202 + {
  203 + counterClick++;
  204 + alert("Clique o ponto de destino da rota");
  205 + pontoRota1 = latlng
  206 + return;
  207 + }
  208 + if(counterClick == 2)
  209 + {
  210 + pontoRota2 = latlng
  211 + counterClick = 0;
  212 + GEvent.removeListener(rotaEvento)
  213 + constroiRota()
  214 + }
  215 + }
  216 +
  217 + function constroiRota()
  218 + {
  219 + geocoder = new GClientGeocoder();
  220 + var pt2 = function(response)
  221 + {
  222 + if (!response || response.Status.code != 200) {
  223 + alert("Status Code:" + response.Status.code);
  224 + } else {
  225 + place = response.Placemark[0];
  226 + point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
  227 + marker = new GMarker(point);
  228 + map.addOverlay(marker);
  229 + /*
  230 + marker.openInfoWindowHtml(
  231 + '<b>orig latlng:</b>' + response.name + '<br/>' +
  232 + '<b>latlng:</b>' + place.Point.coordinates[0] + "," + place.Point.coordinates[1] + '<br>' +
  233 + '<b>Status Code:</b>' + response.Status.code + '<br>' +
  234 + '<b>Status Request:</b>' + response.Status.request + '<br>' +
  235 + '<b>Address:</b>' + place.address + '<br>' +
  236 + '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
  237 + '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
  238 + */
  239 + endereco2 = place.address;
  240 + montaRota()
  241 + }
  242 + }
  243 +
  244 + var pt1 = function(response)
  245 + {
  246 + map.clearOverlays();
  247 + if (!response || response.Status.code != 200) {
  248 + alert("Status Code:" + response.Status.code);
  249 + } else {
  250 + place = response.Placemark[0];
  251 + point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
  252 + marker = new GMarker(point);
  253 + map.addOverlay(marker);
  254 + /*
  255 + marker.openInfoWindowHtml(
  256 + '<b>orig latlng:</b>' + response.name + '<br/>' +
  257 + '<b>latlng:</b>' + place.Point.coordinates[0] + "," + place.Point.coordinates[1] + '<br>' +
  258 + '<b>Status Code:</b>' + response.Status.code + '<br>' +
  259 + '<b>Status Request:</b>' + response.Status.request + '<br>' +
  260 + '<b>Address:</b>' + place.address + '<br>' +
  261 + '<b>Accuracy:</b>' + place.AddressDetails.Accuracy + '<br>' +
  262 + '<b>Country code:</b> ' + place.AddressDetails.Country.CountryNameCode);
  263 + */
  264 + endereco1 = place.address;
  265 + }
  266 + geocoder.getLocations(pontoRota2, pt2);
  267 +
  268 + }
  269 + geocoder.getLocations(pontoRota1, pt1);
  270 + }
  271 + function montaRota()
  272 + {
  273 + if(!document.getElementById("descrota"))
  274 + {
  275 + var descrota = document.createElement("div");
  276 + descrota.id = "descrota"
  277 + document.body.appendChild(descrota);
  278 + }
  279 + else
  280 + {
  281 + descrota = document.getElementById("descrota")
  282 + descrota.innerHTML = ""
  283 + }
  284 + directions = new GDirections(map, descrota);
  285 + directions.load("from: "+endereco1+" to: "+endereco2);
  286 + GEvent.addListener(directions, "load", function() {
  287 + var linha = directions.getPolyline();
  288 + var nvertices = linha.getVertexCount();
  289 + pontos = new Array()
  290 + for(i=0;i<nvertices;i++)
  291 + {
  292 + var vertice = linha.getVertex(i);
  293 + pontos.push(vertice.lng()+" "+vertice.lat())
  294 + }
  295 + function ativanovotema(retorno)
  296 + {
  297 + var temaNovo = retorno.data
  298 + var converteParaLinha = function()
  299 + {
  300 + var cp = new cpaint();
  301 + cp.set_response_type("JSON");
  302 + //cp.set_debug(2)
  303 + var p = window.parent.g_locaplic+"/classesphp/mapa_controle.php?g_sid="+window.parent.g_sid+"&funcao=sphPT2shp&para=linha&tema="+temaNovo;
  304 + cp.call(p,"sphPT2shp",window.parent.ajaxredesenha);
  305 + }
  306 + var p = window.parent.g_locaplic+"/classesphp/mapa_controle.php?g_sid="+window.parent.g_sid+"&funcao=insereSHP&tema="+retorno.data+"&xy="+pontos.join(" ");
  307 + var cp = new cpaint();
  308 + //cp.set_debug(2)
  309 + cp.set_response_type("JSON");
  310 + cp.call(p,"insereSHP",converteParaLinha);
  311 + }
  312 + var cp = new cpaint();
  313 + cp.set_response_type("JSON");
  314 + cp.set_transfer_mode("POST");
  315 + var p = window.parent.g_locaplic+"/classesphp/mapa_controle.php?g_sid="+window.parent.g_sid;
  316 + cp.call(p,"criaSHPvazio",ativanovotema,"&funcao=criashpvazio");
  317 +
  318 + });
  319 + }
183 320 ondegoogle(map);
184 321 </script>
185 322 </body>
... ...
ferramentas/inserexy2/index.js
... ... @@ -152,9 +152,6 @@ function criatemaeditavel()
152 152 var cp = new cpaint();
153 153 cp.set_response_type("JSON");
154 154 cp.set_transfer_mode("POST");
155   - //cp.set_debug(2)
156   - //var p = g_locaplic+"/classesphp/mapa_controle.php?g_sid="+g_sid+"&funcao=criashpvazio";
157   - //cp.call(p,"criaSHPvazio",ativanovotema);
158 155 var p = g_locaplic+"/classesphp/mapa_controle.php?g_sid="+g_sid;
159 156 cp.call(p,"criaSHPvazio",ativanovotema,"&funcao=criashpvazio");
160 157 }
... ...