Skip to content

Commit 8a3830f

Browse files
committed
Ajustes para software novo. osm-codes/WS#58
1 parent 8e0a13d commit 8a3830f

File tree

3 files changed

+120
-107
lines changed

3 files changed

+120
-107
lines changed

logistic/main.js

Lines changed: 63 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -511,7 +511,7 @@ function toggleCoverLayers()
511511
if(getCover)
512512
{
513513
let input = defaultMap.isocode + '-' + document.getElementById('sel_jurL2').value + '-' + document.getElementById('sel_jurL3').value
514-
loadGeojson(uri_base + "/" + input + ".json/cover/" + defaultMap.scientificBase,[layerCoverAll],function(e){},function(e){});
514+
loadGeojson(uri_base + "/" + input + ".json/cover",[layerCoverAll],function(e){},function(e){});
515515
getCover = false;
516516
}
517517
else
@@ -524,17 +524,44 @@ function toggleOfficialBordersLayers()
524524
{
525525
map.hasLayer(layerJurisdAll) ? map.removeLayer(layerJurisdAll) : map.addLayer(layerJurisdAll);
526526
}
527-
function generateSelectLevel(base,baseValue,size_shortestprefix,size=0)
527+
function generateSelectLevel(base,size_shortestprefix,size=0)
528528
{
529+
// let html = '';
530+
//
531+
// for (let i = base.iniLevel, k=base.iniDigit; i <= base.endLevel; i+=base.modLevel, k++)
532+
// {
533+
// if (k > size_shortestprefix)
534+
// {
535+
// html += '<option value="' + levelValues[i] + ( size > 0 ? (Math.floor(size) <= levelSize[i] ? '" selected>' : '">') : (i == base.levelDefault ? '" selected>' : '">') ) + 'L' + (0.5*i - 0.5*base.diffl0br).toString() + ' (' + ((levelSize[i]<1000)? Math.round(levelSize[i]*100.0)/100 : Math.round(levelSize[i]*100.0/1000)/100) + ((levelSize[i]<1000)? 'm': 'km') + ') ' + (i % 2 == 0 ? '&#9643;' : '&#9645;') + '</option>'
536+
// }
537+
// }
538+
// return html
539+
529540
let html = '';
530541

531-
for (let i = base.iniLevel, k=base.iniDigit; i <= base.endLevel; i+=base.modLevel, k++)
542+
let m=0, p=5, q=base.iniLevel;
543+
544+
const endLevel = base.endLevel;
545+
546+
for (let j=0; j <= endLevel; j++)
532547
{
533-
if (k > size_shortestprefix)
534-
{
535-
html += '<option value="' + levelValues[i] + ( size > 0 ? (Math.floor(size) <= levelSize[i] ? '" selected>' : '">') : (i == base.levelDefault ? '" selected>' : '">') ) + 'L' + (0.5*i - 0.5*base.diffl0br).toString() + ' (' + ((levelSize[i]<1000)? Math.round(levelSize[i]*100.0)/100 : Math.round(levelSize[i]*100.0/1000)/100) + ((levelSize[i]<1000)? 'm': 'km') + ') ' + (i % 2 == 0 ? '&#9643;' : '&#9645;') + '</option>'
536-
}
548+
if(j % p !== q) continue;
549+
550+
m = (j%4 == 0 ? (j/4)+1 : Math.floor(j/4)+2 )
551+
552+
const levelSize = (j % 2 === 0)
553+
? Math.pow(2, (endLevel - j) / 2)
554+
: Math.pow(2, (endLevel - j - 1) / 2) * 1.41;
555+
556+
const formattedSize = levelSize<1000 ? (Math.round(levelSize*100.0)/100)+'m' : (Math.round(levelSize*100.0/1000)/100)+'km' ;
557+
558+
const symbol = j % 2 === 0 ? '&#9643;' : '&#9645;';
559+
560+
const selected = ( Math.floor(size) <= levelSize ? ' selected' : '' )
561+
562+
html += `<option value="${levelValues[j]}"${selected}>L${j} (${m}d) (${formattedSize}) ${symbol}</option>`;
537563
}
564+
538565
return html
539566
}
540567

