if (typeof (i3GEO) === 'undefined') { var i3GEO = {}; } i3GEO.editor = { _mascCompose: "", _interacoes: "", _idsSelecionados: [], _copia: [], _backup : new ol.layer.Vector({ source : new ol.source.Vector({ features : new ol.Collection(), useSpatialIndex : false, name : "Backup" }), //map : i3geoOL, visible : false }), _featuresBackup : [], _simbologia : { opacidade : 0.4, texto : "", fillColor : "250,180,15", strokeWidth : 5, strokeColor : "250,150,0", pointRadius : 6, graphicName : "square", fontSize : "12px", fontColor : "0,0,0", externalGraphic : "", graphicHeight : 25, graphicWidth : 25 }, _freehand : false, _snap : false, _snapInteraction: "", _tolerance: 10, toggleSnap: function(){ if(i3GEO.editor._snap == true){ i3geoOL.addInteraction(i3GEO.editor.getSnap()); } else { i3geoOL.removeInteraction(i3GEO.editor._snapInteraction); } }, getSnap: function(){ if(i3GEO.editor._snapInteraction == ""){ i3GEO.editor._snapInteraction = new ol.interaction.Snap({ source: i3GEO.desenho.layergrafico.getSource(), pixelTolerance: i3GEO.editor._tolerance }); } return i3GEO.editor._snapInteraction; }, copy: function(){ var f = i3GEO.editor.sel.getFeatures(), n = f.length, i = 0, clone; i3GEO.editor._copia = []; for(i = 0; i < n; i++){ clone = f[i].clone(); clone.setId(i3GEO.util.uid()); i3GEO.editor._copia.push(clone); } }, paste: function(){ var n = i3GEO.editor._copia.length, i = 0, clone; i3GEO.desenho.layergrafico.getSource().addFeatures(i3GEO.editor._copia); for(i = 0; i < n; i++){ i3GEO.editor._idsSelecionados.push(i3GEO.editor._copia[i].getId()); } i3GEO.editor._copia = []; }, masc: function(){ if(i3GEO.editor._mascCompose == ""){ i3GEO.editor.addMasc(); } else { i3GEO.editor.removeMasc(); } }, removeMasc: function(){ ol.Observable.unByKey(i3GEO.editor._mascCompose); i3GEO.editor._mascCompose = ""; i3geoOL.renderSync(); }, addMasc: function(){ var nsel = i3GEO.editor._idsSelecionados.length, s = i3GEO.desenho.layergrafico.getSource(), feature; if(nsel != 1){ i3GEO.janela.tempoMsg($trad("selum")); } else { feature = s.getFeatureById(i3GEO.editor._idsSelecionados[0]); var style = new ol.style.Style({ stroke: new ol.style.Stroke({ color: 'rgba(' + i3GEO.editor._simbologia.strokeColor + ',' + i3GEO.editor._simbologia.opacidade + ')', width: i3GEO.editor._simbologia.strokeWidth }), fill: new ol.style.Fill({ color: "rgba('0,0,0,0.1')" }) }); var a = i3geoOL.on('precompose', function(event) { var ctx = event.context; var vecCtx = event.vectorContext; ctx.save(); vecCtx.drawFeature(feature,style); ctx.clip(); }); var b = i3geoOL.on('postcompose', function(event) { var ctx = event.context; ctx.restore(); }); i3geoOL.renderSync(); i3GEO.editor.sel.deleteFeatures(); i3GEO.editor._mascCompose = [a,b]; } }, sel: { unselFeature : function(id) { i3GEO.editor.sel.un(id); }, confirmDelete: function(){ var x, nsel = i3GEO.editor._idsSelecionados.length; i3GEO.editor._featuresBackup = []; if(nsel > 0){ x = window.confirm($trad("excsel") + "?"); if(x){ i3GEO.editor.sel.deleteFeatures(); i3GEO.desenho.layergrafico.getSource().changed(); } } else{ i3GEO.janela.tempoMsg($trad("selum")); } }, getFeatures : function(){ var s, i, nsel, f, sel = []; nsel = i3GEO.editor._idsSelecionados.length; s = i3GEO.desenho.layergrafico.getSource(); for(i=0; i 1) { temp = i3GEO.editor.jsts.run(polis,"union"); if(temp){ i3GEO.editor.sel.deleteFeatures(); i3GEO.desenho.layergrafico.getSource().addFeatures([temp]); i3GEO.editor._idsSelecionados.push(temp.getId()); } } }, intersect : function() { if(i3GEO.editor._idsSelecionados.length < 2){ i3GEO.janela.tempoMsg($trad("selum")); return; } var polis = i3GEO.editor.sel.getFeatures(), temp; if (polis.length > 0) { temp = i3GEO.editor.jsts.run(polis,"intersection"); if(temp){ i3GEO.editor.sel.deleteFeatures(); i3GEO.desenho.layergrafico.getSource().addFeatures([temp]); i3GEO.editor._idsSelecionados.push(temp.getId()); } } }, symdif : function() { if(i3GEO.editor._idsSelecionados.length < 2){ i3GEO.janela.tempoMsg($trad("selum")); return; } var polis = i3GEO.editor.sel.getFeatures(), temp; if (polis.length > 0) { temp = i3GEO.editor.jsts.run(polis,"symDifference"); if(temp){ i3GEO.editor.sel.deleteFeatures(); i3GEO.desenho.layergrafico.getSource().addFeatures([temp]); i3GEO.editor._idsSelecionados.push(temp.getId()); } } }, dif : function() { if(i3GEO.editor._idsSelecionados.length < 2){ i3GEO.janela.tempoMsg($trad("selum")); return; } var polis = i3GEO.editor.sel.getFeatures(), temp; if (polis.length > 0) { temp = i3GEO.editor.jsts.run(polis,"difference"); if(temp){ i3GEO.editor.sel.deleteFeatures(); i3GEO.desenho.layergrafico.getSource().addFeatures([temp]); i3GEO.editor._idsSelecionados.push(temp.getId()); } } } }, draw: { rectangle : function (drawendcallback){ i3GEO.eventos.cliquePerm.desativa(); i3GEO.editor.removeInteracoes(); var draw = new ol.interaction.Draw({ type: "Circle", geometryFunction: ol.interaction.Draw.createBox() }); //adiciona a interacao para poder ser removida i3GEO.editor._interacoes = draw; i3GEO.Interface.openlayers.parametrosMap.interactions[0].setActive(false); draw.on("drawend", function(evt) { evt.feature.setStyle( i3GEO.editor.getPolygonStyle() ); evt.feature.setId(i3GEO.util.uid()); i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature); i3GEO.editor.removeInteracoes(); setTimeout(function() { i3GEO.eventos.cliquePerm.ativa(); },1000); i3GEO.editor.tableRefresh(); }); if(drawendcallback){ draw.on("drawend",drawendcallback); } i3geoOL.addInteraction(draw); i3GEO.editor.toggleSnap(); }, text : function(drawendcallback){ i3GEO.eventos.cliquePerm.desativa(); i3GEO.editor.removeInteracoes(); var draw = new ol.interaction.Draw({ type : "Point" }); //adiciona a interacao para poder ser removida i3GEO.editor._interacoes = draw; i3GEO.Interface.openlayers.parametrosMap.interactions[0].setActive(false); draw.on("drawend", function(evt) { var texto = window.prompt("Texto", ""); evt.feature.setStyle( i3GEO.editor.getTextStyle() ); evt.feature.setId(i3GEO.util.uid()); i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature); i3GEO.editor.removeInteracoes(); setTimeout(function() { i3GEO.eventos.cliquePerm.ativa(); },1000); i3GEO.editor.tableRefresh(); }); if(drawendcallback){ draw.on("drawend",drawendcallback); } i3geoOL.addInteraction(draw); }, point : function(drawendcallback){ i3GEO.eventos.cliquePerm.desativa(); i3GEO.editor.removeInteracoes(); var draw = new ol.interaction.Draw({ type : "Point" }); //adiciona a interacao para poder ser removida i3GEO.editor._interacoes = draw; i3GEO.Interface.openlayers.parametrosMap.interactions[0].setActive(false); draw.on("drawend", function(evt) { evt.feature.setStyle( i3GEO.editor.getPointStyle() ); evt.feature.setId(i3GEO.util.uid()); i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature); i3GEO.editor.removeInteracoes(); setTimeout(function() { i3GEO.eventos.cliquePerm.ativa(); },1000); i3GEO.editor.tableRefresh(); }); if(drawendcallback){ draw.on("drawend",drawendcallback); } i3geoOL.addInteraction(draw); i3GEO.editor.toggleSnap(); }, lineString : function(drawendcallback){ i3GEO.eventos.cliquePerm.desativa(); i3GEO.editor.removeInteracoes(); var draw = new ol.interaction.Draw({ type : "LineString" }); //adiciona a interacao para poder ser removida i3GEO.editor._interacoes = draw; //desativa ol.interaction.DoubleClickZoom i3GEO.Interface.openlayers.parametrosMap.interactions[0].setActive(false); draw.on("drawend", function(evt) { evt.feature.setStyle( i3GEO.editor.getLineStringStyle() ); evt.feature.setId(i3GEO.util.uid()); i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature); i3GEO.editor.removeInteracoes(); i3GEO.eventos.cliquePerm.ativa(); i3GEO.editor.tableRefresh(); }); if(drawendcallback){ draw.on("drawend",drawendcallback); } i3geoOL.addInteraction(draw); i3GEO.editor.toggleSnap(); }, polygon : function(drawendcallback){ i3GEO.eventos.cliquePerm.desativa(); i3GEO.editor.removeInteracoes(); var draw = new ol.interaction.Draw({ type : "Polygon", freehand : i3GEO.editor._freehand }); //adiciona a interacao para poder ser removida i3GEO.editor._interacoes = draw; i3GEO.Interface.openlayers.parametrosMap.interactions[0].setActive(false); draw.on("drawend", function(evt) { evt.feature.setStyle( i3GEO.editor.getPolygonStyle() ); evt.feature.setId(i3GEO.util.uid()); i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature); i3GEO.editor.removeInteracoes(); i3GEO.eventos.cliquePerm.ativa(); i3GEO.editor.tableRefresh(); }); if(drawendcallback){ draw.on("drawend",drawendcallback); } i3geoOL.addInteraction(draw); i3GEO.editor.toggleSnap(); }, circle : function(drawendcallback){ i3GEO.eventos.cliquePerm.desativa(); i3GEO.editor.removeInteracoes(); var draw = new ol.interaction.Draw({ type : "Circle" }); //adiciona a interacao para poder ser removida i3GEO.editor._interacoes = draw; i3GEO.Interface.openlayers.parametrosMap.interactions[0].setActive(false); draw.on("drawend", function(evt) { evt.feature.setStyle( i3GEO.editor.getPolygonStyle() ); evt.feature.setId(i3GEO.util.uid()); i3GEO.desenho.layergrafico.getSource().addFeature(evt.feature); i3GEO.editor.removeInteracoes(); setTimeout(function() { i3GEO.eventos.cliquePerm.ativa(); },1000); i3GEO.editor.tableRefresh(); }); if(drawendcallback){ draw.on("drawend",drawendcallback); } i3geoOL.addInteraction(draw); i3GEO.editor.toggleSnap(); } }, removeInteracoes: function(){ i3geoOL.removeInteraction(i3GEO.editor._interacoes); i3GEO.editor._interacoes = ""; }, deleteFeatureById : function(id){ var s = i3GEO.desenho.layergrafico.getSource(), f = s.getFeatureById(id); if(f){ i3GEO.editor._featuresBackup.push(f.clone()); s.removeFeature(f); i3GEO.editor.tableRefresh(); } }, edit: function(){ i3GEO.editor._featuresBackup = []; var draw, nsel, f, c; nsel = i3GEO.editor._idsSelecionados.length; if(nsel == 1){ i3GEO.janela.tempoMsg($trad("shiftdel")); i3GEO.editor.removeInteracoes(); i3GEO.eventos.cliquePerm.desativa(); f = i3GEO.desenho.layergrafico.getSource().getFeatureById(i3GEO.editor._idsSelecionados[nsel - 1]); i3GEO.editor._featuresBackup.push(f.clone()); c = new ol.Collection(); c.push(f); draw = new ol.interaction.Modify({ features: c, deleteCondition: function(event) { return ol.events.condition.shiftKeyOnly(event) && ol.events.condition.singleClick(event); } }); i3GEO.editor._interacoes = draw; i3GEO.Interface.openlayers.parametrosMap.interactions[0].setActive(false); i3geoOL.addInteraction(draw); i3GEO.editor.toggleSnap(); } else{ i3GEO.janela.tempoMsg($trad("seluma")); } }, orderToFront: function(){ var nsel = i3GEO.editor._idsSelecionados.length; if(nsel > 0){ var s, i, nsel, id, clone; s = i3GEO.desenho.layergrafico.getSource(); nsel = i3GEO.editor._idsSelecionados.length; for(i=0; i 0){ i3GEO.editor.table(i3GEO.editor.table.seletor); } }, table: function(seletor){ i3GEO.editor.table.seletor = seletor; var keys,propriedades = [],id, temp, f, geos = i3GEO.desenho.layergrafico.getSource().getFeatures(), n = geos.length, ins = "", botoes = []; while (n > 0) { n -= 1; f = geos[n]; id = f.getId(); if(!id || id == "" || id == undefined ){ id = i3GEO.util.uid(); f.setId(id); } if(id){ botoes = []; propriedades = []; botoes.push({ "onclick": "i3GEO.editor.sel.un('" + id + "')", "title": "Unsel", "icone": "check_box_outline_blank" }); botoes.push({ "onclick": "i3GEO.editor.sel.all('" + id + "')", "title": "Sel", "icone": "check_box" }); botoes.push({ "onclick": "i3GEO.editor.deleteFeatureById('" + id + "')", "title": "Del", "icone": "delete" }); botoes.push({ "onclick": "i3GEO.editor.exportFeatureById('" + id + "')", "title": "Export", "icone": "save" }); ins += Mustache.render("{{#data}}" + i3GEO.template.botoes.listaDeIcones + "{{/data}}", {data: botoes}) + " " + id + " "; keys = f.getKeys(); $.each(keys, function( index, name ) { if(name != "geometry" && keys.indexOf(name) < 0){ propriedades.push(name + " = " +f.get(name)); } }); ins += propriedades.join(" ") + "
"; } } if (geos.length === 0) { ins = $trad("meneditor2"); } ins = '"; $(seletor).html(ins); }, properties : function(seletor){ i3GEO.editor.properties.seletor = seletor; var template = "
" + "" + "" + "
"; var hash = [ { "label": "Tolerância Snap", "value": i3GEO.editor._tolerance, "typesymbol":"pixelTolerance", "class":"", "id": "i3GEOeditorpixelTolerance" }, { "label": "Cor do contorno", "value": i3GEO.editor._simbologia.strokeColor, "typesymbol":"strokeColor", "class":"i3geoFormIconeAquarela", "id": "i3GEOeditorstrokeColor" }, { "label": "Cor do preenchimento", "value": i3GEO.editor._simbologia.fillColor, "typesymbol":"fillColor", "class":"i3geoFormIconeAquarela", "id": "i3GEOeditorfillColor" }, { "label": "Cor da fonte", "value": i3GEO.editor._simbologia.fontColor, "typesymbol":"fontColor", "class":"i3geoFormIconeAquarela", "id": "i3GEOeditorfontColor" }, { "label": "Tamanho da fonte", "value": i3GEO.editor._simbologia.fontSize, "typesymbol":"fontSize", "class":"", "id": "i3GEOeditorfontSize" }, { "label": "Opacidade (de 0 a 1)", "value": i3GEO.editor._simbologia.opacidade, "typesymbol":"opacidade", "class":"", "id": "i3GEOeditoropacidade" }, { "label": "Largura da linha/contorno", "value": i3GEO.editor._simbologia.strokeWidth, "typesymbol":"strokeWidth", "class":"", "id": "i3GEOeditorstrokeWidth" }, { "label": "Url de uma imagem", "value": i3GEO.editor._simbologia.externalGraphic, "typesymbol":"externalGraphic", "class":"", "id": "i3GEOeditorexternalGraphic" }, { "label": "Largura da imagem", "value": i3GEO.editor._simbologia.graphicWidth, "typesymbol":"graphicWidth", "class":"", "id": "i3GEOeditorgraphicWidth" }, { "label": "Altura da imagem", "value": i3GEO.editor._simbologia.graphicHeight, "typesymbol":"graphicHeight", "class":"", "id": "i3GEOeditorgraphicHeight" } ]; ins = '"; $(seletor).html(ins); $(seletor).find(".i3geoFormIconeAquarela").click(function() { if(this.firstChild){ i3GEO.util.abreCor("", $(this).find("input")[0].id); } else { i3GEO.util.abreCor("", this.id); } }); }, setPropertie: function(id){ var obj = $i(id),s, i, nsel, f; if(obj.name == "pixelTolerance"){ i3GEO.editor._snap.set("pixelTolerance",obj.value*1); return; } i3GEO.editor._simbologia[obj.name] = obj.value; nsel = i3GEO.editor._idsSelecionados.length; s = i3GEO.desenho.layergrafico.getSource(); for(i=0; i