Commit 3862ee73450f408d2b140be84ebb67568f86c62d

Authored by Edmar Moretti
1 parent ecca08aa

--no commit message

Showing 1 changed file with 124 additions and 159 deletions   Show diff stats
ferramentas/editorol/editorol.js
... ... @@ -1326,22 +1326,14 @@ i3GEO.editorOL =
1326 1326 temp.className = "editorOLapagaItemInactive olButton";
1327 1327 temp.title = $trad("excsel");
1328 1328 temp.onclick = function(){
1329   - var x, i, s, nsel = i3GEO.editorOL.idsSelecionados.length;
  1329 + var x, nsel = i3GEO.editorOL.idsSelecionados.length;
1330 1330 i3GEO.editorOL.featuresBackup = [];
1331 1331 i3GEO.editorOL.marcaBotao();
1332 1332 if(nsel > 0){
1333 1333 x = window.confirm($trad("excsel") + "?");
1334 1334 if(x){
1335   - s = i3GEO.desenho.layergrafico.getSource();
1336   - for(i=0; i<nsel; i++){
1337   - f = s.getFeatureById(i3GEO.editorOL.idsSelecionados[i]);
1338   - if(f){
1339   - i3GEO.editorOL.featuresBackup.push(f.clone());
1340   - s.removeFeature(f);
1341   - }
1342   - }
1343   - s.changed();
1344   - i3GEO.editorOL.idsSelecionados = [];
  1335 + i3GEO.editorOL.removeFeaturesSel();
  1336 + i3GEO.desenho.layergrafico.getSource().changed();
1345 1337 }
1346 1338 }
1347 1339 else{
... ... @@ -1457,33 +1449,54 @@ i3GEO.editorOL =
1457 1449 };
1458 1450 i3GEOpanelEditor.appendChild(temp);
1459 1451 }
1460   -
  1452 + //TODO abrir em uma janela flutuante interna
  1453 + if (botoes.ajuda === true) {
  1454 + temp = document.createElement("div");
  1455 + temp.className = "editorOLajudaItemInactive olButton";
  1456 + temp.title = $trad("s1");
  1457 + temp.onclick = function(){
  1458 + if(i3GEO.configura && i3GEO.configura.locaplic){
  1459 + window.open(i3GEO.configura.locaplic + "/mashups/openlayers_ajuda.php");
  1460 + }
  1461 + else{
  1462 + window.open("openlayers_ajuda.php");
  1463 + }
  1464 + };
  1465 + i3GEOpanelEditor.appendChild(temp);
  1466 + }
  1467 + if (botoes.fecha === true) {
  1468 + temp = document.createElement("div");
  1469 + temp.className = "editorOLfechaItemInactive olButton";
  1470 + temp.title = $trad("x74");
  1471 + temp.onclick = function(){
  1472 + i3GEO.editorOL.unselTodos();
  1473 + i3GEO.editorOL.featuresBackup = [];
  1474 + i3GEO.editorOL.marcaBotao();
  1475 + i3GEO.eventos.cliquePerm.ativa();
  1476 + $i("i3GEObarraEdicao").style.display = "none";
  1477 + };
  1478 + i3GEOpanelEditor.appendChild(temp);
  1479 + }
  1480 + if (botoes.tools === true) {
  1481 + temp = document.createElement("div");
  1482 + temp.className = "editorOLtoolsItemInactive olButton";
  1483 + temp.title = $trad("u15a");
  1484 + temp.onclick = function(){
  1485 + // fora do i3geo, usa o jsts
  1486 + if (i3GEO.php) {
  1487 + i3GEO.editorOL.ferramentas();
  1488 + } else {
  1489 + i3GEO.editorOL.carregajts("i3GEO.editorOL.ferramentas()");
  1490 + }
  1491 + };
  1492 + i3GEOpanelEditor.appendChild(temp);
  1493 + }
1461 1494  
1462 1495 i3GEOpanelEditor.style.width = i3GEOpanelEditor.getElementsByTagName("div").length * 33 + "px";
1463 1496 i3GEO.editorOL.mapa.getViewport().getElementsByClassName("ol-overlaycontainer-stopevent")[0].appendChild(i3GEOpanelEditor);
1464 1497  
1465 1498 /*
1466 1499  
1467   - if (botoes.tools === true && i3GEO.php) {
1468   -
1469   - button = new OpenLayers.Control.Button({
1470   - displayClass : "editorOLtools",
1471   - trigger : function() {
1472   - // fora do i3geo, usa o jsts
1473   - if (i3GEO.php) {
1474   - i3GEO.editorOL.ferramentas();
1475   - } else {
1476   - i3GEO.editorOL.carregajts("i3GEO.editorOL.ferramentas()");
1477   - }
1478   -
1479   - },
1480   - title : $trad("u15a"),
1481   - type : OpenLayers.Control.TYPE_BUTTON
1482   - });
1483   - controles.push(button);
1484   - adiciona = true;
1485   -
1486   - }
1487 1500 if (botoes.propriedades === true) {
1488 1501  
1489 1502 button = new OpenLayers.Control.Button({
... ... @@ -1512,86 +1525,6 @@ i3GEO.editorOL =
1512 1525 adiciona = true;
1513 1526  
1514 1527 }
1515   - if (botoes.ajuda === true) {
1516   -
1517   - button = new OpenLayers.Control.Button({
1518   - displayClass : "editorOLajuda",
1519   - trigger : function() {
1520   - try {
1521   - window.open(i3GEO.configura.locaplic + "/mashups/openlayers_ajuda.php");
1522   - } catch (e) {
1523   - window.open("openlayers_ajuda.php");
1524   - }
1525   - },
1526   - title : $trad("s1"),
1527   - type : OpenLayers.Control.TYPE_BUTTON
1528   - });
1529   - controles.push(button);
1530   - adiciona = true;
1531   -
1532   - }
1533   - if (botoes.fecha === true) {
1534   -
1535   - button = new OpenLayers.Control.Button({
1536   - displayClass : "editorOLfecha",
1537   - trigger : function() {
1538   - var temp = window.confirm($trad("x94"));
1539   - if (i3GEO.eventos) {
1540   - i3GEO.eventos.cliquePerm.ativa();
1541   - }
1542   - i3GEOpanelEditor.destroy();
1543   - try {
1544   - YAHOO.temaativo.container.panel.destroy();
1545   - } catch (e) {
1546   - }
1547   - try {
1548   - YAHOO.procura.container.panel.destroy();
1549   - } catch (e) {
1550   - }
1551   - try {
1552   - YAHOO.editorOL.container.panel.destroy();
1553   - } catch (e) {
1554   - }
1555   - try {
1556   - YAHOO.editorOL.listaGeometrias.panel.destroy();
1557   - } catch (e) {
1558   - }
1559   - // try{YAHOO.panelpropriedadesEditor.panel.destroy();}catch(e){}
1560   - // try{YAHOO.editorOL.panellistagEditor.panel.destroy();}catch(e){}
1561   - try {
1562   - YAHOO.editorOL.ferramentas.panel.destroy();
1563   - } catch (e) {
1564   - }
1565   - // try{YAHOO.panelprocura.panel.destroy();}catch(e){}
1566   - try {
1567   - YAHOO.legendaeditorOL.container.panel.destroy();
1568   - } catch (e) {
1569   - }
1570   - try {
1571   - YAHOO.salvaGeometrias.container.panel.destroy();
1572   - } catch (e) {
1573   - }
1574   - if (temp === true) {
1575   - try {
1576   - if (i3GEO.desenho.layergrafico) {
1577   - i3GEO.editorOL.mapa.removeLayer(i3GEO.desenho.layergrafico);
1578   - delete (i3GEO.desenho.layergrafico);
1579   - }
1580   - if (i3GEO.editorOL.backup) {
1581   - i3GEO.editorOL.mapa.removeLayer(i3GEO.editorOL.backup);
1582   - delete (i3GEO.editorOL.backup);
1583   - }
1584   - } catch (e) {
1585   - }
1586   - }
1587   - },
1588   - title : $trad("x74"),
1589   - type : OpenLayers.Control.TYPE_BUTTON
1590   - });
1591   - controles.push(button);
1592   - adiciona = true;
1593   -
1594   - }
1595 1528 if (botoes.identifica === true) {
1596 1529 //TODO incluir codigo ol3
1597 1530  
... ... @@ -1706,6 +1639,19 @@ i3GEO.editorOL =
1706 1639 }
1707 1640 */
1708 1641 },
  1642 + removeFeaturesSel : function(){
  1643 + var s, i, nsel, f;
  1644 + nsel = i3GEO.editorOL.idsSelecionados.length;
  1645 + s = i3GEO.desenho.layergrafico.getSource();
  1646 + for(i=0; i<nsel; i++){
  1647 + f = s.getFeatureById(i3GEO.editorOL.idsSelecionados[i]);
  1648 + if(f){
  1649 + i3GEO.editorOL.featuresBackup.push(f.clone());
  1650 + s.removeFeature(f);
  1651 + }
  1652 + }
  1653 + i3GEO.editorOL.idsSelecionados = [];
  1654 + },
