Loop - Map Search
by NPetrovich
Short Description
Loop - locations search, based on Google Maps service. Allows to use search through marked locations, select them from the map or from locations lists and more. Also you can group locations and select locations by groups. It has a simple locations submission and good commented code, that allows you to easily use or modify functionality and styles.
Installation
Upload script files, via FTP client to any place in your project. To know more about using FTP and uploading files fallow this link use FTP Instructions
To connect script to your project you need to connect styles and scripts before google map script. Example:
1 2 3 4
<link rel="stylesheet" href="assets/styles/style.css">
<script defer src="assets/scripts/script.js"></script>
<script defer src="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js"></script>
<script defer src="https://maps.googleapis.com/maps/api/js?key=here_your_key&callback=initMap&language=en"></script>
Notice: do not change order of scripts.
Notice: do not forget to delete or edit map callback function if you had one before.
After you connected files, you need to add your Google API key to 'key' value in google script link. To know more about this key fallow this link use Get API Key
And at the end add div with id 'map' to place where you want map to appear. Example:
Now you may find you need to change some styles, you can do it in uploaded CSS file. To change settings or add markers follow this instruction.
Map Configuration
You can apply any Google Maps setting to this script. To know more about fallow this link use Google Maps Platform Documentation But most common setting you can configure via data attribute of the map div. This is the example of applying settings:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<div id="map"
data-zoom="5"
data-center-lat="-25.363"
data-center-lng="136.044"
data-markers="assets/scripts/markers.json"
data-clustering="false"
data-cluster="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m"
data-control-search="true"
data-control-list="true"
data-control-groups="true"
data-layer-traffic="false"
data-layer-transit="false"
data-layer-bicycling="false"
></div>
Center & Zoom
Probably first you would like to setup it`s a map`s first view. To do it you need to choose zoom scale and find GPS coordinates of the center. Read more at Zoom Levels and Find Place for Coordinates. After that add this data to map div. For example:
1 2 3 4 5
<div id="map"
data-zoom="5"
data-center-lat="-25.363"
data-center-lng="136.044"
></div>
Locations
Maps download markers data from JSON file with structured data. You can put name, coordinates and HTML template of Info Window. You can edit default .json or create your own with the same structure. JSON example:
1 2 3 4 5 6 7 8 9 10 11
json_markers_upload({
"markers":[
{
"title":"Banana",
"info":"This is InfoWindow content Banana",
"location":{
"lat":-25.363,
"lng":131.044
}
}
]
});
Notice: do not change structure and hook name of the JSON data.
Also, you can setup your own source of data putting link in 'data-markers' attribute, example:
1 2 3 4 5
<div id="map"
data-zoom="5"
data-center-lat="-25.363"
data-center-lng="136.044"
data-markers="assets/scripts/markers.json"
></div>
Icons
You can add custom icon to your marker by signing url to image file in JSON, example:
1 2 3 4 5 6 7 8 9 10 11 12
json_markers_upload({
"markers":[
{
"title":"Banana",
"icon":"assets/images/koala.svg",
"info":"This is InfoWindow content Banana",
"location":{
"lat":-25.363,
"lng":131.044
}
}
]
});
Language
You can choose language of your map by changing 'language' variable in GET parameter of the maps.googleapis.com request script, example:
1
<script defer src="https://maps.googleapis.com/maps/api/js?key=here_your_key&callback=initMap&language=ja"></script>
You also can read more about this here Maps Localization.
Clustering
You can make markers combine to a groups if you enable clustering. To do it you need to setup two attributes - switcher and link to image of the cluster, example:
1 2 3 4 5
<div id="map"
data-zoom="5"
data-center-lat="-25.363"
data-center-lng="136.044"
data-clustering="true"
data-cluster="https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m"
></div>
Notice: you can disconnect 'markerclusterer.js' from the header if you will never turn on this function.
Search
You can enable custom search control by switching it`s attribute to true, example:
1 2 3 4 5
<div id="map"
data-zoom="5"
data-center-lat="-25.363"
data-center-lng="136.044"
data-control-search="true"
></div>
List
You can enable custom list control by switching it`s attribute to true, example:
1 2 3 4 5
<div id="map"
data-zoom="5"
data-center-lat="-25.363"
data-center-lng="136.044"
data-control-list="true"
></div>
Groups
You can enable custom list control by switching it`s attribute to true, example:
1 2 3 4 5
<div id="map"
data-zoom="5"
data-center-lat="-25.363"
data-center-lng="136.044"
data-control-groups="true"
></div>
To group markers you need to add additional value to markers JSON, example:
1 2 3 4 5 6 7 8 9 10 11 12
json_markers_upload({
"markers":[
{
"title":"Banana",
"group":"Fruits",
"info":"This is InfoWindow content Banana",
"location":{
"lat":-25.363,
"lng":131.044
}
}
]
});
Layers
You can enable traffic, transit and bicycling map layers on your map by adding attributes to map div, example:
1 2 3 4 5 6 7
<div id="map"
data-zoom="5"
data-center-lat="-25.363"
data-center-lng="136.044"
data-layer-traffic="true"
data-layer-transit="true"
data-layer-bicycling="true"
></div>
File Structure
File |
Type |
Description |
assets |
Folder |
Folder with all assets of the template |
=> images |
Folder |
Folder with all images |
=> => favicon.ico |
Icon |
Icon for template |
=> => koala.svg |
Vector |
Custom marker |
=> scripts |
Folder |
Folder with all scripts |
=> => markers.json |
Javascript |
Markers data base file of the template |
=> => script.js |
Javascript |
Main logic javascript file of the template |
=> styles |
Folder |
Folder with all styles |
=> => style.css |
Stylesheet |
Main style css file of the template |
index.html |
HTML |
Main file of the template |
Get a Free Gift
You can get a free gift if you will contact me and share your experience of using this item. Your story may help to improve item quality, and you will get this improvements for free with the next update. Dependently from use of your experience I will define "size" of the gift. I can send you any item from my library for free, give you free freelance hours or more. You can contact me via
Envato profile page or use contacts from this documentation, it is located in the blue sidebar under the navigation. Thank you for purchase and may the Force be with you!