Skip to content

Commit ad74a09

Browse files
committed
Fixes missing zoomTo event for multiple maps per page
1 parent f271231 commit ad74a09

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

assets/javascripts/app.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
var App = (function ($, publ) {
88

99
var map, vector, bounds, contents, toolbar, geolocation = null;
10+
var maps = [];
1011
var features = [];
1112
var layerArr = [];
1213
var filters = {
@@ -210,6 +211,9 @@ var App = (function ($, publ) {
210211
publ.zoomToExtent();
211212
map.on('moveend', publ.updateFilter);
212213
});
214+
215+
// Handle multiple maps per page
216+
maps.push(map);
213217
};
214218

215219
/**
@@ -344,12 +348,14 @@ var App = (function ($, publ) {
344348
if (!force && (filters.distance || filters.location)) {
345349
// Do not zoom to extent but show the previous extent stored as cookie
346350
var parts = (getCookie("_redmine_gtt_permalink")).split("/");
347-
map.getView().setZoom(parseInt(parts[0], 10));
348-
map.getView().setCenter(ol.proj.transform([
349-
parseFloat(parts[1]),
350-
parseFloat(parts[2])
351-
],'EPSG:4326','EPSG:3857'));
352-
map.getView().setRotation(parseFloat(parts[3]));
351+
maps.forEach(function (m) {
352+
m.getView().setZoom(parseInt(parts[0], 10));
353+
m.getView().setCenter(ol.proj.transform([
354+
parseFloat(parts[1]),
355+
parseFloat(parts[2])
356+
],'EPSG:4326','EPSG:3857'));
357+
m.getView().setRotation(parseFloat(parts[3]));
358+
})
353359
}
354360
else if (vector.getSource().getFeatures().length > 0) {
355361
var extent = ol.extent.createEmpty();
@@ -358,14 +364,20 @@ var App = (function ($, publ) {
358364
vector.getSource().getFeatures().forEach(function (feature) {
359365
ol.extent.extend(extent, feature.getGeometry().getExtent());
360366
});
361-
map.getView().fit(extent, map.getSize());
367+
maps.forEach(function (m) {
368+
m.getView().fit(extent, m.getSize());
369+
});
362370
}
363371
else if (bounds.getSource().getFeatures().length > 0) {
364-
map.getView().fit(bounds.getSource().getExtent(), map.getSize());
372+
maps.forEach(function (m) {
373+
m.getView().fit(bounds.getSource().getExtent(), m.getSize());
374+
});
365375
}
366376
else if (geolocation) {
367377
geolocation.once('change:position', function (error) {
368-
map.getView().setCenter(geolocation.getPosition());
378+
maps.forEach(function (m) {
379+
m.getView().setCenter(geolocation.getPosition());
380+
});
369381
});
370382
}
371383
};

0 commit comments

Comments
 (0)