United States of America

This interactive map is rendered within the browser using SVG.


<!DOCTYPE HTML>
<html lang="en-US">
  <head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="css/piximaps.min.css">
    <script src="js/piximaps.min.js"></script>
    <style>
      #chart { width: 540px; height: 540px; box-shadow: 0 1px 4px 0 rgba(0, 0, 0, 0.17); }
      .pixi .charttitle .subtitle { font-size: 0.9em; font-style: italic; text-anchor: start }
      .pixi .map .series .land.n0 { fill: #0D47A1 }
    </style>
    <script>
      window.addEventListener('load', () => {
        'use strict';

        // Select the DOM element displaying the event info:
        const el = document.getElementById('event');

        // Set the map attributes:
        const map = {
          type: 'geojson',
          url: '/maps/maps/unitedstatesofamerica.json',
          exclude: { gn_name: ['Alaska', 'Hawaii'] },
          coordinates: [40.0, -95.0],
          zoom: 8,
          minZoom: 1,
          maxZoom: 15,
        };

        // Define the chart settings:
        const opts = {
          chart: {
            width: window.innerWidth < (540 * 0.8) ? (window.innerWidth * 0.8) : 540,
            height: window.innerHeight < 540 ? window.innerHeight : 540,
          },
          title: { label: 'United States of America' },
          footer: { label: 'Source Wikipedia (estimation 2014)', x: 3, y: 0 },
          legend: { enabled: false },
        };

        // Define a list of map ids and set their properties:
        const states = [
          {'USA-US-MA': { title: 'Massachusetts', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '6,745,408' }}},
          {'USA-US-MN': { title: 'Minnesota', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '5,457,173' }}},
          {'USA-US-MT': { title: 'Montana', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '1,023,579' }}},
          {'USA-US-ND': { title: 'North Dakota', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '739,482' }}},
          {'USA-US-ID': { title: 'Idaho', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '1,634,464' }}},
          {'USA-US-WA': { title: 'Washington', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '7,061,530' }}},
          {'USA-US-AZ': { title: 'Arizona', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '6,731,484' }}},
          {'USA-US-CA': { title: 'California', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '38,802,500' }}},
          {'USA-US-CO': { title: 'Colorado', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '5,355,866' }}},
          {'USA-US-NV': { title: 'Nevada', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '2,839,099' }}},
          {'USA-US-NM': { title: 'New Mexico', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '2,085,572' }}},
          {'USA-US-OR': { title: 'Oregon', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '3,970,239' }}},
          {'USA-US-UT': { title: 'Utah', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '2,949,902' }}},
          {'USA-US-WY': { title: 'Wyoming', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '584,153' }}},
          {'USA-US-AR': { title: 'Arkansas', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '2,966,369' }}},
          {'USA-US-IA': { title: 'Iowa', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '3,107,126' }}},
          {'USA-US-KS': { title: 'Kansas', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '2,904,021' }}},
          {'USA-US-MO': { title: 'Missouri', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '6,063,589' }}},
          {'USA-US-NE': { title: 'Nebraska', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '1,881,503' }}},
          {'USA-US-OK': { title: 'Oklahoma', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '3,878,051' }}},
          {'USA-US-SD': { title: 'South Dakota', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '853,175' }}},
          {'USA-US-LA': { title: 'Louisiana', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '4,649,676' }}},
          {'USA-US-TX': { title: 'Texas', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '27,695,284' }}},
          {'USA-US-CT': { title: 'Connecticut', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '3,596,677' }}},
          {'USA-US-NH': { title: 'New Hampshire', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '1,326,813' }}},
          {'USA-US-RI': { title: 'Rhode Island', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '1,055,173' }}},
          {'USA-US-VT': { title: 'Vermont', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '626,562' }}},
          {'USA-US-AL': { title: 'Alabama', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '4,849,377' }}},
          {'USA-US-FL': { title: 'Florida', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '19,893,297' }}},
          {'USA-US-GA': { title: 'Georgia', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '10,097,343' }}},
          {'USA-US-MS': { title: 'Mississippi', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '2,994,079' }}},
          {'USA-US-SC': { title: 'South Carolina', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '4,832,482' }}},
          {'USA-US-IL': { title: 'Illinois', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '12,880,580' }}},
          {'USA-US-IN': { title: 'Indiana', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '6,596,855' }}},
          {'USA-US-KY': { title: 'Kentucky', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '4,413,457' }}},
          {'USA-US-NC': { title: 'North Carolina', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '10,054,192' }}},
          {'USA-US-OH': { title: 'Ohio', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '11,594,163' }}},
          {'USA-US-TN': { title: 'Tennessee', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '6,549,352' }}},
          {'USA-US-VA': { title: 'Virginia', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '8,326,289' }}},
          {'USA-US-WI': { title: 'Wisconsin', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '5,757,564' }}},
          {'USA-US-WV': { title: 'West Virginia', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '1,850,326' }}},
          {'USA-US-DE': { title: 'Delaware', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '935,614' }}},
          {'USA-US-DC': { title: 'District of Columbia', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '658,893' }}},
          {'USA-US-MD': { title: 'Maryland', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '5,976,407' }}},
          {'USA-US-NJ': { title: 'New Jersey', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '8,938,175' }}},
          {'USA-US-NY': { title: 'New York', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '19,746,227' }}},
          {'USA-US-PA': { title: 'Pennsylvania', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '12,787,209' }}},
          {'USA-US-ME': { title: 'Maine', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '1,330,089' }}},
          {'USA-US-MI': { title: 'Michigan', style: {fillColor: '#2196F3', fillOpacity: 0.75, strokeColor: 'white', strokeWidth: 0.1}, over: {fillOpacity: 1}, properties: { 'Population': '9,909,877' }}},
        ];

        // Set the overlay attributes:
        const poi = [
          {
            NY: {
              title: 'New York',
              style: { fillColor: 'navy', strokeColor: 'white', strokeWidth: 1 },
              geometry: {
                type: 'Point',
                radius: 5,
                coordinates: [40.7142700, -74.0059700]
              },
              properties: {
                φ: '40° 42\' 51" N',
                λ: '74° 00\' 21" W',
              },
            },
          },
          {
            LA: {
              title: 'Los Angeles',
              style: { fillColor: 'navy', strokeColor: 'white', strokeWidth: 1 },
              geometry: {
                type: 'Point',
                radius: 5,
                coordinates: [34.0522300, -118.2436800]
              },
              properties: {
                φ: '34° 03\' 08" N',
                λ: '118° 14\' 37" W',
              },
            },
          },
          {
            houston: {
              title: 'Houston',
              style: { fillColor: 'navy', strokeColor: 'white', strokeWidth: 1 },
              geometry: {
                type: 'Point',
                radius: 5,
                coordinates: [29.7632800, -95.3632700]
              },
              properties: {
                φ: '29° 45\' 47" N',
                λ: '95° 21\' 47" W',
              },
            },
          },
          {
            chicago: {
              title: 'Chicago',
              style: { fillColor: 'navy', strokeColor: 'white', strokeWidth: 1 },
              geometry: {
                type: 'Point',
                radius: 5,
                coordinates: [41.8500300, -87.6500500]
              },
              properties: {
                φ: '41° 51\' 00" N',
                λ: '87° 39\' 00" W',
              },
            },
          },
          {
            phil: {
              title: 'Philadelphia',
              style: { fillColor: 'navy', strokeColor: 'white', strokeWidth: 1 },
              geometry: {
                type: 'Point',
                radius: 5,
                coordinates: [39.9523400, -75.1637900]
              },
              properties: {
                φ: '39° 57\' 08" N',
                λ: '75° 09\' 49" W',
              },
            },
          },
        ];

        // Fix the chart dimensions:
        const el2 = document.getElementById('chart');
        el2.style.width = opts.chart.width + 'px';
        el2.style.height = opts.chart.height + 'px';

        const el3 = document.getElementsByClassName('viewsource');
        el3[0].style.width = opts.chart.width + 'px';

        // Draw the chart and add the POIs:
        const chart = Pixi.Map('#chart', map, opts);
        chart.overlayUpdate(states);
        chart.overlayAppend(poi);

        // Process the event 'overlayover':
        chart
          .on('overlayover', (data) => {
            el.textContent = 'Country: ' + data.overlay.title;
            if (data.overlay.geometry.type === 'Point')
              el.textContent = 'City: ' + data.overlay.title;
            else
              el.textContent = 'State: ' + data.overlay.title;
          })
          // Process the event 'overlayout':
          .on('overlayout', () => {
            el.textContent = '---';
          })
          .on('click', (data) => {
            console.log(data);
          });
        ;
      });
    </script>
  </head>
  <body>
    <div id="chart" class="pixi"></div>
  </body>
