$(document).ready(() => {
const mapEl = $('#our_map').get(0); // OR document.getElementById('our_map');
// Display a map on the page
const map = new google.maps.Map(mapEl, { mapTypeId: 'roadmap' });
const buildings = [
{
title: 'London Eye, London',
coordinates: [51.503454, -0.119562],
info: 'carousel'
},
{
title: 'Palace of Westminster, London',
coordinates: [51.499633, -0.124755],
info: 'palace'
}
];
placeBuildingsOnMap(buildings, map);
});
const placeBuildingsOnMap = (buildings, map) => {
// Loop through our array of buildings & place each one on the map
const bounds = new google.maps.LatLngBounds();
buildings.forEach((building) => {
const position = { lat: building.coordinates[0], lng: building.coordinates[1] }
// Stretch our bounds to the newly found marker position
bounds.extend(position);
const marker = new google.maps.Marker({
position: position,
map: map,
title: building.title
});
const infoWindow = new google.maps.InfoWindow();
// Allow each marker to have an info window
google.maps.event.addListener(marker, 'click', () => {
infoWindow.setContent(building.info);
infoWindow.open(map, marker);
})
// Automatically center the map fitting all markers on the screen
map.fitBounds(bounds);
})
})
yep MongoDB хранит порядок массива .. точно так же, как Javascript engine ..
Да, на самом деле, из быстрого поиска Google по этому вопросу, кажется, довольно сложно переупорядочить их: http://groups.google.com/group/mongodb-user/browse_thread/thread / 1df1654889e664c1
Я понимаю, что это старый вопрос, но Mongo docs теперь указывают, что все свойства документа сохраняют свой порядок, когда они вставлены . Это естественно распространяется и на массивы.
Порядок полей документа
MongoDB сохраняет порядок полей документа после операций записи, за исключением следующих случаев:
- Поле _id всегда является первым полем в документе.
- Обновления, которые включают переименование имен полей, могут привести к переупорядочению полей в документе.
Изменено в версии 2.6 : Начиная с версии 2.6, MongoDB активно пытается сохранить порядок полей в документе. До версии 2.6 MongoDB не активно сохранял порядок полей в документе.
blockquote>