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

wp-map-picker

v0.7.1

Published

This jQuery plugin for WordPress can be used to transform an input field into a flexible map field with a location picker.

Downloads

4

Readme

WP Map Picker

This jQuery plugin for WordPress can be used to transform an input field into a flexible map field with a location picker.

Plugin Screenshot

Features

  • transforms a simple input field in the WordPress admin into a map picker where you can both enter a value in an input field (with autocompletion) and automatically show it on the map or select a location on the map and automatically put it in the input field
  • handles how the value is stored in the input field (you're free to choose between address and coords)
  • uses the Google Maps API v3 to display the map
  • is based on jQuery UI Widget for a standardized API
  • uses WordPress Core technology wherever possible
  • customizable with numerous settings which can be defined in the function call or as data attributes

Installation and Setup

Install the plugin

The preferred method to install this package is to use NPM.

npm install wp-map-picker

Enqueue script and stylesheet

To include the script and stylesheet, enqueue the script and stylesheet like so:

<?php
$gmaps_url = add_query_arg( 'language', str_replace( '_', '-', get_locale() ), 'https://maps.google.com/maps/api/js' );
wp_enqueue_script( 'google-maps', $gmaps_url, array(), false, true );
wp_enqueue_script( 'wp-map-picker', 'PATHTOMAPPICKER/wp-map-picker.min.js', array( 'jquery', 'jquery-ui-widget', 'jquery-ui-autocomplete', 'google-maps' ), '0.7.1', true );
wp_enqueue_style( 'wp-map-picker', 'PATHTOMAPPICKER/wp-map-picker.min.css', array(), '0.7.1' );

Make sure to use the proper hook to enqueue the assets, for example in the admin_enqueue_scripts hook. Furthermore the dependencies in the above code sample must explicitly be included, otherwise the plugin will not work. Note that the above example will also load the Google Maps API in the current language set in WordPress.

Initialize the plugin on your fields

To turn your raw and boring input fields into really exciting map picker fields, you simply need to run the main plugin function wpMapPicker() on your jQuery elements. For example:

jQuery( '.custom-map-field' ).wpMapPicker();

Plugin Settings

The plugin supports numerous settings so that you can tweak how your fields work. There are two ways to apply settings to a field: Either specify the settings (as an object) when initializing the plugin in Javascript, or apply them as data attributes on the field.

Here you find a list of all available settings:

store:

  • Determines how the attachment is stored in the input field
  • Accepts 'address' or 'coords'
  • Default: 'address'

storeAdditional:

  • Object with additional input element selectors to set their values automatically; these inputs have to exist in the page as they will not be created manually
  • Accepts an object where each property is a selector for one input element and the property value is the type of information to store in that element; valid values are 'address', 'coords', 'latitude', 'longitude' or any other field that the Google Geocoder returns in a response
  • Default: false

zoom:

  • Sets the initial zoom level for the map
  • Accepts an integer between 1 and 18
  • Default: 15

draggable:

  • Defines whether the map is draggable or not
  • Accepts a boolean
  • Default: true

mapType:

  • Specifies the type of the map
  • Accepts 'roadmap', 'satellite', 'terrain' or 'hybrid'
  • Default: 'roadmap'

defaultLocation:

  • Specifies the default location if the input field does not contain any
  • Accepts an object with three properties (lat for the latitude default, lng for the longitude default and zoom for the initial zoom level used when the default location is applied)
  • Default: { lat: '0.0', lng: '0.0', zoom: 2 }

decimalSeparator:

  • Defines the decimal separator used for coords
  • Accepts '.' or ','
  • Default: '.'

change:

  • An optional callback function to run when the location has changed
  • Accepts a function
  • Default: false

clear:

  • An optional callback function to run when the location has been cleared (reset to default)
  • Accepts a function
  • Default: false

Plugin Methods

There are a number of methods that you can call by using a construct like jQuery( '{{SELECTOR}}' ).wpMapPicker( '{{NAME_OF_FUNCTION}}' {{,FUNCTION_PARAMS}} ).

clear:

  • Clears the location selection (resets it to the default)

refresh:

  • Refreshes the Google map; this needs to be run whenever the map becomes visible inside dynamic content, for example an accordion

Contribute

I'm always grateful for contributions, whether it is about enhancements or bugfixes, especially since the plugin is at an early stage. If you encounter bugs, compatibility issues or totally missing functionality that must be in this plugin, I would appreciate if you created an issue. Or even better, if you can, do it yourself and open a pull-request.