1709 1655 mudaSimbolo : function(estilo, id) {
1710 1656 var valor = $i(id).value, geos = i3GEO.desenho.layergrafico.selectedFeatures, n = geos.length, i;
1711 1657 i3GEO.editorOL.simbologia[estilo] = valor;
... ... @@ -1971,7 +1917,7 @@ i3GEO.editorOL =
1971 1917 YAHOO.editorOL.listaGeometrias.panel.render(document.body);
1972 1918 }
1973 1919 var id, temp, geos = i3GEO.desenho.layergrafico.getSource().getFeatures(), n = geos.length, ins = "<table class=lista4 >";
1974   - ins += "<tr><td><i>" + $trad("u6") + "</i></td><td><i>" + $trad("opcoes") + "</i></td><td></td><td></td></tr>";
  1920 + ins += "<tr><td><i>" + $trad("u6") + "</i></td><td><i>" + $trad("opcoes") + "</i></td><td></td></tr>";
1975 1921  
1976 1922 while (n > 0) {
1977 1923 n -= 1;
... ... @@ -1983,9 +1929,7 @@ i3GEO.editorOL =
1983 1929 + id
1984 1930 + "\")'>seleciona</td><td style='cursor:pointer;color:blue' onclick='javascript:i3GEO.editorOL.unselFeature(\""
1985 1931 + id
1986   - + "\")'>limpa</td><td style='cursor:pointer;color:blue' onclick='javascript:i3GEO.editorOL.flashFeaturesI(\""
1987   - + id
1988   - + "\")'>brilha</td></tr>";
  1932 + + "\")'>limpa</td></tr>";
1989 1933 }
1990 1934 }
1991 1935 ins += "</table>";
... ... @@ -2002,6 +1946,7 @@ i3GEO.editorOL =
2002 1946 temp.style.height = "100px";
2003 1947 temp.innerHTML = ins;
2004 1948 },
  1949 + //TODO incuir um botao para executar a operacao ao inves do evento onchange
