YOUR_API_KEY
: <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
YOUR_API_KEY&callback=initMap
with the name of your function after the key. We connect the script on the page and create a block for the future map in the markup: <div id="map"></div>
function initMap() { var coordinates = {lat: 47.212325, lng: 38.933663}, map = new google.maps.Map(document.getElementById('map'), { center: coordinates }); }
zoom: number
- determines the initial scale.disableDefaultUI: boolean
- removes controls.scrollwheel: boolean
- disables scaling with the mouse wheel (it is useful if the map is full-page wide and stops scrolling down). function initMap() { var coordinates = {lat: 47.212325, lng: 38.933663}, map = new google.maps.Map(document.getElementById('map'), { center: coordinates }), marker = new google.maps.Marker({ position: coordinates, map: map }); }
position
(required) indicates the starting position of the marker. If you specify the same coordinates as for the map, the marker will be in the center of the screen. You can shift the marker by changing the value of the coordinates, or by changing the position of the map itself relative to the visible area (parent unit).map
(optional) indicates the map on which the marker is placed.DROP
- after loading the map marker falls from the top.BOUNCE
- the marker bounces on the spot. function initMap() { var coordinates = {lat: 47.212325, lng: 38.933663}, map = new google.maps.Map(document.getElementById('map'), { center: coordinates }), marker = new google.maps.Marker({ position: coordinates, map: map, animation: google.maps.Animation.BOUNCE }); }
setAnimation()
method. google.maps.event.addListener(infowindow,'closeclick',function(){ marker.setAnimation(google.maps.Animation.BOUNCE); }); marker.addListener('click', function () { marker.setAnimation(null); });
icon
property. image = 'images/marker.png', marker = new google.maps.Marker({ position: coordinates, map: map, icon: image });
content
property: function initMap() { var coordinates = {lat: 47.212325, lng: 38.933663}, popupContent = '<p class="content"> </p>', markerImage = 'images/marker.png', map = new google.maps.Map(document.getElementById('map'), { center: {lat: 47.212325, lng: 38.933663} }), marker = new google.maps.Marker({ position: coordinates, map: map, icon: markerImage }), infowindow = new google.maps.InfoWindow({ content: popupContent }); }
open()
method: infowindow.open(map, marker);
marker.addListener('click', function() { infowindow.open(map, marker); });
.gm-style-iw { background: $black; box-shadow: -14px 0px 0px $black, -14px 9px 0px $black, -14px -8px 0px $black, 15px -8px 0px $black, 15px 9px 0px $black; }
.gm-style-iw
- the main unit, it contains content. In the screenshot above, this block has a black background..poi-info-window
- a wrapper for text in a standard information window, is inside. .gm-style-iw.gm-style-iw + div
- cross. .gm-style-iw { overflow: visible !important; div { overflow: visible !important; } }
.gm-style-iw
, or blocks inside you can create pseudo-elements to overlap the background and the arrow: .gm-style-iw { // &::before { content: ''; width: calc(100% + 29px); height: calc(100% + 17px); @include absolute; @include center-align; background: $black; } // &::after { content: ''; width: 0; height: 0; border: 22px solid transparent; border-top-color: $black; z-index: 4; @include absolute; top: auto; bottom: -53px; margin: auto; } }
.clone(true)
into the content of the information window with transfer of handlers will not be allowed by the API. var $parallaxImg = null; this.$body.mousemove(function(e) { if($parallaxImg) { ... } else if($(this.parallaxImg).length) { $parallaxImg = $(this.parallaxImg); } }.bind(this));
var $parallaxImg = null; this.$body.mousemove(function(e) { if($parallaxImg) { var $el = $(e.currentTarget), xPos = e.pageX - (window.innerWidth / 2), mXPcnt = Math.round(xPos / $el.width() * 100), diffX = $parallaxImg.width() - $el.width(), myX = diffX * (mXPcnt / 1500); $parallaxImg.animate({left: myX}, 0); } else if($(this.parallaxImg).length) { $parallaxImg = $(this.parallaxImg); } }.bind(this));
$('.map').on('click', '.js-parallax-img', function() { ... });
var styles = [ { "featureType": "water", "stylers": [ { "color": "#a73cff" } ] } ]
map.setOptions({styles: styles});
$.getJSON("../json/map-style/map-style.json", function(data) { map.setOptions({styles: data}); });
var coordinates = {lat: 47.212325, lng: 38.933663}, popupContent = this.$popupContent.html(), markerImage = 'images/marker.png', zoom = 15, map = new google.maps.Map(document.getElementById('map'), { center: coordinates, zoom: zoom, disableDefaultUI: true }), infowindow = new google.maps.InfoWindow({ content: popupContent }), marker = new google.maps.Marker({ position: coordinates, map: map, icon: markerImage }); $.getJSON("../json/map-style/map-style_colored.json", function(data) { map.setOptions({styles: data}); }); google.maps.event.addListener(infowindow,'closeclick',function(){ marker.setAnimation(google.maps.Animation.BOUNCE); }); marker.addListener('click', function () { marker.setAnimation(null); }); marker.addListener('click', function() { infowindow.open(map, marker); }); infowindow.open(map, marker);
.gm-style-mtc
.gmnoprint
.gm-svpc
.gm-style-mtc > div, .gmnoprint > div, .gm-svpc { background-color: #f63981 !important; }
mask-image
property, but it is not supported by all browsers.pointer-events
, which on the mask should be in the value of none
. This will not take this block into account in mouse events (in other words, click and scroll through this block).Source: https://habr.com/ru/post/324880/
All Articles