From d2c25eef4376fd4b1b31504a93070066322051f3 Mon Sep 17 00:00:00 2001 From: Ko Nagase Date: Thu, 9 Jan 2020 12:22:45 +0900 Subject: [PATCH] refs #137 fixed map flicker issue --- assets/javascripts/app.js | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/assets/javascripts/app.js b/assets/javascripts/app.js index acc53861..1ae8d552 100644 --- a/assets/javascripts/app.js +++ b/assets/javascripts/app.js @@ -423,7 +423,8 @@ var App = (function ($, publ) { publ.setView = function () { var view = new ol.View({ - center: ol.proj.fromLonLat([defaults.lon, defaults.lat]), + // Avoid flicker (map move) + //center: ol.proj.fromLonLat([defaults.lon, defaults.lat]), zoom: defaults.zoom, maxZoom: defaults.maxzoom // applies for Mierune Tiles }); @@ -469,12 +470,19 @@ var App = (function ($, publ) { }); }); } - else if (geolocation) { - geolocation.once('change:position', function (error) { - maps.forEach(function (m) { - m.getView().setCenter(geolocation.getPosition()); - }); + else { + // Set default center, once + maps.forEach(function (m) { + m.getView().setCenter(ol.proj.transform([defaults.lon, defaults.lat], + 'EPSG:4326', 'EPSG:3857')); }); + if (geolocation) { + geolocation.once('change:position', function (error) { + maps.forEach(function (m) { + m.getView().setCenter(geolocation.getPosition()); + }); + }); + } } };