Question:
Can you help me display these points dynamically (i.e. depending on the page we are on)?
Product:
Wix Editor
What are you trying to achieve:
[Explain the details of what you are trying to achieve. The more details you provide, the easier it is to understand what you need.]
What have you already tried:
I am creating a site on Wix. I created a CMS database with dynamic pages. It works very well. I would however like to add a map for each trip (each page is one trip). So I created a Velo javascript table with the list of points to display on the map.
Additional information:
// Récupérer l'élément de carte
const mapElement = $w('#votre_id_de_carte').value; // Remplacez 'votre_id_de_carte' par l'ID de votre élément de carte
// Initialiser la carte Mapbox
mapboxgl.accessToken = 'YOUR_MAPBOX_ACCESS_TOKEN';
const map = new mapboxgl.Map({
container: mapElement,
style: 'mapbox://styles/mapbox/streets-v11',
center: [0, 0], // Coordonnées de départ (peu importe car nous allons ajuster la vue)
zoom: 10 // Niveau de zoom initial
});
// Ajouter des marqueurs pour chaque point d'intérêt
pointsOfInterest.forEach(point => {
new mapboxgl.Marker()
.setLngLat(point.coordinates)
.setPopup(new mapboxgl.Popup().setHTML(`<h3>${point.name}</h3><p>${point.description}</p>`))
.addTo(map);
});
// Ajuster la vue pour inclure tous les marqueurs
const bounds = new mapboxgl.LngLatBounds();
pointsOfInterest.forEach(point => {
bounds.extend(point.coordinates);
});
map.fitBounds(bounds, { padding: 50 });
In fact, I created a travel site on Wix. I have a CMS that allows me to list all the destinations that I offer. When we click on a destination, we have the details of the trip with the difference points of the journey. It is on this page that I want to integrate the map with the points on it that correspond to the journey.
Today, I have already personalized my map via the mapbox site, but the point that is blocking me is the integration of this map on the detailed travel page as well as the display of the points on it.
Mapbox allows you to do a lot of things compared to Google.
I just installed the package on the site.
but I have a problem with the code.
Should it be imported into the code as well as the package?
YOU WILL NEED TO INTEGRATE ON → BACKEND <— not on frontend!!!
SHOW CODES → ALWAYS IN → CODE-BLOCKS → much better then PICs → because EDITABLE → COPY & PASTE.
Which package have been installed ? → full name of package (the shown NPM above) ???
I think you are not realising how deep it could you drawn into code.
Maybe you first try to find an EMBED-VERSION provided by Map-Box, maybe?
Inside your Map-Box-Generator/Editor → isn’t there an options which allows you to generate a CODE for your current edited/generated MAP on MapBox ???
For COPY and PASTE ?
Since you are using → API-KEYS → (SENSITIVE DATA) ← you will also need to look for Wix-Secrets, where you will have to store the API-KEY (SECURE-STORAGE). <— next API-IMPLEMENTATION needed!
Open the NPM-README and check the APIs and CODE-STRUCTUREs —> done !?
Generate your BACKEND-JSW-FILE inside of your Wix-Editor → BACKEND
Generate the code inside of your created JSW-FILE.
import mapboxgl from 'mapbox-gl/dist/mapbox-gl';
import MapboxWorker from 'mapbox-gl/dist/mapbox-gl-csp-worker';
export function myFunction() {
return mapboxgl; //inspect what it gives you on frontend (console-logging-it)
}
Copy the name of the generated JSW-FILE → for ex. → mapBox.jsw
Create a new wix-page (give it a name for example Map-Box) → your frontend.
Activate the dev-mode → done!
Navigate to the CODE-SECTION of your Map-Box-Page.
Import one of your generated functions of your BACKEND-MODULE (mapBox.jsw) on your FRONTEND… import { myFunction } from 'backend/mapBox.jsw'
Frontend-example-code:
import { myFunction } from 'backend/mapBox.jsw';
$w.onReady(async()=>{console.log('Page ready...');
let mapBox = await myFunction; console.log('RESULT: ', mapBox);
// rest of code.......
// rest of code.......
// rest of code.......
// rest of code.......
});
By the way → you also can add this into an HTML-Component inside of your Wix-Website and EDIT it on your own…