//SET VARIABLES
var map = null;
var minimap = null;
var map_tiles = {};
var ctr_tiles = {};
var map_layers = {};
var ctr_layers = {};
var data1 = [];
var idPopup = 0;
var edifPopup = 0;
var checarNome = 0;
$(document).ready(function(){
document.getElementById("nomeUsuario").value = "";
$("#searchbar").keypress(function(e){
if(e.keyCode==13)
$("#btnSubmit").click();
});
$("#nomeUsuario").keypress(function(e){
if(e.keyCode==13)
$("#botaoModal").click();
});
});
function generateRandomHex() {
const hexDigits = "0123456789abcdef";
let hexCode = "#";
for (let i = 0; i < 6; i++) {
hexCode += hexDigits.charAt(Math.floor(Math.random() * 16));
}
return hexCode;
}
function busca() {
p1 = document.getElementById("searchbar").value;
$.each(data1, function(index, value){
if(map.hasLayer(value)){
map.removeLayer(value);
}
});
if (isNaN(p1)){
let latLng = p1.split(',');
if (latLng[1]) {
L.marker([latLng[0], latLng[1]],{icon:marker[20]}).bindPopup("Local pesquisado: "+ p1).addTo(map);
map.setView(new L.LatLng(latLng[0], latLng[1]), 14);
} else {
$.getJSON("https://nominatim.openstreetmap.org/search?q="+ p1 +"&format=geojson&viewbox=-35.829849243164055,-9.723946569800441,-35.591583251953125,-9.467349225571983&bounded=1", function(geoinfo){
$.each(geoinfo.features, function(a){
if(geoinfo.features[a].geometry.type == "Point"){
let coordinates = geoinfo.features[a].geometry.coordinates;
L.marker([coordinates[1], coordinates[0]],{icon:marker[20], alt:(JSON.stringify(geoinfo.features[a].properties))}).bindPopup("Local: " + geoinfo.features[a].properties.display_name).addTo(map);
map.setView(new L.LatLng(coordinates[1], coordinates[0]), 14);
}
});
});
}
}else{
var http = new XMLHttpRequest();
var url = 'https://semecmaceio.com/v1/integracao/polygon';
var params = '{"lotes":[{"inscricao":'+ Number(p1) +'}]}';
http.open('POST', url, true);
//Send the proper header information along with the request
http.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
http.onreadystatechange = function() {//Call a function when the state changes.
if(http.readyState == 4 && http.status == 200) {
var data = JSON.parse(http.responseText);
L.geoJSON(data.features[0]).bindPopup(data.features[0].properties.LOGRADOURO +" - "+ data.features[0].properties.PATH).addTo(map).openPopup();
}
}
http.send(params);
}
}
$(document).ready(function(){
//SET TILES
map_tiles["osm"] = L.tileLayer("https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png", {
maxNativeZoom:19,
maxZoom: 22
});
ctr_tiles["Ruas"] = map_tiles["osm"];
map_tiles["osm2"] = L.tileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
maxNativeZoom:19,
maxZoom: 22
});
ctr_tiles["Ruas 2"] = map_tiles["osm2"];
map_tiles["arcgis"] = L.tileLayer('http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}',{
maxNativeZoom:18,
maxZoom: 22
});
ctr_tiles["Satelite"] = map_tiles["arcgis"];
/*
map_tiles["bing"] = L.tileLayer.bing('AgLA0Q_eJvbHQPhbE1H83YyV3PSBgsatKeO-Otwr8s3DCWsZtxKBsuxEIrXtQjC9',{
maxNativeZoom:18,
maxZoom: 20
});
ctr_tiles["Mapa Bing"] = map_tiles["bing"];
*/
//SET LAYERS
map_layers["search"]= L.layerGroup();
if(typeof my_layer != "undefined" && my_layer == "corona"){
map_layers["Corona Vírus"] = L.layerGroup();
ctr_layers["Corona Vírus"] = map_layers["Corona Vírus"];
map_layers["Mapa de Calor"] = L.layerGroup();
ctr_layers["Mapa de Calor"] = map_layers["Mapa de Calor"];
}
camadas_enviadas=[];
if(document.getElementById("postjson").innerText !== ""){
var dadosenviados = JSON.parse(document.getElementById("postjson").innerText);
if ("features" in dadosenviados){
map_layers["Dados Enviados"] = L.layerGroup();
ctr_layers["Dados Enviados"] = map_layers["Dados Enviados"];
} else if ("camadas" in dadosenviados){
for ( [key, value] of Object.entries(dadosenviados.camadas)) {
map_layers[key] = L.layerGroup();
ctr_layers[key] = map_layers[key];
camadas_enviadas.push(key);
}
}
}
map_layers["Bairros"] = L.layerGroup();
ctr_layers["Bairros"] = map_layers["Bairros"];
map_layers["Quadras"] = L.layerGroup();
ctr_layers["Quadras"] = map_layers["Quadras"];
//tipos[90]={"texto":"Quadras", "marker":"1"};
map_layers["Correios"] = L.layerGroup();
ctr_layers["Correios"] = map_layers["Correios"];
map_layers["Vias Oficial"] = L.layerGroup();
ctr_layers["Vias Oficial"] = map_layers["Vias Oficial"];
map_layers["Circunscrição Cartórios"] = L.layerGroup();
ctr_layers["Circunscrição Cartórios"] = map_layers["Circunscrição Cartórios"];
map_layers["Zoneamento Alto-Risco"] = L.layerGroup();
ctr_layers["Zoneamento Alto-Risco"] = map_layers["Zoneamento Alto-Risco"];
map_layers["Zoneamento"] = L.layerGroup();
ctr_layers["Zoneamento"] = map_layers["Zoneamento"];
/*
map_layers["Imóveis Municipais"] = L.layerGroup();
ctr_layers["Imóveis Municipais"] = map_layers["Imóveis Municipais"];
map_layers["Lotes Territoriais"] = L.layerGroup();
ctr_layers["Lotes Territoriais"] = map_layers["Lotes Territoriais"];
map_layers["Lei de incentivo do Jaraguá"] = L.layerGroup();
ctr_layers["Lei de incentivo do Jaraguá"] = map_layers["Lei de incentivo do Jaraguá"];
map_layers["Regularidade do Jaraguá"] = L.layerGroup();
ctr_layers["Regularidade do Jaraguá"] = map_layers["Regularidade do Jaraguá"];
map_layers["Evento geológico do Pinheiro"] = L.layerGroup();
ctr_layers["Evento geológico do Pinheiro"] = map_layers["Evento geológico do Pinheiro"];
*/
$.getJSON(dir + "json/tipos.php", function(tipos){
$.each(tipos, function(e){
map_layers[e] = L.layerGroup();
ctr_layers[tipos[e]["texto"]] = map_layers[e];
});
//tipos[90]={"texto":"Quadras", "marker":"1"}; teste parece inutil
L.control.layers(ctr_tiles, ctr_layers).addTo(map);
//STARTER LAYER
if(typeof my_layer == "number" && typeof map_layers[my_layer] != "undefined"){
map.addLayer(map_layers[my_layer]);
}else if(typeof my_layer != "undefined" && my_layer == "corona"){
map.addLayer(map_layers["Corona Vírus"]);
}
//SIZE CORRECTION
map.invalidateSize(true);
});
camadas_qgis=['Cartórios','Geológico','Zoneamento'];
for ( key of camadas_qgis) {
map_layers["QGIS-"+key] = L.layerGroup();
ctr_layers["QGIS-"+key] = map_layers["QGIS-"+key];
}
//SET CONFIG
map = L.map('map', {
center: [-9.663136558749533, -35.71422457695007],
layers: [map_tiles["osm"]],
zoomControl: true,
maxZoom: 20,
minZoom: 12,
zoom: 14
});
var plugin = L.control.measure({
position: 'topleft',
primaryLengthUnit: 'meters',
primaryAreaUnit: 'sqmeters',
activeColor: '#363535',
completedColor: '#363535',
}).addTo(map)
minimap = L.map("location-minimap", {
center: [0, 0],
layers: L.tileLayer("https://{s}.tile.openstreetmap.de/{z}/{x}/{y}.png"),
zoomControl: false,
zoom: 17
});
//MINIMAP CONTROL
minimap._handlers.forEach(function(handler) {
handler.disable();
});
//LOAD DATA
map.on('overlayadd', function(e){
$.getJSON(dir + "json/tipos.php", function(tipos){
var key = Object.keys(tipos).find(key => tipos[key]["texto"] === e.name);
var popupId = 1;
var auxiliar = 0;
var localStorage = JSON.parse(window.localStorage.getItem('idPontos'));
if(key === undefined){
if(map_layers[e.name].getLayers().length === 0){
if(e.name.includes('QGIS')){
$.getJSON("https://geo.maceio.al.gov.br/dados/map.php?" + e.name.replace('QGIS-','').toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, "") + "=1&json=1", function(geoinfo){
$("#info-back").fadeOut("slow");
stopRot();
L.geoJSON(geoinfo, {
onEachFeature: function (feature, layer) {
if(e.name == "QGIS-Cart"){
layer.bindPopup("Cartório: " + feature.properties.Cartório);
cor_random=generateRandomHex();
layer.setStyle({fillColor:cor_random, weight:2, opacity:1, color:'#0F0000', dashArray:'1', fillOpacity:0.1});
} else if(e.name == "Quadras"){
txtset=feature.properties.setor.toString().padStart(2, `0`);
txtquad=feature.properties.quadra.toString().padStart(4, `0`);
layer.bindPopup("Bairro: " + feature.properties.bairro + "
Setor: " + feature.properties.setor + "
Quadra: " + txtquad + "
Pesquisa Imóveis");
layer.setStyle({fillColor:'blue', weight:1, opacity:1, color:'#23BED6', dashArray:'1', fillOpacity:0.1}).on('click', showLocation);
} else {
txt_geojson="";
for(const propriedade in feature.properties){
txt_geojson+=`${propriedade}: ${feature.properties[propriedade]}
`;
}
layer.bindPopup(txt_geojson);
cor_random=generateRandomHex();
layer.setStyle({fillColor:cor_random, weight:2, opacity:1, color:'#0F0000', dashArray:'1', fillOpacity:0.1});
}
}
}).addTo(map_layers[e.name]);
});
}else if(camadas_enviadas.length>0 && e.name.includes('Dados')){
for(camada of camadas_enviadas){
if(e.name == camada){
document.getElementById("info-back").style.display = "none";
stopRot();
camadaenviada=dadosenviados.camadas[camada];
var groupMarker = new L.MarkerClusterGroup({
disableClusteringAtZoom: 18,
showCoverageOnHover: true,
zoomToBoundsOnClick: true,
spiderfyOnMaxZoom: true
});
$.each(camadaenviada.features, function(a){
if(camadaenviada.features[a].geometry!=null){
if(camadaenviada.features[a].geometry.type=="Point"){
var coordinates = camadaenviada.features[a].geometry.coordinates;
}else if(camadaenviada.features[a].geometry.type=="LineString" ){
var coordinates = camadaenviada.features[a].geometry.coordinates[0];
}else if(camadaenviada.features[a].geometry.type=="Polygon" || camadaenviada.features[a].geometry.type=="MultiLineString"){
var coordinates = camadaenviada.features[a].geometry.coordinates[0][0];
}else{
var coordinates = camadaenviada.features[a].geometry.coordinates[0][0][0];
}
loc = new L.LatLng(coordinates[1], coordinates[0]);
if (!("properties" in camadaenviada.features[a])){
}else if (camadaenviada.features[a].properties.Tipo=="QGIS"){
//L.marker(loc,{icon:marker[20], alt:(JSON.stringify(camadaenviada.features[a].properties))}).bindPopup("Titulo: " + camadaenviada.features[a].properties.Titulo + "
Dados: "+JSON.stringify(camadaenviada.features[a].properties)).addTo(map).openPopup();
} else if (camadaenviada.features[a].properties.KEY===0){
L.marker(loc,{icon:marker[5], alt:(JSON.stringify(camadaenviada.features[a].properties))}).bindPopup("Geo: " + camadaenviada.features[a].properties.GEO_KEY + "
Guia de ITBI: " + camadaenviada.features[a].properties.BUSCA).addTo(map).openPopup();
} else if (camadaenviada.features[a].properties.KEY>0){
L.marker(loc,{icon:marker[6], alt:(JSON.stringify(camadaenviada.features[a].properties))}).bindTooltip("Geo: " + camadaenviada.features[a].properties.GEO_KEY + "
Guia de ITBI: " + camadaenviada.features[a].properties.BUSCA).addTo(groupMarker);
}
}
});
L.geoJSON(camadaenviada,{onEachFeature: function(feature, layer){
poptxt="";
for (const [key, value] of Object.entries(feature.properties)){
poptxt+=`${key}: ${value}
`
}
layer.bindTooltip(poptxt);
var regFillColor = "blue";
var regColor = "blue";
if(("semtitular" in feature.properties && feature.properties.semtitular=="S") || ("territorial" in feature.properties && feature.properties.territorial=="S")){
regColor = "red";
if (feature.properties.territorial=="S"){
regFillColor = "brown";
}
}
if (feature.properties.semtitular=="S" && feature.properties.territorial=="S"){
regFillColor = "purple";
regColor = "red";
} else if (feature.properties.semtitular=="S" && feature.properties.territorial=="N"){
regFillColor = "yellow";
regColor = "red";
} else if (feature.properties.semtitular=="N" && feature.properties.territorial=="S"){
regFillColor = "brown";
regColor = "red";
}
if (feature.properties.maisConstrucao=="S"){
//dash=",stroke-dasharray='16'";
dash="6 20";
} else {
//dash=",stroke-dasharray='0'";
dash="0";
}
//layer.bindPopup("Bairro: " + feature.properties.PATH + "
GEO: " + feature.properties.GEO_KEY + "
zoneamento: " + feature.properties.ZONEAMENTO + "
área: " + feature.properties.AREA + "
regularidade: " + regularidade + "
Pesquisa Imóveis");
if (layer.feature.geometry.type=="MultiPolygon"){
if ('pontoEnergia' in feature.properties){
//layer.bindTooltip("my tooltip text").openTooltip();
//regColor = "green";
regFillColor = "white";
}
layer.setStyle({"fillColor":regFillColor, "weight":1, "opacity":1, "color":regColor, "fillOpacity":0.3, "dashArray":dash});
if (feature.properties.siat=="N"){
//layer.bindTooltip("my tooltip text").openTooltip();
layer.setStyle({"fillColor":"white","color":"black","weight":5});
} else if (feature.properties.siat=="D"){
//layer.bindTooltip("my tooltip text").openTooltip();
layer.setStyle({"fillColor":"black","color":"black","weight":5});
}
if (feature.properties.maisConstrucao=="S"){
//layer.bindTooltip("my tooltip text").openTooltip();
layer.setStyle({"weight":5});
}
} else if (layer.feature.geometry.type=="Point" && 'lote' in layer.feature.properties){
//layer.setStyle({"opacity":0.5,"outline":"dashed"});
layer.options['opacity']=0.5;
}
}
}).addTo(groupMarker);
map_layers[camada].addLayer(groupMarker);
}
}
map.setView(loc, 14);
if (document.getElementById('legenda')=== null){
var legend = L.control({position: 'topleft'});
legend.onAdd = function (map) {
var div = L.DomUtil.create('div', 'leaflet-control leaflet-control-layers');
div.style = `#position: absolute; #top: 50%; align:left;`;
div.id = 'legenda';
div.innerHTML =
'