I am relatively new to Drupal and currently working on developing a custom map module. While my module functions correctly and displays the map along with relevant information, I encountered a challenge regarding calling my geojson file using a hard-coded path. I couldn't find documentation on how to dynamically call the file with a relative path to facilitate easy deployment of my module on different websites.
I suspect that utilizing routes might be the solution, but I'm unsure how to implement this approach effectively.
Below is a snippet of my code:
var url = "/drupal-site/recommended-project/web/modules/custom/carto_conseillers/src/geojson/annuaire_cf.geojson";
var centerProj = new ol.proj.transform([1.33333,47.583328], 'EPSG:4326', 'EPSG:3857');
const source = new ol.source.Vector({
url: url,
format: new ol.format.GeoJSON(),
});
const view = new ol.View({
center: centerProj,
zoom: 8
});
const vectorLayer = new ol.layer.Vector({
source: source,
style: function (feature) {
const color = feature.get('color') || '#c7c7c7';
style.getFill().setColor(color);
return style;
},
});
In addition, here are snippets from my librairies.yml, routing.yml, and ModuleController.php.
Any guidance or suggestions would be greatly appreciated.
Thank you for taking the time to review this.
Best Regards