1.1.8 • Published 5 years ago

@wmyl/places v1.1.8

Weekly downloads
-
License
ISC
Repository
github
Last release
5 years ago

@wmyl/places npm version

Interactive map based on Google Maps. Each place can have a popup with information, along with other features such as in-view list and clustering.

Installation

npm install --save @wmyl/places

Usage

Step 1 - Get Google Maps API key

Don't worry! It's free, at least for a smaller amount of request.

https://developers.google.com/maps/documentation/javascript/get-api-key

Step 2 - Add HTML

Add container such as div with class name places in HTML

<div class="places"></div>

Step 3 - Init JavaScript

import Places from '@wmyl/places';

...

const options = {
    tag: "https://maps.googleapis.com/maps/api/js?key=<YOUR_KEY_HERE>",
    places: [{
        lat: 57.682909,
        lng: 11.932970,
        name: 'My First Place'
        address: 'Exampleroad 23',
        link: 'https://github.com/wmyl/places',
        phone: '555-1234567',
        comment: 'This place is wonderful!'
    }, {
        lat: 58.232909,
        lng: 07.562970,
        name: 'My Second Place'
        address: 'Exampleroad 25',
        link: 'https://github.com/wmyl/places',
        phone: '555-1234569',
        comment: 'This place is almost as wonderful!'
    }],
    popup: true,
    mapStyle: 'minimalistic',
    imagePath: '/assets/static/images/dog',
    sidebar: {
        footer: {
            text: 'Visit our site!',
            logo: '/assets/static/images/companyLogo.png',
            logoLink: 'https://github.com/wmyl/places'
        }
    },
};

new Places(options);

...

Step 4 (Optional) - Add custom styling

You can override all styling on the map with your own css.

Options

OptionTypeRequiredDefaultDescription
tagstringYesGoogle Maps Script tag with API Key
placesarrayNo[]List of place objects
popupanyNoWhether to show popup on marker click or not and if so, specify popup options
mapStyleanyNo'default'Use one of predefined map styles or provide own
startPosobjectNo{ lon: 57.7004286, lat: 11.9543521 }Start position of map. Will change if geoloc is enabled and position is found
noGeolocBooleanNofalseSet to true to disable geolocation in map
pinImagePathstringNoPath to pin images. Will pick different depending on place type. See below.
iconImagePathstringNoSame as pinImagePathPath to icon images. Will pick different depending on place type. See below.
sidebaranyNoWhether to use sidebar or not and if so, specify options
clustereranyNofalseWhether to use marker clustering or not and if so, specify clusterer options

Place object

PropertyTypeRequiredDefaultDescription
latnumberYesThe latitude of the place
lngnumberYesThe longitude of the place
typestringNoThe type of the place. Not predefined, so it can be anything. Will only affect the icon of the place.
namestringYesThe name of the place. This must match the name in Google Maps for the search to work properly.
addressstringYesThe address of the place. This must match the address in Google Maps for the search to work properly.
linkstringNoURL to the link for the place
phonestringNoPhone number to the place
commentstringNoShort description or comment of the place

Popup options

OptionTypeRequiredDefaultDescription
noResultTextstringNoVi hittar tyvärr inte några resultat på <PLACE_NAME>Text shown when to result is found for a location. Use <PLACE_NAME> to insert the name of the place.
linkstringNoURL for link shown when a place is searched for but not present, such as "Contact Us". Both link and link text is required.
textLinkstringNoText for link shown when a place is searched for but not present, such as "Contact Us". Both link and link text is required.
noResultHTMLstringNoCustom HTML to override all other HTML in the popup, when place is not present.

Map styling

It is possible to either specify a custom array of Google Map styles, see more here: https://mapstyle.withgoogle.com/

It is also possible to specify one of predefined styles. Current valid stlyes are:

  • default
  • minimalistic

Image paths

Path to the collection of images for the place icons. The images need to be in .png-format. The file ending (.png) will automatically be appended. If types are used, this will be appended to the image path as well. Note that if pinImagePath is not specified, Google Maps default pins will be used for the map and no icons will be shown in sidebar.

For example, if image path is place_ and a place has type "hotel" the map will expect there is an image named place_hotel.png. If the place has no type, simply place_.png will be expected.

Sidebar options

Options can be specified but for default usage true is enough. Will display a sidebar to the leftwith all places in viewport. Has a search bar at the top. On mobile, the sidebar will be on the lower half of the screen and is minimizable. On mobile phones, the sidebar will be minimized when tapping a marker on the map.

OptionTypeRequiredDefaultDescription
searchBarobjectNoSearch bar options object. If the sidebar is enabled, the searchbar is always enabled too.
footeranyNofalseWhether to use sidebar footer or not and if so, specify options.
mobileListToggleIconstringNoImage to use for closing and opening sidebar on smaller devices (preferably an arrow)

Search bar options

OptionTypeRequiredDefaultDescription
searchIconstringNoImage to use as the search icon (typically magnifying glass)
placeholderstringNoPlaceholder for search bar

Footer options

OptionTypeRequiredDefaultDescription
htmlstringNoReplaces all HTML in the footer with this string.
textstringNoText shown in footer
logostringNoPath to image to use in logo
logoLinkstringNoURL for the logo (requires logo image)
logoTitlestringNoTitle property for the logo image (requires logo image)

Clusterer options

Clusterer will put close places together in a cluster with a number showing how many places are clustered in the cluster.

OptionTypeRequiredDefaultDescription
imagePathstringNoSee below.
textSizenumberNo16Textsize of the numbers in the clusters
textColorstringNo'#000'Textcolor of the numbers in the clusters
sizesarrayNo[10, 10, 10, 10, 10]Array of pixel sizes for the different images

The imagePath is similar to the imagePath of the main options but more strict. It requires that there are five different square PNG images, each ending with a number from 1 to 5. For example, if imagePath is cluster_ball_, the clusterer will expect that there are five images; cluster_ball_1.png, cluster_ball_2.png, cluster_ball_3.png, cluster_ball_4.png and cluster_ball_5.png. This is unfortunately how the used library js-marker-clusterer works.

Examples

Bare minimum map

This is the absolute minimum configuration - it will only show the default Google Maps.

alt text

const options = {
    tag: "https://maps.googleapis.com/maps/api/js?key=<YOUR_API_KEY>",
};

new Places(options);
1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.102

5 years ago

1.0.101

5 years ago

1.0.100

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.91

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago