Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                

<div id="map"></div>

<div id="menu">
<input id="kozui" type="checkbox" name="rtoggle" value="kozui">
<!-- See a list of Mapbox-hosted public styles at https://docs.mapbox.com/api/maps/styles/#mapbox-styles -->
<label for="kozui">洪水</label>
  
<input id="gake" type="checkbox" name="rtoggle" value="gake">
<label for="gake">がけ崩れ、土石流及び地滑り</label>

<input id="sio" type="checkbox" name="rtoggle" value="sio">
<label for="sio">高潮</label>
  
<input id="jishin" type="checkbox" name="rtoggle" value="jishin">
<label for="jishin">地震</label>

<input id="tsunami" type="checkbox" name="rtoggle" value="tsunami">
<label for="tsunami">津波</label>

<input id="kaji" type="checkbox" name="rtoggle" value="kaji">
<label for="kaji">火事</label>

<input id="hanran" type="checkbox" name="rtoggle" value="hanran">
<label for="hanran">内水氾濫</label>

  <input id="kazan" type="checkbox" name="rtoggle" value="kazan">
<label for="kazan">火山現象</label>

</div>


<div id="style">
    <input
    id="satellite"
    type="radio"
    name="rtoggle"
    value="satellite"    
    />
    <label for="satellite">3D+衛星</label>
    <input id="streets" type="radio" name="rtoggle" value="streets" checked="checked"/>
    <label for="streets">地図</label>
</div>


    <div class='absolute fl bottom my24 mx24 py24 px24 bg-gray-faint round'>
        <form id='params'>
          <h4 class='txt-m txt-bold mb6'>移動手段:</h4>
          <div class='mb12 mr12 toggle-group align-center'>
            <label class='toggle-container'>
              <input name='profile' type='radio' value='walking' checked>
              <div class='toggle toggle--active-null toggle--null'>徒歩</div>
            </label>
          </div>
          <h4 class='txt-m txt-bold mb6'>所要時間(概算):</h4>
          <div class='mb12 mr12 toggle-group align-center'>
            <label class='toggle-container'>
              <input name='duration' type='radio' value='10' checked>
              <div class='toggle toggle--active-null toggle--null'>10 min</div>
            </label>
            <label class='toggle-container'>
              <input name='duration' type='radio' value='20'>
              <div class='toggle toggle--active-null toggle--null'>20 min</div>
            </label>
            <label class='toggle-container'>
              <input name='duration' type='radio' value='30'>
              <div class='toggle toggle--active-null toggle--null'>30 min</div>
            </label>
        </form>
    </div>


              
            
!

CSS

              
                
body { margin: 0; padding: 0; }

#menu {
  position: absolute;
  background: #efefef;
  padding: 10px;
  font-family: 'Open Sans', sans-serif;
}

#style {
  position: absolute;
  background: #efefef;
  right: 10px;
  font-family: 'Open Sans', sans-serif;
}

#map { position: absolute; top: 0; bottom: 0; width: 100%; border-left: 1px solid #fff }

    .mapboxgl-popup {
      padding-bottom: 5px;
    }

    .mapboxgl-popup-close-button {
      display: none;
    }

    .mapboxgl-popup-content {
      font: 400 15px/22px 'Source Sans Pro', 'Helvetica Neue', Sans-serif;
      padding: 0;
      width: 250px;
    }

    .mapboxgl-popup-content-wrapper {
      padding: 1%;
    }

    .mapboxgl-popup-content h3 {
      background: rgb(61, 59, 59);
      text-align: center;
      color: #fff;
      margin: 0;
      display: block;
      padding: 15px;
      font-weight: 700;
      margin-top: -5px;
    }

    .mapboxgl-popup-content h4 {
      margin: 0;
      display: block;
      padding: 10px 3px 10px 10px;
      font-weight: 400;
    }

    .mapboxgl-popup-content img{
      display: block;
      margin-left: auto;
      margin-right: auto;
      width: 50%;
    }

    .mapboxgl-container {
      cursor: pointer;
    }

    .mapboxgl-popup-anchor-top>.mapboxgl-popup-content {
      margin-top: 3px;
    }

    .mapboxgl-popup-anchor-top>.mapboxgl-popup-tip {
      border-bottom-color: rgb(61, 59, 59);
    }
              
            
!

