npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kapusons-ui-map

v1.3.10

Published

Kapusons implementation of interactive map through GeoJson data

Downloads

12

Readme

kapusons-ui-map is a Kapusons implementation of interactive maps through GeoJson data. It uses Google Maps API. It allows you to easily render polygons of all the world's states over a google map.

preview

Features

Complete navigation flow

kapusons-ui-map consists in a mini-site with a common navigation flow:

  • A general map, with the states you've choosen, as an index page
  • A second level shows markers associated with the selected country with few informations
  • A third level goes inside the marker info and displays a longer description (enabled for italian regions, for italy and afghanistan as example)

GeoJson data

kapusons-ui-map provides two GeoJson libraries with polygons coordinates for:

  • Italian regions
  • All the world's states until 2015.

Fully configurable jQuery plugin

kapusons-ui-map requires jQuery as it's released as a jQuery plugin.

Installation

Setup development environment

git clone [email protected]:KapusonsSRL/kapusons-ui-map.git
npm install
gulp serve

As a npm package

npm install kapusons-ui-map --save

Usage

You will need to include:

  • Google maps API with proper API key
  • jQuery library
  • The JavaScript file kapusons-ui-map.js (or its minified version kapusons-ui-map.min.js)
  • The css file kapusons-ui-map.css (or its minified version kapusons-ui-map.min.css)

Once that is done you'll only need a dom element in your html to initialize the jQuery plugin:

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

and call kapusonsUiMap plugin inside a $(document).ready function:

  $('#map-wrapper').kapusonsUiMap()

Configuration

A more complex initialization with all options set could look like this:

$('#map-wrapper').kapusonsUiMap({
  dataSource: "json/world.subset.json", 
  l10n: 'en',
  mapTitle: 'Regions',
  showLeftColumn: true,
  showRegionTooltip: true,
  showRegionDetail: true,
  map: {
    center: {
      lat: 38.513456, 
      lng: 44.523900
    },
    zoom: 5,
    scrollwheel: false,
    gestureHandling: 'cooperative',
      mapTypeControlOptions: {
        style: google.maps.MapTypeControlStyle.DEFAULT  
    },
    styles: [
        {
          featureType: "all",
          elementType: "labels",
          stylers: [
            { 
              visibility: "off" 
            }
          ]
        }
    ]
  },
  features:{
    fillColor: "#3367D6",
    fillColorSelected: "#4285F4",
    strokeWeight: 1.5,
    strokeColor: '#96C7FC',
    fillOpacity: 1
  },
  regionOnClick: null,
  onMapLoaded: null
})

Options

  • dataSource: defines which json will populate your map; kapusons-ui-map provides two GeoJson libraries (Italian regions and all the world's states until 2015). See how to generate a custom GeoJson library starting from this two.
  • l10n: defines the localization for your map
  • mapTitle: a string title for your map
  • showLeftColumn: displaying or not the left column navigation menu
  • showRegionTooltip: displaying or not the tooltip on state/polygon hover. The tooltip has a class that corresponds to the hovered region name (e.g. .Egypt, .Italy etc...)
  • showRegionDescription: displaying or not the third level info of a selected state/region
  • map: MapOptions object specification: Google Maps JavaScript API V3 Reference
    • center
      • lat
      • lng
    • zoom
    • scrollwheel
    • gestureHandling
    • mapTypeControlOptions
    • styles
      • featureType
      • elementType
      • stylers
        • visibility
  • features: defines the polygon styles
    • fillColor
    • fillColorSelected
    • strokeWeight
    • strokeColor
    • fillOpacity
  • regionOnClick: defines a custom handler for click event on a state/polygon; this function ovverrides the default behavior
  • onMapLoaded: the callback fired when the map is idle

How to generate a custom GeoJson library as data source

You can easily create your GeoJson data source starting from the two GeoJson libraries provided by kapousns-ui-map. As you probably want to display a custom set of polygons/states, you'll find a usefull gulp task for this purpose. As example:

gulp json:extract --regions "it,fr,gb" --featureProperty ISO_A2 --searchIn world
  • In the --regions parameter you can define a list of states/polygon you want to include in your map in the form of a comma separated string. Each value must match one of those supported standard code (ISO 3166 and others): SOV_A3, ADMIN, ADM0_A3, GEOUNIT, GU_A3, SUBUNIT, SU_A3, name, NAME_LONG, BRK_A3, BRK_NAME, BRK_GROUP, ABBREV, POSTAL, FIPS_10_, ISO_A2, ISO_A3, ISO_N3, UN_A3, WB_A2, WB_A3, ADM0_A3_IS, ADM0_A3_US
  • You'll define the selected standard code in the --featureProperty parameter, as a comparison value
  • the --searchIn parameter defines in which data source you'll search the specified regions (availables data source are world and italy)

This task generates a (italy/world).subset-json file in the src/json folder.

Once that is done, you can minify your new GeoJson file by running this task:

gulp json:minify --filename "your-brand-new.json"

By running the gulp serve task all the json file in the src folder will be copied into the dist/json folder.

Localization

Kapusons-ui-map provides a minimal support for l10n:

  • add a LOCALE.js file with proper translations in the src/js/l10n folder (use the it.js file as a reference)
  • add the l10n option in the plugin configuration: $('#map-wrapper').kapusonsUiMap({ l10n: 'it' })

Contributing

Once you've made your commits:

  1. Fork kapusons-ui-map
  2. Create a topic branch - git checkout -b my_branch
  3. Push to your branch - git push origin my_branch
  4. Create a Pull Request from your branch
  5. That's it!

License

MIT (http://www.opensource.org/licenses/mit-license.php)