Mapbox
참조: www.mapbox.com
Mapbox에 존재하는 mapbox-sdk 라는 Node 클라이언트 설치
controllers 폴더 내 <campgrounds.js>
const mbxGeocoding = require("@mapbox/mapbox-sdk/services/geocoding");
const mapBoxToken = process.env.MAPBOX_TOKEN;
const geocoder = mbxGeocoding({ accessToken: mapBoxToken })
models 폴더 내 campgrounds.js
const CampgroundSchema = new Schema({
title: String,
images : [
{
url: String,
filename: String
}
],
geometry: {
type: {
type:String,
enum: ['Point'],
required: true
},
coordinates: {
type: [Number],
required: true
}
},
price: Number,
description: String,
location: String,
author : {
type:Schema.Types.ObjectId,
ref: 'User'
},
reviews: [
{
type: Schema.Types.ObjectId,
ref: 'Review'
}
]
});
Mabox GL JS
show.ejs 하단에 등록
const campground = <%-JSON.stringify(campground) %>
showPageMap.js
mapboxgl.accessToken = mapToken;
const map = new mapboxgl.Map({
container: "map", // container ID
style: "mapbox://styles/mapbox/streets-v11", // style URL
center: campground.geometry.coordinates, // starting position [lng, lat]
zoom: 9, // starting zoom
projection: "globe", // display the map as a 3D globe
});
map.on("style.load", () => {
map.setFog({}); // Set the default atmosphere style
});
new mapboxgl.Marker()
.setLngLat(campground.geometry.coordinates)
.addTo(map)