</html>
          

Methods

Map Methods

Name Return Description
.Map (id, map, series, options) this Creates, draws and returns the map object.
.moveTo (id, zoom) this Moves the map to get the overlay at the center of the chart (if the zoom parameter is omitted, the map doesn't scale; if the zoom is 'auto', the map is scaled to best fit).
.moveTo ([φ, λ], zoom) this Moves the map to get these coordinates at the center of the chart (if the zoom parameter is omitted, the map doesn't scale; if the zoom is 'auto', the map is scaled to best fit).

Overlay Methods

Name Return Description
.overlayAppend (overlays) this Appends one or more overlays.
.overlayUpdate (overlays) this Updates one or more overlays.
.overlayRemove ([ids]) this Removes one or more overlays.
.overlayDelete () this Removes all the overlays.
.overlayBlink ([ids]) this Starts one or more overlays.
.overlayUnblink ([ids]) this Stops one or more overlays.
.overlaySetVisible ([ids]) this Sets one or more overlays, identified by their id, visible.
.overlaySetInvisible ([ids]) this Sets one or more overlays, identified by their id, invisible.
.overlayAttachTooltip (id, xmlString, width, height) this Attachs a user defined tooltip to a given overlay. The user defined HTML5 tooltip is included in a SVG foreignObject element.

Event Methods

Name Return Description
.addEventListener (type, listener) this Registers the specified listener on the EventTarget it's called on.
.addOneTimeEventListener (type, listener) this Registers the specified listener on the EventTarget it's called on for a one-time event.
.removeEventListener (type, listener) this Removes the event listener previously registered with addEventListener ().
.on (type, listener) this Alias on addEventListener ().
.one (type, listener) this Alias on addOneTimeEventListener ().
.off (type, listener) this Alias on removeEventListener ().

Event Types

Attribute Type Object Info
'overlayover' String OverEvent Fired when the mouse enters on the overlay.
'overlayout' String OverEvent Fired when the mouse leaves the overlay.
'click' String ClickEvent Fired when the mouse clicks the overlay.
'dblclick' String ClickEvent Fired when the mouse double clicks the overlay.

Event Objects

OverEvent
Attribute Type Info
id String The id of the SVG element that fired the event.
title String The title of this SVG element.
style Object The style applied to this SVG element. See the section 'Series Options' for the detail of the style attributes.
properties Object/Array The data displayed by the tooltip when the mouse goes over or leaves this SVG element.
geometry Object The geometry of this SVG element.
ClickEvent
Attribute Type Info
overlay Object The OverEvent object of the (double) clicked overlay.
cursor Array The relative position of the point (double) clicked on the chart ([x, y]).

Map Attributes

map is an object with the following attributes:

Attribute Type Default Info
url String The url of the map file.
origin Object The position of the map against the grid.
origin.x Number 0 On x axis.
origin.y Number 0 On y axis.
zoom Number 1 The zoom attribute.
maxZoom Number 20 The maximum zoom level.
minZoom Number 0.1 The minimum zoom level.
draggable Boolean true Authorizes (true) or prevents (false) the map from being dragged.
scrollwheel Boolean true Enables (true) or disables (false) scrollwheel zooming on the map.
keypad Boolean true Enables (true) or disables (false) the keypad.

If the map object is undefined, the following default map object is processed:

map = { url: '../maps/worldmap.json', origin: { x: 0, y: 50 }, scale: 1 };

Series Options

The series are specified in an array of objects. The serie object has the following attributes:

Attribute Type Default Info
title String undefined The title of the serie.
style Object undefined The style to apply to the SVG elements that belong to the serie. By default, the css style is applied.
style.fillColor String undefined The fill color attribute.
style.fillOpacity Number undefined The color opacity attribute.
style.strokeColor String undefined The stroke color attribute.
style.strokeOpacity Number undefined The stroke color opacity attribute.
style.strokeWidth Number undefined The stroke width attribute.

Chart Options

Attribute Type Default Info
chart Object The chart attributes.
chart.type String map The type of map (currently, 'map' is the only option).
chart.width Number 600 The outer width of the chart.
chart.height Number 420 The outer height of the chart.
chart.grid Object The position and the size of the inner box.
chart.grid.x Number - The inner box origin on the x axis.
chart.grid.y Number - The inner box origin on the y axis.
chart.grid.width Number - The inner box width.
chart.grid.height Number - The inner box height.
chart.grid.margin Object The inner box margins.
chart.grid.margin.top Number 0 The inner box top margin.
chart.grid.margin.left Number 0 The inner box left margin.
chart.grid.margin.right Number 0 The inner box right margin.
chart.grid.margin.bottom Number 0 The inner box bottom margin.
title Object The title attributes.
title.label String The title text.
title.x Number - The horizontal anchor position of the title.
title.y Number - The vertical anchor position of the title.
subtitle Object The subtitle attributes.
subtitle.label String The subtitle text.
subtitle.x Number - The horizontal anchor position of the title.
subtitle.y Number - The vertical anchor position of the title.
legend Object The legend attributes.
legend.enabled Boolean true Enables or disables the legend.
legend.floating Boolean true Enables or not the legend to float above the map.
legend.layout String vertical The legend could be horizontal or vertical.
legend.align Object The legend position on the grid.
legend.align.horizontal String right The legend position on x axis could be: left, right or middle
legend.align.vertical String top The legend position on y axis could be: top, bottom or middle
legend.shift Object The shift position of the legend on the grid.
legend.shift.x Number 0 Moves slightly the legend on the x direction.
legend.shift.y Number 0 Moves slightly the legend on the y direction.
legend.icon Object The icon rectangle size.
legend.icon.width Number 10 The icon rectangle width.
legend.icon.height Number 10 The icon rectangle height.
tooltip Object The tooltip attributes.
tooltip.enabled Boolean true Enables (true) or disables (false) the tooltip.
tooltip.animated Boolean true smoothly moves (true) or not (false) the tooltip from previous item to current.

- means a computed value.

Overlay Attributes

The overlays are specified in an object. The overlays object has the following attributes:

Attribute Type Default Info
'id' String or Number The overlay Id.
'id'.title String undefined The name of the overlay.
'id'.style Object undefined The style applied to the overlay. By default, the css style is applied.
'id'.style.fillColor String undefined The color of the overlay.
'id'.style.fillOpacity String undefined The opacity of the overlay.
'id'.style.strokeColor String undefined The color of the overlay stroke.
'id'.style.strokeOpacity String undefined The opacity of the overlay stroke.
'id'.style.strokeWidth Number undefined The width of the overlay stroke.
'id'.over Object undefined The style to apply to the SVG elements that belong to the serie when the mouse is over the element. By default, the css style is applied.
'id'.over.fillColor String undefined The fill color attribute.
'id'.over.fillOpacity Number undefined The color opacity attribute.
'id'.over.strokeColor String undefined The stroke color attribute.
'id'.over.strokeOpacity Number undefined The stroke color opacity attribute.
'id'.over.strokeWidth Number undefined The stroke width attribute.
'id'.properties Object/Array null A set of data displayed by the tooltip when the mouse goes over the overlay.
'id'.properties[n] String ' ' If properties is an array of string, each string is a line of text displayed by the tooltip over the overlay.
'id'.properties[n] String ' ' If properties is an object, each pair of key/value is a list of items displayed by the tooltip over the overlay.
'id'.geometry Object The geometry of the overlay. It looks like to the GeoJSON specification. See details below for each type of overlay.

Point

The overlay Point has the following geometry attributes:

Attribute Type Default Info
'id'.geometry Object The geometry of the overlay (similar to the GeoJSON specification).
'id'.geometry.type String 'Point' The type of the overlay. Here a 'Point'.
'id'.geometry.radius Number 0 The radius of the 'Point' overlay (not in the GeoJSON specification).
'id'.geometry.coordinates Array [ ] The coordinates [φ, λ] of the center of the 'Point' overlay.