Я хочу отобразить свою карту MapBox в мае <div id="map">...
, но я получаю две ошибки: >This page appears to be missing CSS declarations for Mapbox GL JS...
и >_ReferenceError: _typeof is not defined
Я прочитал много вопросов об этом в Интернете, но все еще нене работает: /
views / layouts / Applications.html.erb
<html>
<head>
<title>MarryApp</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<!-- <link href="https://api.tiles.mapbox.com/mapbox-gl-js/v0.44.2/mapbox-gl.css" rel="stylesheet" /> -->
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= stylesheet_pack_tag 'application', media: 'all' %>
<%= javascript_include_tag 'application' %>
</head>
<body>
<%= render 'shared/navbar' %>
<%= render 'shared/flashes' %>
<div class="container-fluid">
<div class="row">
<div class="col-sm-12 p-0">
<%= yield %>
</div>
</div>
</div>
<%= javascript_pack_tag 'application' %>
</body>
</html>
app / javascript / packs / application.js
import 'mapbox-gl/dist/mapbox-gl.css';
import { initMapbox } from '../plugins/mapbox';
initMapbox();
app / javascript / plugins / mapbox.js
import mapboxgl from 'mapbox-gl';
const initMapbox = () => {
const mapElement = document.getElementById('map');
if (mapElement) { // only build a map if there's a div#map to inject into
mapboxgl.accessToken = mapElement.dataset.mapboxApiKey;
const map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v10'
});
}
console.log(mapElement.dataset.mapboxApiKey)
};
export { initMapbox };