0
Good morning!
I have a web application, where I use a leafletjs map (http://tombatossals.github.io/angular-leaflet-directive/#!/) and openstreetmap as Tile.
The map works perfectly, I can interact in any way (add markers, create layers, zoom.), however, when I access the page where the map is, it does not load correctly, as printscreen below:
It readjusts when I resize the window or open and close the console, follows image below:
Codes:
View:
<div class="col-md-12">
<div class="box_whiteframe_map">
<leaflet ng-init="vm.buscaEnderecoClientesEmpresas()" center="vm.center" defaults="vm.defaults" markers="vm.markers" width="100%" height="480px"></leaflet>
</div>
</div>
CSS/SASS:
.box_whiteframe_map {
background-color: #fff;
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, .2), 0 1px 1px 0 rgba(0, 0, 0, .14), 0 2px 1px -1px rgba(0, 0, 0, .12);
color: #000;
margin: 0;
clear: both;
}
Controller:
/* MAP */
vm.markers = new Array();
vm.buscaEnderecoClientesEmpresas = function() {
vm.items = loadSaas(Cookies.get('crm_o2_hash')); // carregar saas id
vm.items.then(function(items) { // ler array de retorno
vm.saasid = items;
var dados = {
'saasid': vm.saasid
}
relatoriosService.carregarEnderecoClientesEmpresas(dados).then(function(response) {
if (response.data != 'null') {
vm.enderecoClientesEmpresas = response.data;
angular.forEach(vm.enderecoClientesEmpresas, function(value, key) {
if (value.tipo == 'p'){
var icon = 'user';
} else {
var icon = 'cog';
}
vm.markers.push({
group: value.cidade,
lat: value.lat_lng.lat,
lng: value.lat_lng.lng,
message: value.nome,
icon: {
type: 'awesomeMarker',
icon: icon,
markerColor: 'blue'
},
label: {
options: {
noHide: true
}
}
});
});
} else {
vm.enderecoClientesEmpresas = '';
}
}, function(error) {
console.log('Erro findSemEmail: ', error);
});
});
}
angular.extend(vm, { // EXTENDE AS PROPRIEDADES DO MAPA (MARCADORES, LOCALIZAÇÃO INCIAL..)
center: { // LOCALIZAÇÃO INICIAL .
lat: -22.952419,
lng: -43.211667,
zoom: 4
},
defaults: {
tileLayer: "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
zoomControlPosition: 'topright',
tileLayerOptions: {
opacity: 0.9,
detectRetina: true,
reuseTiles: true,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a> | © <a href="http://www.openstreetmap.org/copyright">Funil PRÓ</a>',
},
scrollWheelZoom: true,
minZoom: 3,
worldCopyJump: true
}
});
/* MAP FINAL */
Some help?
Can you show us some code?
– BrTkCa
Added!!!!!
– Fred
I believe I went through a similar problem and solved using a
timeout
and calling the methodinvalidateSize()
. Example:$timeout(ctrl.map.invalidateSize());
. The variablectrl.map
is my Map object (L.Map). So, after loading Angular from Document, it will execute this method and give a resize on the map.– Douglas Garrido
Usually this problem happens when the map first loaded something or you placed the map in some element of html that is/was invisible. The solution to both problems is to give a resize on the map. In the first case you give a resize after where you are sure that the map has already been completely "configured" and in the second case you should put a resize EVERY time you display the hidden element.
– Hugo Lima