JS

              
                
    var streetstyle = 'mapbox://styles/tichimura/ckm3oa0jk63gh17o7b14j7vt8';
    var satellitestyle = 'mapbox://styles/tichimura/ckm4a890pbr9q17o1mn240y7c';

    mapboxgl.accessToken = 'pk.eyJ1Ijoic3ZjLW9rdGEtbWFwYm94LXN0YWZmLWFjY2VzcyIsImEiOiJja21kYWtiMXIyamo4MnBqeHhvZmhvMHFjIn0.sormn2WnNbOfS3emWH6XkQ';

    var map = new mapboxgl.Map({
        container: 'map',
        style: streetstyle + '/draft',
        center: [139.73100, 35.66572],
        zoom: 11.15,
        localIdeographFontFamily: "'Noto Sans', 'Noto Sans CJK SC', sans-serif,'Arial Unicode MS Regular'"
      
    });

    var layerList = document.getElementById('style');
    var inputs = layerList.getElementsByTagName('input');
    

    // スタイルが増えたらここを編集する
    function switchLayer(layer) {
        var layerId = layer.target.id;
        if(layerId === 'streets'){
          
          map.setStyle(streetstyle +'/draft');
     
        }else if(layerId === 'satellite'){         
          map.setStyle(satellitestyle +'/draft');          
          
        }
    }
    
    for (var i = 0; i < inputs.length; i++) {
        inputs[i].onclick = switchLayer;
    }


    // // Create variables to use in getIso()
    var urlBase = 'https://api.mapbox.com/isochrone/v1/mapbox/';
    var lon = 139.61124;
    var lat = 35.64312;
    var profile = 'walking';
    var minutes = 10;

    var menuList = document.getElementById('menu');
    var inputs = menuList.getElementsByTagName('input');
    
    map.on('styledata', function() {
      
        if(map.getSource('iso') === undefined){
      
      
        map.addSource('iso', {
          type: 'geojson',
          data: {
            'type': 'FeatureCollection',
            'features': []
          }
        });

        map.addLayer({
          'id': 'isoLayer',
          'type': 'fill',
          // Use "iso" as the data source for this layer
          'source': 'iso',
          'layout': {},
          'paint': {
            // The fill color for the layer is set to a light purple
            'fill-color': '#5a3fc0',
            'fill-opacity': 0.4
          }
        }, "points");               
        }
      
    });

    map.on('load', function () {
        // Add a GeoJSON source containing place coordinates and information.

      if(map.getSource('iso') === undefined){

        map.addSource('iso', {
          type: 'geojson',
          data: {
            'type': 'FeatureCollection',
            'features': []
          }
        });

        map.addLayer({
          'id': 'isoLayer',
          'type': 'fill',
          // Use "iso" as the data source for this layer
          'source': 'iso',
          'layout': {},
          'paint': {
            // The fill color for the layer is set to a light purple
            'fill-color': '#5a3fc0',
            'fill-opacity': 0.4
          }
        }, "points");               

      }
      
      
        var params = document.getElementById('params');
      
        params.addEventListener('change', function(e) {
            if (e.target.name === 'profile') {
                profile = e.target.value;
                // getIso();
            } else if (e.target.name === 'duration') {
                minutes = e.target.value;
                // getIso();
            }
        });       
      
      
        menuList.addEventListener('change', function (e) {

          
          if(e.target.checked){

            if(map.getLayoutProperty('points','visibility') == 'none') map.setLayoutProperty('points', 'visibility', 'visible');
            
            var filters = map.getFilter('points');
            var newfilter = true           
            
            if(Array.isArray(filters)){
              
                filters.forEach(function(element) {
                  if (element.includes(e.target.labels[0].textContent)){
                    newfilter = false;
                  } 
                });
              
                if( newfilter == true){
                  filters.push(["==",e.target.labels[0].textContent,"◎"]);
                  map.setFilter('points', filters);
                }
                // console.log(filters);
                }else{
                  map.setFilter('points', ['all', ["==",e.target.labels[0].textContent,"◎"]]);
                 // map.setFilter('points', ['all', ["==",e.target.labels[0].textContent,"◎"]]);
              };
                        
          }else{
            var filters_now = map.getFilter('points');
            var filters_new = new Array();
            filters_now.forEach(function(element) {
              if (!element.includes(e.target.labels[0].textContent)){
                    filters_new.push(element);
                  } 
            });
            
            if(filters_new.length > 1){
              map.setFilter('points', filters_new);            
            }else{
              map.setLayoutProperty('points', 'visibility', 'none')
              map.setFilter('points', null);
            }
                        
          }

        });              
             
      
        map.on('click', 'points', function (e) {
          
          
          var popup = new mapboxgl.Popup()
          .setLngLat(e.lngLat)
          .setHTML(`<h3>` + e.features[0].properties.指定緊急避難場所 + `</h3>`)
          .addTo(map);
          
          // popup.on('open', function(){

          lon = popup.getLngLat().lng;
          lat = popup.getLngLat().lat;
          getIso();
                    
        });
      
    });

    function getIso() {

      var query = urlBase + profile + '/' + lon + ',' + lat + '?contours_minutes=' + minutes + ',' + (parseInt(minutes,10) + 10) + ',' + (parseInt(minutes,10) + 20) + '&polygons=true&access_token=' + mapboxgl.accessToken;
      
      $.ajax({
        method: 'GET',
        url: query
      }).done(function(data) {
        map.getSource('iso').setData(data);
      })
    };  

              
            
!
999px

Console