@@ -559,6 +586,8 @@ function isMarkerInsidePolygonOrMultiPolygon(x, y, poly) {
559586
// Check if the input is a multi-polygon or a single polygon
560587
const isMultiPolygon = Array.isArray(polys[0]) && Array.isArray(polys[0][0]);
561588

589+
console.log(isMultiPolygon)
590+
562591
// Function to check if a point is inside a polygon
563592
const checkInside = (polyPoints) => {
564593
for (let k = 0, l = polyPoints.length - 1; k < polyPoints.length; l = k++) {
@@ -896,9 +925,9 @@ function popUpFeature(feature,layer)
896925

897926
var popupContent = "";
898927

899-
if(feature.properties.short_code )
928+
if(feature.properties.logistic_id )
900929
{
901-
popupContent += "Logistic code: <big><code>" + (feature.properties.short_code.split(/[~]/)[1]) + "</code></big><br>";
930+
popupContent += "Logistic code: <big><code>" + (feature.properties.logistic_id.split(/[~]/)[1]) + "</code></big><br>";
902931
popupContent += "Area: " + value_area + " " + sufix_area + "<br>";
903932
popupContent += "Side: " + value_side + " " + sufix_side + "<br>";
904933

@@ -916,15 +945,15 @@ function popUpFeature(feature,layer)
916945
{
917946
if(feature.properties.type)
918947
{
919-
popupContent += (feature.properties.type).toUpperCase() + " code: <big><code>" + (feature.properties.code) + "</code></big><br>";
948+
popupContent += (feature.properties.type).toUpperCase() + " code: <big><code>" + (feature.id) + "</code></big><br>";
920949
}
921950
else if(feature.properties.index)
922951
{
923952
popupContent += "Code: <big><code>" + (feature.properties.index) + "</code></big><br>";
924953
}
925954
else
926955
{
927-
popupContent += "Code: <big><code>" + (feature.properties.code) + "</code></big><br>";
956+
popupContent += "Code: <big><code>" + (feature.id) + "</code></big><br>";
928957
}
929958
popupContent += "Area: " + value_area + " " + sufix_area + "<br>";
930959
popupContent += "Side: " + value_side + " " + sufix_side + "<br>";
@@ -949,17 +978,17 @@ function layerTooltipFeature(feature,layer)
949978
{
950979
var layerTooltip = feature.properties.code_subcell;
951980
}
952-
else if(feature.properties.short_code)
981+
else if(feature.properties.logistic_id)
953982
{
954-
var layerTooltip = '.' + (feature.properties.short_code.split(/[~]/)[1]);
983+
var layerTooltip = '.' + (feature.properties.logistic_id.split(/[~]/)[1]);
955984
}
956985
else if(feature.properties.index)
957986
{
958987
var layerTooltip = '.' + feature.properties.index
959988
}
960989
else
961990
{
962-
var layerTooltip = (feature.properties.code);
991+
var layerTooltip = (feature.id);
963992
}
964993

965994
layer.bindTooltip(layerTooltip,{ permanent:toggleTooltipStatus,direction:'auto',className:'tooltip' + feature.properties.base});
@@ -1009,16 +1038,16 @@ function onEachFeature(feature,layer)
10091038

10101039
L.circleMarker(center,{color: 'black', radius: 3, weight: 1, opacity: 0.8, fillOpacity: 0.6 }).addTo(layerPolygonCurrent);
10111040

1012-
if(feature.properties.scientic_code)
1041+
if(feature.id)
10131042
{
1014-
const codsci = (feature.properties.scientic_code).replace(/([GQHMRVJKNPSTZY])/g,'\.$1');
1015-
document.getElementById('sciCode').innerHTML = '<a href="' + uri_base + '/' + defaultMap.isocode + defaultMap.bases[defaultMap.scientificBase].symbol + feature.properties.scientic_code + '">' + defaultMap.isocode + defaultMap.bases[defaultMap.scientificBase].symbol +'<span class="feSchrift">'+ codsci +'</span></a>';
1043+
const codsci = (feature.id).replace(/([GQHMRVJKNPSTZY])/g,'\.$1');
1044+
document.getElementById('sciCode').innerHTML = '<a href="' + uri_base + '/' + defaultMap.isocode + defaultMap.bases[defaultMap.scientificBase].symbol + feature.id + '">' + defaultMap.isocode + defaultMap.bases[defaultMap.scientificBase].symbol +'<span class="feSchrift">'+ codsci +'</span></a>';
10161045
}
10171046

1018-
if(feature.properties.short_code)
1047+
if(feature.properties.logistic_id)
10191048
{
1020-
document.getElementById('sel_jurL3').innerHTML == feature.properties.short_code.split(/[-~]/)[2] ? '' : updateJurisd(feature.properties.isolabel_ext)
1021-
document.getElementById('logCode').innerHTML = (feature.properties.short_code.split(/[~]/)[1]).replace(reg, '$1.');
1049+
document.getElementById('sel_jurL3').innerHTML == feature.properties.logistic_id.split(/[-~]/)[2] ? '' : updateJurisd(feature.properties.isolabel_ext)
1050+
document.getElementById('logCode').innerHTML = (feature.properties.logistic_id.split(/[~]/)[1]).replace(reg, '$1.');
10221051
}
10231052

10241053
layer.on({
@@ -1220,7 +1249,7 @@ function afterLoadJurisdAll(featureGroup,fittobounds=true,genSelect=true)
12201249

12211250
if(genSelect)
12221251
{
1223-
document.getElementById('level_size').innerHTML = generateSelectLevel(defaultMap.bases[defaultMap.postalcodeBase],defaultMap.postalcodeBase,size_shortestprefix);
1252+
document.getElementById('level_size').innerHTML = generateSelectLevel(defaultMap.bases[defaultMap.postalcodeBase],size_shortestprefix);
12241253
}
12251254
}
12261255

@@ -1249,7 +1278,7 @@ function afterData(data,layer)
12491278
}
12501279
}
12511280

1252-
if(data.features[0].properties.isolabel_ext && !data.features[0].properties.short_code)
1281+
if(data.features[0].properties.isolabel_ext && !data.features[0].properties.logistic_id)
12531282
{
12541283
var nextURL = uri_base + "/" + data.features[0].properties.canonical_pathname
12551284
const nextTitle = 'AFA.codes: ' + data.features[0].properties.canonical_pathname;
@@ -1259,7 +1288,7 @@ function afterData(data,layer)
12591288
}
12601289
else if (!data.features[0].properties.index)
12611290
{
1262-
if(data.features[0].properties.short_code)
1291+
if(data.features[0].properties.logistic_id)
12631292
{
12641293
if(getJurisdAfterLoad)
12651294
{
@@ -1270,23 +1299,23 @@ function afterData(data,layer)
12701299
loadGeojson(uri,[layerJurisdAll],function(e){afterLoadJurisdAll(e,false)},function(e){});
12711300
}
12721301

1273-
var nextURL = uri_base + "/" + data.features[0].properties.short_code
1274-
const nextTitle = 'AFA.codes: ' + data.features[0].properties.short_code;
1302+
var nextURL = uri_base + "/" + data.features[0].properties.logistic_id
1303+
const nextTitle = 'AFA.codes: ' + data.features[0].properties.logistic_id;
12751304
const nextState = { additionalInformation: 'to canonical.' };
12761305

12771306
window.history.pushState(nextState, nextTitle, nextURL);
12781307

12791308

1280-
document.getElementById('fielddecode').value = data.features[0].properties.short_code.split(/[~]/)[1];
1309+
document.getElementById('fielddecode').value = data.features[0].properties.logistic_id.split(/[~]/)[1];
12811310
let df_short_code = ''
12821311

12831312
if(data.features[0].properties.isolabel_ext_abbrev)
12841313
{
1285-
df_short_code = '<small>'+(data.features[0].properties.isolabel_ext_abbrev)+ '~</small>' + data.features[0].properties.short_code.split(/[~]/)[1];
1314+
df_short_code = '<small>'+(data.features[0].properties.isolabel_ext_abbrev)+ '~</small>' + data.features[0].properties.logistic_id.split(/[~]/)[1];
12861315
}
12871316
else
12881317
{
1289-
df_short_code = '<small>'+(data.features[0].properties.short_code).replace(/~/,'~</small>');
1318+
df_short_code = '<small>'+(data.features[0].properties.logistic_id).replace(/~/,'~</small>');
12901319
}
12911320

12921321
document.getElementById('canonicalCode').innerHTML = df_short_code.replace( /([a-z])([A-Z])/g, '$1.$2' );
@@ -1300,7 +1329,7 @@ function afterData(data,layer)
13001329
{
13011330
sizeCurrentCell = data.features[0].properties.side;
13021331

1303-
document.getElementById('level_size').innerHTML = generateSelectLevel(defaultMap.bases[defaultMap.postalcodeBase],defaultMap.postalcodeBase,size_shortestprefix,sizeCurrentCell);
1332+
document.getElementById('level_size').innerHTML = generateSelectLevel(defaultMap.bases[defaultMap.postalcodeBase],size_shortestprefix,sizeCurrentCell);
13041333

13051334
let level = document.getElementById('level_size').value
13061335
let decimals = (level <= 64 ? 5 : 4)
@@ -1312,9 +1341,9 @@ function afterData(data,layer)
13121341
document.getElementById('fieldencode').value = 'geo:' + latRound(lat) + "," + latRound(lng) + ";u=" + document.getElementById('level_size').value;
13131342
}
13141343
}
1315-
else if(data.features[0].properties.code)
1344+
else if(data.features[0].id)
13161345
{
1317-
document.getElementById('fielddecode').value = data.features[0].properties.code;
1346+
document.getElementById('fielddecode').value = data.features[0].id;
13181347
}
13191348
}
13201349
}
@@ -1328,7 +1357,7 @@ function afterDataOlcGhs(data,layer)
13281357
{
13291358
sizeCurrentCell = data.features[0].properties.side;
13301359

1331-
document.getElementById('level_size').innerHTML = generateSelectLevel(defaultMap.bases[defaultMap.postalcodeBase],defaultMap.postalcodeBase,size_shortestprefix,sizeCurrentCell);
1360+
document.getElementById('level_size').innerHTML = generateSelectLevel(defaultMap.bases[defaultMap.postalcodeBase],size_shortestprefix,sizeCurrentCell);
13321361

13331362
document.getElementById('tcode').innerHTML = generateSelectTypeCode(data.features[0].properties.type);
13341363

@@ -1341,8 +1370,8 @@ function afterDataOlcGhs(data,layer)
13411370
document.getElementById('geoUri').innerHTML = 'geo:' + data.features[0].properties.type + ':' + latRound(lat,decimals) + "," + latRound(lng,decimals);
13421371
document.getElementById('fieldencode').value = 'geo:' + data.features[0].properties.type + ':' + latRound(lat) + "," + latRound(lng) + ";u=" + document.getElementById('level_size').value;
13431372

1344-
var nextURL = uri_base + "/geo:" + data.features[0].properties.type + ':' + data.features[0].properties.code
1345-
const nextTitle = 'AFA.codes: ' + data.features[0].properties.code;
1373+
var nextURL = uri_base + "/geo:" + data.features[0].properties.type + ':' + data.features[0].id
1374+
const nextTitle = 'AFA.codes: ' + data.features[0].id;
13461375
const nextState = { additionalInformation: 'to canonical.' };
13471376

13481377
window.history.pushState(nextState, nextTitle, nextURL);

0 commit comments

Comments
 (0)