2005 1950 ferramentas : function() {
2006 1951 if (!document.getElementById("panelferramentasEditor")) {
2007 1952 YAHOO.namespace("editorOL.ferramentas");
... ... @@ -2017,6 +1962,7 @@ i3GEO.editorOL =
2017 1962 "" + '<p class=paragrafo >'
2018 1963 + $trad("opsel")
2019 1964 + ':</p>'
  1965 + + '<div class=styled-select >'
2020 1966 + '<select onchange="i3GEO.editorOL.processageo(this.value);this.value = \'\'" >'
2021 1967 + ' <option value="">---</option>'
2022 1968 + ' <option value=union >Uni&atilde;o</option>';
... ... @@ -2028,7 +1974,7 @@ i3GEO.editorOL =
2028 1974 + ' <option value=symdifference >Diferen&ccedil;a sim&eacute;trica</option>';
2029 1975 }
2030 1976 ins +=
2031   - '</select>' + '<br><br><a class=paragrafo href=# onclick="i3GEO.desenho.layergrafico.destroyFeatures()" >Apaga tudo</a>';
  1977 + '</select></div>';
2032 1978  
2033 1979 YAHOO.editorOL.ferramentas.panel.setBody(ins);
2034 1980 if (i3GEO && typeof i3GEO != undefined && i3GEO != "") {
... ... @@ -2083,11 +2029,31 @@ i3GEO.editorOL =
2083 2029 if (operacao === "") {
2084 2030 return;
2085 2031 }
2086   - var geosel = i3GEO.desenho.layergrafico.selectedFeatures, polis, linhas, pontos, temp;
2087   - if (geosel.length > 0) {
2088   - polis = i3GEO.editorOL.retornaGeometriasTipo(geosel, "OpenLayers.Geometry.Polygon");
2089   - linhas = i3GEO.editorOL.retornaGeometriasTipo(geosel, "OpenLayers.Geometry.LineString");
2090   - pontos = i3GEO.editorOL.retornaGeometriasTipo(geosel, "OpenLayers.Geometry.Point");
  2032 + var polis, linhas, pontos, temp, nsel = i3GEO.editorOL.idsSelecionados.length;
  2033 +
  2034 + /*
  2035 +
  2036 + var s, i, nsel, id, clone;
  2037 + s = i3GEO.desenho.layergrafico.getSource();
  2038 + nsel = i3GEO.editorOL.idsSelecionados.length;
  2039 + for(i=0; i<nsel; i++){
  2040 + f = s.getFeatureById(i3GEO.editorOL.idsSelecionados[i]);
  2041 + if(f){
  2042 + clone = f.clone();
  2043 + id = f.getId();
  2044 + s.removeFeature(f);
  2045 + clone.setId(id);
  2046 + s.addFeature(clone);
  2047 + }
  2048 + }
  2049 + s.changed();
  2050 +
  2051 + */
  2052 +
  2053 + if (nsel > 0) {
  2054 + polis = i3GEO.editorOL.retornaGeometriasTipo("Polygon");
  2055 + linhas = i3GEO.editorOL.retornaGeometriasTipo("LineString");
  2056 + pontos = i3GEO.editorOL.retornaGeometriasTipo("Point");
2091 2057 temp = function(retorno) {
2092 2058 if (i3GEO.janela) {
2093 2059 i3GEO.janela.fechaAguarde("i3GEO.editorPoli");
... ... @@ -2144,17 +2110,18 @@ i3GEO.editorOL =
2144 2110 i3GEO.php.funcoesGeometriasWkt(temp, pontos.join("|"), operacao);
2145 2111 }
2146 2112 }
  2113 + i3GEO.desenho.layergrafico.getSource().changed();
2147 2114 return;
2148 2115 } else {
2149 2116 i3GEO.janela.tempoMsg("Selecione pelo menos dois elementos");
2150 2117 }
2151 2118 },
2152 2119 merge : function(geoms) {
2153   - var n = geoms.length, w = new Wkt.Wkt(), g, m, i;
2154   - w.read(geoms[0].toString());
  2120 + var n = geoms.length, w = new Wkt.Wkt(), g, m, i, format = new ol.format.WKT();
  2121 + w.read(format.writeFeatures([geoms[0]]));
2155 2122 if (n > 1) {
2156 2123 for (i = 1; i < n; i++) {
2157   - g = geoms[i].toString();
  2124 + g = format.writeFeatures([geoms[i]]);
2158 2125 m = new Wkt.Wkt();
2159 2126 m.read(g);
2160 2127 w.merge(m);
... ... @@ -2163,28 +2130,34 @@ i3GEO.editorOL =
2163 2130 return w.write();
2164 2131 },
2165 2132 uniaojts : function(geoms) {
2166   - var n = geoms.length, rwkt = new jsts.io.WKTReader(), wwkt = new jsts.io.WKTWriter(), fwkt = new OpenLayers.Format.WKT(), g, i, uniao;
  2133 + var n = geoms.length,
  2134 + fwkt = new ol.format.WKT(),
  2135 + rwkt = new jsts.io.WKTReader(),
  2136 + wwkt = new jsts.io.WKTWriter(),
  2137 + g, i, uniao;
2167 2138 if (n > 1) {
2168   - uniao = (fwkt.read(geoms[0]).geometry).toString();
  2139 + uniao = fwkt.writeFeatures([geoms[0]]);
2169 2140 uniao = rwkt.read(uniao);
2170 2141 for (i = 1; i <= n; i++) {
2171   - g = (fwkt.read(geoms[i]).geometry).toString();
  2142 + g = fwkt.writeFeatures([geoms[i]]);
2172 2143 uniao = uniao.union(rwkt.read(g));
2173 2144 }
2174 2145 uniao = wwkt.write(uniao);
2175 2146 return [
2176   - fwkt.read(uniao)
  2147 + fwkt.readFeatures(uniao)
2177 2148 ];
2178 2149 } else {
2179 2150 return false;
2180 2151 }
2181 2152 },
2182   - retornaGeometriasTipo : function(features, tipo) {
2183   - var n = features.length, lista = [], i, temp;
  2153 + retornaGeometriasTipo : function(tipo) {
  2154 + var n = i3GEO.editorOL.idsSelecionados.length, lista = [], i,
  2155 + s = i3GEO.desenho.layergrafico.getSource(),
  2156 + fwkt = new ol.format.WKT();
2184 2157 for (i = 0; i < n; i++) {
2185   - temp = features[i].geometry;
2186   - if (temp.CLASS_NAME == tipo) {
2187   - lista.push(temp);
  2158 + f = s.getFeatureById(i3GEO.editorOL.idsSelecionados[i]);
  2159 + if (f.getGeometry().getType() == tipo) {
  2160 + lista.push(fwkt.writeFeatures([f]));
2188 2161 }
2189 2162 }
2190 2163 return lista;
... ... @@ -2262,31 +2235,23 @@ i3GEO.editorOL =
2262 2235 }
2263 2236 // i3GEO.editorOL.backup.removeFeatures(i3GEO.editorOL.backup.features);
2264 2237 },
2265   - //TODO remover?
2266   - substituiFeaturesSel : function(wkt) {
2267   - i3GEO.editorOL.guardaBackup();
2268   - try {
2269   - var f, fwkt = new OpenLayers.Format.WKT();
2270   - i3GEO.desenho.layergrafico.removeFeatures(i3GEO.desenho.layergrafico.selectedFeatures);
2271   - f = fwkt.read(wkt);
2272   - f["attributes"] = {
2273   - opacidade : i3GEO.editorOL.simbologia.opacidade,
2274   - texto : i3GEO.editorOL.simbologia.texto,
2275   - fillColor : i3GEO.editorOL.simbologia.fillColor,
2276   - strokeWidth : i3GEO.editorOL.simbologia.strokeWidth,
2277   - strokeColor : i3GEO.editorOL.simbologia.strokeColor,
2278   - pointRadius : i3GEO.editorOL.simbologia.pointRadius,
2279   - graphicName : i3GEO.editorOL.simbologia.graphicName
2280   - };
2281   - i3GEO.desenho.layergrafico.addFeatures([
2282   - f
2283   - ]);
2284   - if (document.getElementById("panellistagEditor")) {
2285   - i3GEO.editorOL.listaGeometrias();
2286   - }
2287   - } catch (e) {
2288   - i3GEO.editorOL.restauraBackup();
2289   - }
  2238 + substituiFeaturesSel : function(f) {
  2239 + i3GEO.editorOL.removeFeaturesSel();
  2240 + var fwkt = new ol.format.WKT();
  2241 + f = fwkt.readFeatures(f)[0];
  2242 + f.setStyle(
  2243 + new ol.style.Style({
  2244 + stroke: new ol.style.Stroke({
  2245 + color: 'rgba(' + i3GEO.editorOL.simbologia.strokeColor + ',' + i3GEO.editorOL.simbologia.opacidade + ')',
  2246 + width: i3GEO.editorOL.simbologia.strokeWidth
  2247 + }),
  2248 + fill: new ol.style.Fill({
  2249 + color: 'rgba(' + i3GEO.editorOL.simbologia.fillColor + ',' + i3GEO.editorOL.simbologia.opacidade + ')'
  2250 + })
  2251 + })
  2252 + );
  2253 + f.setId(i3GEO.util.uid());
  2254 + i3GEO.desenho.layergrafico.getSource().addFeature(f);
2290 2255 },
2291 2256 adicionaFeatureWkt : function(wkt, atributos) {
2292 2257 var f, fwkt = new OpenLayers.Format.WKT();
... ...