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

              
                <script src="https://www.amcharts.com/lib/3/ammap.js"></script>
<script src="https://www.amcharts.com/lib/3/maps/js/usaLow.js"></script>
<script src="https://www.amcharts.com/lib/3/maps/js/canadaLow.js"></script>
<form id="user_form">

  <div class="option-group">
    <h2>Select US States</h2>
    <div id="usa" class="mapdiv"></div>
    <input type="hidden" name="usa" id="usa_field" value="" />
  </div>
  
  <div class="option-group">
    <h2>Select Canadian Provinces</h2>
    <div id="canada" class="mapdiv"></div>
    <input type="hidden" name="canada" id="canada_field" value="" />
  </div>
  
  <div class="option-group">
    <h2>Other options</h2>
    <p><input type="text" name="name" value="" placeholder="Your first name" /></p>
    <p><input type="text" name="surname" value="" placeholder="Your last name" /></p>
    <p><label><input type="checkbox" name="option1" value="1" /> Option #1</label></p>
    <p><label><input type="checkbox" name="option1" value="2" /> Option #2</label></p>
    <p><label><input type="checkbox" name="option1" value="3" /> Option #3</label></p>
    <p><input type="submit" value="Submit" onclick="return handleFormSubmit();" />
  </div>
  
  <div class="option-group">
    <h2>Form data debug</h2>
    <div id="form-debug">Once you select some options, click "Submit" to see form data here</div>
  </div>
						
</form>
              
            
!

CSS

              
                .mapdiv {
	width	: 250px;
	height	: 220px;
}
.option-group {
  float: left;
  overflow: auto;
  font-family: Verdana;
  font-size: 14px;
  margin-right: 20px;
  max-width: 250px;
}
.option-group h2 {
  color: #555;
  font-weight: 500;
  font-size: 17px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 10px;
  margin-bottom: 10px;
}
#form-debug {
  font-size: 12px;
}
              
            
!

JS

              
                /**
 * AmCharts.ready function handler is executed when the page loads
 * We are going to create both maps then. We'll store references to
 * all maps we create in the global maps variable so that we can
 * come back and get info from them later.
 */
var maps = {};
AmCharts.ready(function() {
  createMap('usa');
  createMap('canada');
});

/**
 * Creates a country map
 * $param country A map and container id
 */
function createMap (country) {
    var map = new AmCharts.AmMap();
    maps[country] = map;
    map.panEventsEnabled = true;
    map.backgroundColor = "#666666";
    map.backgroundAlpha = 1;
    
    map.zoomControl.panControlEnabled = false;
    map.zoomControl.zoomControlEnabled = true;
    
    var dataProvider = {
    map: country + "Low",
        getAreasFromMap: true
    };
    
    map.dataProvider = dataProvider;
    
    map.areasSettings = {
        autoZoom: false,
        color: "#CDCDCD",
        colorSolid: "#5EB7DE",
        selectedColor: "#5EB7DE",
        outlineColor: "#666666",
        rollOverColor: "#88CAE7",
        rollOverOutlineColor: "#FFFFFF",
        selectable: true
    };
    
    map.addListener('clickMapObject', function (event) {
        // deselect the area by assigning all of the dataProvider as selected object
        map.selectedObject = map.dataProvider;
        
        // toggle showAsSelected
        event.mapObject.showAsSelected = !event.mapObject.showAsSelected;
        
        // bring it to an appropriate color
        map.returnInitialColor(event.mapObject);
    });
    
    map.write(country);
}

function handleFormSubmit() {
  /**
   * Gather selected areas from all maps and populate
   * hidden fields with them
   */
  for(var x in maps) {
    var map = maps[x];
    var states = [];
    for (var i in map.dataProvider.areas) {
      var area = map.dataProvider.areas[i];
      if (area.showAsSelected) {
        states.push(area.id);
      }
    }
    document.getElementById(x + '_field').value = states.join(',');
  }
  
  /**
   * Add submited info debug information (optional step)
   * We're going to use jQuery to keep the code simple. However, jQuery
   * is not necessary to run the maps - we're just using it here to
   * print out debug info.
   */
  var formData = [];
  jQuery('#user_form').find('input[type=hidden],input[type=text],input:checked').each(function () {
    formData.push(this.name + ': <strong>' + this.value + '</strong>');
  });
  document.getElementById('form-debug').innerHTML = formData.join('<br />');
  
  /**
   * Prevent form from actually submitting.
   * We probably don't want it in real life situations.
   */
  return false;
}
              
            
!
999px

Console