Last active
October 25, 2017 13:09
-
-
Save Altenrion/a0fada2d3a9ac91435c16f38d71c4cd6 to your computer and use it in GitHub Desktop.
tests for google map
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map, | |
EasingAnimator = function(opt){ | |
opt = opt || {}; | |
this.easingInterval = opt.easingInterval; | |
this.duration = opt.duration || 1000; | |
this.step = opt.step || 50; | |
this.easingFn = opt.easingFn || function easeInOutElastic(t, b, c, d) { | |
if ((t/=d/2) < 1) return c/2*t*t*t*t + b; | |
return -c/2 * ((t-=2)*t*t*t - 2) + b; | |
}; | |
this.callBack = opt.callBack || function(){}; | |
}, | |
data_options = { | |
generate_controls : false, | |
locations : [ | |
{ | |
lat : 56.13863363, | |
lon : 37.49602139, | |
animation : google.maps.Animation.DROP, | |
html : "Питомник Графство Багиры", | |
icon : "img/paw_main.png", | |
}, | |
{ | |
lat : 58.493333, | |
lon : 31.241667, | |
animation : google.maps.Animation.DROP, | |
html : "Новгород", | |
},{ | |
lat : 55.755826, | |
lon : 37.6173, | |
animation : google.maps.Animation.DROP, | |
html : "Москва", | |
lat : 51.533333, | |
lon : 46.016667, | |
animation : google.maps.Animation.DROP, | |
html : "Саратов", | |
},{ | |
lat : 45.05, | |
lon : 41.983333, | |
animation : google.maps.Animation.DROP, | |
html : "Ставрополь", | |
},{ | |
lat : 50.4501, | |
lon : 30.5234, | |
animation : google.maps.Animation.DROP, | |
html : "Киев", | |
},{ | |
lat : 43.133333, | |
lon : 131.9, | |
animation : google.maps.Animation.DROP, | |
html : "Владивосток", | |
},{ | |
lat : 56.8389261, | |
lon : 60.6057025, | |
animation : google.maps.Animation.DROP, | |
html : "Екатиринбург", | |
lat : 59.9342802, | |
lon : 30.3350986, | |
animation : google.maps.Animation.DROP, | |
html : "Санкт-Петербург", | |
},{ | |
lat : 45.033333, | |
lon : 38.966667, | |
animation : google.maps.Animation.DROP, | |
html : "Краснодар", | |
},{ | |
lat : 52.3702157, | |
lon : 4.8951679, | |
animation : google.maps.Animation.DROP, | |
html : "Амстердам", | |
},{ | |
lat : 40.2731911, | |
lon : -76.8867008, | |
animation : google.maps.Animation.DROP, | |
html : "Гаррисберг", | |
lat : 56.9496487, | |
lon : 24.1051864, | |
animation : google.maps.Animation.DROP, | |
html : "Рига", | |
},{ | |
lat : 60.1733244, | |
lon : 24.9410248, | |
animation : google.maps.Animation.DROP, | |
html : "Хельсинки", | |
}, | |
{ | |
lat : 56.2965039, | |
lon : 43.9360589, | |
animation : google.maps.Animation.DROP, | |
html : "Нижний Новгород", | |
},{ | |
lat : 44.716667, | |
lon : 37.75, | |
animation : google.maps.Animation.DROP, | |
html : "Новороссийск", | |
},{ | |
lat : 68.9585244, | |
lon : 33.0826598, | |
animation : google.maps.Animation.DROP, | |
html : "Мурманск", | |
},{ | |
lat : 55.790278, | |
lon : 49.134722, | |
animation : google.maps.Animation.DROP, | |
html : "Казань", | |
},{ | |
lat : 55.1644419, | |
lon : 61.4368431, | |
animation : google.maps.Animation.DROP, | |
html : "Челябинск", | |
},{ | |
lat : 48.5027313, | |
lon : 135.0662599, | |
animation : google.maps.Animation.DROP, | |
html : "Хабаровск", | |
},{ | |
lat : 46.886967, | |
lon : 142.71745, | |
animation : google.maps.Animation.DROP, | |
html : "Ю-Сахалинск", | |
},{ | |
lat : 43.585278, | |
lon : 39.720278, | |
animation : google.maps.Animation.DROP, | |
html : "Сочи", | |
},{ | |
lat : 57.6260744, | |
lon : 39.8844708, | |
animation : google.maps.Animation.DROP, | |
html : "Ярославль", | |
},{ | |
lat : 54.7903112, | |
lon : 32.0503663, | |
animation : google.maps.Animation.DROP, | |
html : "Смоленск", | |
}, | |
], | |
map_options : { | |
center: { lat: 55.763585, lng: 37.560883 }, | |
mapTypeId: google.maps.MapTypeId.ROADMAP, | |
scrollwheel : false, | |
mapTypeControl : false, | |
streetViewControl : false, | |
zoomControlOptions : { | |
style : google.maps.ZoomControlStyle.SMALL, | |
}, | |
zoom : 6, | |
disableDefaultUI: true, | |
} | |
}; | |
EasingAnimator.makeFromCallback = function(callBack){ | |
return new EasingAnimator({ | |
callBack: callBack | |
}); | |
}; | |
EasingAnimator.prototype.easeProp = function(obj, propDict){ | |
propDict = propDict || {}; | |
var self = this, | |
t = 0, | |
out_vals = JSON.parse(JSON.stringify(obj)); | |
clearInterval(self.easingInterval); | |
self.easingInterval = setInterval(function(){ | |
t+= self.step; | |
if (t >= self.duration) { | |
clearInterval(self.easingInterval); | |
self.callBack(propDict); | |
return; | |
} | |
var percent = self.easingFn(t, 0, 1, self.duration); | |
Object.keys(propDict).forEach(function(key, i) { | |
var old_val = obj[key]; | |
out_vals[key] = old_val - percent*(old_val - propDict[key]); | |
}); | |
self.callBack(out_vals); | |
}, self.step); | |
}; | |
function initialize() { | |
var gmap_options = data_options; | |
var points = [], | |
sel_point = 0; | |
for (var marker in gmap_options.locations) { | |
var obj = gmap_options.locations[marker]; | |
points.push({lat: obj.lat , lng: obj.lon }) | |
} | |
map = new google.maps.Map(document.getElementById('map'), gmap_options.map_options); | |
var easingAnimator = EasingAnimator.makeFromCallback(function(latLng){ | |
map.setCenter(latLng) | |
}) | |
easingAnimator.duration = 3000; | |
var newMarkers = new Array; | |
newMarkers[0] = new google.maps.Marker({ | |
position: new google.maps.LatLng(55.763525,37.560893), map: this.map, title: '' | |
}); | |
for (var marker in gmap_options.locations) { | |
var obj = gmap_options.locations[marker]; | |
newMarkers.push(new google.maps.Marker({ | |
position: new google.maps.LatLng(obj.lat ,obj.lon ), | |
map: this.map, | |
title: obj.html | |
})); | |
} | |
map.markers = newMarkers; | |
Array.prototype.slice.apply(document.querySelectorAll('.map_keep__button')) | |
.map(function(dom_elem, i) { | |
dom_elem.addEventListener('click', function(event){ | |
var point = map.getCenter(); | |
easingAnimator.easeProp({ | |
lat: point.lat(), | |
lng: point.lng() | |
}, points[i]); | |
}); | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment