Giter Club home page Giter Club logo

statamic-google-maps's Introduction

Statamic Google Maps

Statamic 4.0+ Latest Version on Packagist

A Google Map addon for Statamic V4 for creating and displaying Google Maps on your website.

Installation

Require it using Composer.

composer require jezzdk/statamic-google-maps

Publish the assets

php artisan vendor:publish --provider="Jezzdk\StatamicGoogleMaps\ServiceProvider"

Add an environment variable, since this library uses Google Maps under the hood for displaying maps.

GOOGLE_MAPS_API_KEY=""

Lastly, insert this tag in the header in order to load the Google Map JavaScript on the frontend:

{{ map_script }}

*Disclaimer* You will need a billing account on Google if you want to create a Google Maps API key. There are plenty of guides on how to set that up if you ask Google.

Usage

This addon provides a Google Map fieldtype. You can use that in your blueprints which will enable your users to dynamically insert maps onto your website.

There is also a tag that you can use directly in your Antlers template. I'll explain both use cases below.

Map Tag

The simplest way to insert a map is by inserting the tag with latitude and longitude:

{{ map lat="12.1234" lng="52.1234" }}

This will insert a map centered on the given coordinates, with a zoom level of 16 and using the roadmap type. The Map tag supports the following attributes:

Attribute Type Default Description
lat float none The latitude (required)
lng float none The longitude (required)
marker bool false Display a marker in the latitude and longitude from above
markerLat float none The latitude for the marker (the marker attribute must be false or omitted)
markerLng float none The longitude for the marker (the marker attribute must be false or omitted)
zoom integer 16 The map zoom level
type string roadmap Valid values are: roadmap, satellite, terrain, hybrid
icon string /assets/marker.png (Pro feature) Use a path relative to the public folder. If the file doesn't exist, the default Google Map pin will be used.
style string none (Pro feature) The map styles as a JSON string
showControls boolean false Show the default map controls

Google Map Field (Pro feature)

Simply select the fieldtype when creating a blueprint. When a user pans around the map, changes zoom level or changes the map type, the settings are saved and the output will display the same view as selected in the control panel.

The field has a few settings:

  • Initial map type - choose which map type should be selected when the map is loaded initially in the control panel
  • Initial zoom level - choose the zoom level when the map is loaded initially in the control panel
  • Enable maptype selector - Allow the user to select the map type
  • Enable marker creation - The user can create and remove a marker on the map
  • Enable Geocoder - This adds a search field above the map, enabling the user to search for an address (The Geocoder API must be enabled in Google Cloud Console for this to work!)

When using markers, the script will look for an icon at /public/assets/marker.png. If it exist it will be used, otherwise it will use the default Google Map pin.

Styles (Pro feature)

The map can be styled using a JSON array of styles. You can generate the style JSON for free at https://mapstyle.withgoogle.com/ (use the old wizard) or at https://snazzymaps.com/.

The fieldtype has a button that reveals a textarea where the style JSON can be inserted, and the map tag has a style attribute for the same purpose.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.