558
| <![CDATA[<script>
var global = this;
var map;
var kml;
var URLServerMeta = 'https://ciram.epagri.sc.gov.br/';
var URL_ = 'https://www.ciram.epagri.sc.gov.br/agroconnect/';
var bds_ = [[-69, -43], [-35, -22.5]];
var layersMapa = [];
var hasM = new Map();
$(document).ready(function () {
function showOnMapa(object) {
object.addTo(map);
}
function hideOnMapa(object) {
object.remove(map);
}
global.addLayerOnArray = function (key, layer, nohide = false) {
if (layer !== undefined) {
hasM.set(key, {'show': function () {
showOnMapa(layer);
},
'hide': function () {
hideOnMapa(layer);
},
'nohide': nohide
});
}
/*layersMapa[key] = {'show': function () {
showOnMapa(layer);
},
'hide': function () {
hideOnMapa(layer);
}
};*/
}
global.addKML = function (folder) {
var kmlLayer = new L.KML("maps/" + folder + "/doc.kml", {async: true});
kmlLayer.on("loaded", function (e) {
// map.fitBounds(e.target.getBounds());
});
return kmlLayer;
}
global.addKMZ = function (folder) {
var kmz = L.kmzLayer().addTo(map);
kmz.on('load', function (e) {
});
return kmz;
//kmz.load("/ciram_arquivos/agroconnect/cultura/soja/AlertaFerrugemdaSojaSC.kmz");
}
global.createShape = function (folder, arq) {
let geo = L.geoJson({features: []}, {onEachFeature: function popUp(f, l) {
var out = [];
if (f.properties) {
for (var key in f.properties) {
out.push(key + ": " + f.properties[key]);
}
l.bindPopup(out.join("<br />"));
}
}});
var base = window.location.href + "maps/" + folder + arq;
shp(base).then(function (data) {
geo.addData(data);
});
return geo;
}
global.createOverlayKML = function (folder) {
var kmlDir = 'maps/' + folder + '/doc.kml';
var xhr = new XMLHttpRequest();
// xhr.onerror = function () {
//console.log("Error while getting XML.");
// console.log('Cultura sem zoneamento.')
// }
xhr.overrideMimeType('text/xml'); //Needed for some servers to provide responseXML
try {
xhr.open("GET", kmlDir, false);
xhr.send();
var north = parseFloat(xhr.responseXML.getElementsByTagName("north")[0].innerHTML).toFixed(3);
var south = parseFloat(xhr.responseXML.getElementsByTagName("south")[0].innerHTML).toFixed(3);
var east = parseFloat(xhr.responseXML.getElementsByTagName("east")[0].innerHTML).toFixed(3);
var west = parseFloat(xhr.responseXML.getElementsByTagName("west")[0].innerHTML).toFixed(3);
// Creating Image overlay
var imageUrl = 'maps/' + folder + '/Composite.png';
imageBounds = [[north, east], [south, west]];
var overlay = new L.imageOverlay(imageUrl, imageBounds);
return overlay;
} catch (e) {
//console.log('Cultura sem zoneamento.')
//console.error(e.message);
}
}
function initialize() {
var div = document.getElementById("gmaps");
map = L.map(div).setView([-27.593500, -48.558540], 13);
map.setZoom(7); //7
map.zoomControl.setPosition('bottomleft');
map.on("zoomstart", function () {
zoomLevel = map.getZoom();
});
map.options.minZoom = 3; //7 ideal
map.options.maxZoom = 18; //18 ideal pra ver separados
L.control.scale().addTo(map);
L.tileLayer('https://maps.epagri.sc.gov.br/tile/{z}/{x}/{y}.png', {
attribution: 'Dados © <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors, <a href="https://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
id: 'baserwe'
}).addTo(map);
var searchBox = map.addControl(new L.Control.Search({
url: 'https://nominatim.openstreetmap.org/search?format=json&q={s}',
//jsonpParam: 'json_callback',
propertyName: 'display_name',
propertyLoc: ['lat', 'lon'],
marker: L.circleMarker([0, 0], {radius: 100}),
autoCollapse: true,
autoType: false,
minLength: 2,
moveToLocation: function (latlng, title, map) {
map.setView(latlng, 10); // set the zoom
}
}));
//var markers = L.markerClusterGroup();
// var mcg = L.markerClusterGroup().addTo(map);
// var mcg2 = L.markerClusterGroup().addTo(map);
// L.marker([-27.38, -51.12]).addTo(mcg);
// L.marker([-27.38, -51.13]).addTo(mcg);
// for(var i=0;i<40;i++){
// L.marker([-27.38, -51.12]).addTo(mcg2);
// }
/* $("#searchtext20").mouseenter(function() {// .click(function() {
alert("entrei");
});*/
//contorno SC var encodePath; // defini em um arquivo js a parte pois no jsp dava erro: Constant string too long
/* var polyline = L.polyline(L.Polyline.fromEncoded(encodePath).getLatLngs(), {
color: '#000000',
opacity: 0.6,
//weight: 2}).addTo(map);
weight: 2});
layers['contorno']={'show':function(){
showPolyline(polyline);
},
'hide':function(){hidePolyline(polyline)}
};
layers['contorno'].show();*/
//executeFunctionByName(layerBacias
// map.fitBounds(polyline.getBounds());
// Instantiate KMZ parser (async)
/* try {
var kmzParser = new L.KMZParser({
onKMZLoaded: function (layer, name) {
control.addOverlay(layer, name);
// layer.addTo(map);
}
});
// Add remote KMZ files as layers (NB if they are 3rd-party servers, they MUST have CORS enabled)
kmzParser.load('maps/geral/Municípios.kmz');
kmzParser.load('maps/geral/Bacias SC.kmz');
kmzParser.load('maps/geral/Regiões SC.kmz');
var control = L.control.layers(null, null, {position: 'topleft', collapsed: false}).addTo(map);
//Mostra no mapa as coordenada lat/long do mouse em movimento
var coordDIV = document.createElement('div');
coordDIV.id = 'mapCoordDIV';
coordDIV.style.position = 'absolute';
coordDIV.style.zIndex = '900';
coordDIV.style.bottom = '1px';
coordDIV.style.left = '100px';
document.getElementById('gmaps').appendChild(coordDIV);
map.on('mousemove', function (e) {
var lat = e.latlng.lat.toFixed(3);
var lon = e.latlng.lng.toFixed(3);
document.getElementById('mapCoordDIV').innerHTML = 'Coordenadas: ' + lat + ' , ' + lon;
});
} catch (e) {
console.log(e);
}
*/
let contorno = L.polyline(L.Polyline.fromEncoded(encodePath).getLatLngs(), {
color: '#000000',
opacity: 0.6,
//weight: 2}).addTo(map);
weight: 2});
addLayerOnArray('contorno', contorno, true);
//layersMapa['contorno'].show();
hasM.get('contorno').show();
}
initialize();
});
</script>]]>
|