Skip to content

Commit

Permalink
filter system bug fixed
Browse files Browse the repository at this point in the history
caused by new geojson source and fixed. Loads json file for once. Helps optimiation as well.
  • Loading branch information
gorkemkurban committed Nov 18, 2024
1 parent de9c3e8 commit c285f5e
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions Apps/3DHeritageScripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,30 @@ viewer.homeButton.viewModel.command.beforeExecute.addEventListener(function (e)
/**
* Function to load GeoJSON data and add it to the viewer. *
*/
let markersInitialized = false; // Markers will only be loaded once

async function loadGeoJson() {
try {
if (markersInitialized) return; // If markers are already loaded, do not load again

const dataSource = await Cesium.GeoJsonDataSource.load('https://opendem.info/cgi-bin/getDenkmal.py');
await viewer.dataSources.add(dataSource);

const entities = dataSource.entities.values;

// Iterate over entities and set their properties
entities.forEach(entity => {
if (entity.position) {
const name = entity.properties.kurzbezeichnung ? entity.properties.kurzbezeichnung.getValue() : '';

// Set billboard graphics
// Define the marker
entity.billboard = new Cesium.BillboardGraphics({
image: 'Images/marker.png',
width: 32,
height: 32,
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
});

// Set label graphics
// Define the marker label
entity.label = new Cesium.LabelGraphics({
text: name,
font: '11pt sans-serif',
Expand All @@ -149,28 +152,22 @@ async function loadGeoJson() {
pixelOffset: new Cesium.Cartesian2(0, -32),
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
});

// Adjust label position based on zoom level

viewer.scene.preRender.addEventListener(function () {

var zoomThreshold = 5000;
var currentZoom = viewer.camera.zoomFactor;
entity.billboard.pixelOffset = currentZoom < zoomThreshold
? new Cesium.Cartesian2(0, -32)
: new Cesium.Cartesian2(0, -16);

});

}
});

// Mark that markers are loaded
markersInitialized = true;

// Apply the selected filter initially
const selectedRadio = Object.keys(radios).find(key => radios[key].checked);
updateEntities(selectedRadio);

} catch (error) {
console.error(error);
}
}


// Load GeoJSON data
// Wait till scene is ready using scene.globe.tileLoadProgressEvent
viewer.scene.globe.tileLoadProgressEvent.addEventListener((count) => {
Expand Down

0 comments on commit c285f5e

Please sign in to comment.