Skip to content

Commit 1c02db9

Browse files
authored
Merge pull request #413 from fschrader1992/temp_map
LGTM, tried and tested on dev.
2 parents 9af4bdb + 059b91c commit 1c02db9

File tree

1 file changed

+31
-24
lines changed

1 file changed

+31
-24
lines changed

app/assets/javascripts/locations.js

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -73,41 +73,48 @@ require(["lib/models", "lib/tools", "lib/leaflet/leaflet", "lib/msg", "lib/astat
7373

7474
for(var j=0; j<geojson[i].floorplans.length; j++) {
7575

76-
$('#floorplans-wrap').append('<div id="floorplan-div-' + i + + j + '" class="floorplan-divs" style="margin-bottom: 1em;"></div>');
77-
7876
//create image in order to get actual image dimensions cross browser
79-
var img = $("<img>").attr("src", geojson[i].floorplans[j]);
80-
var nw = img.prop('naturalWidth');
81-
var nh = img.prop('naturalHeight');
82-
83-
var floor = L.map('floorplan-div-' + i + j, {
84-
crs: L.CRS.Simple,
85-
minZoom: 0
86-
});
87-
88-
if(nh>nw){
89-
$('#floorplan-div-'+i+j).height($('#floorplan-div-'+i+j).width());
90-
$('#floorplan-div-'+i+j).width(nw/nh*$('#floorplan-div-'+i+j).height());
91-
}else{
92-
$('#floorplan-div-'+i+j).height(nh/nw*$('#floorplan-div-'+i+j).width());
93-
}
94-
95-
var bounds = [[0, 0], [$('#floorplan-div-'+i+j).height(), $('#floorplan-div-'+i+j).width()]];
96-
var image = L.imageOverlay(geojson[i].floorplans[j], bounds).addTo(floor);
97-
floor.fitBounds(bounds);
77+
var img = new Image();
78+
img.src = geojson[i].floorplans[j];
79+
img.onload = handleLoad;
80+
81+
9882
//possible to incorporate rooms with coordinates just as above,
9983
//just be sure to use right coordinate system (cf. leaflet page)
10084
//and mapping probably needed for room number vs. location
10185
}
10286
}
10387
}
104-
if($('.floorplan-divs').length == 0){
105-
$('#floorplans-wrap').append('<p>No floorplans available for this conference.</p>');
106-
}
10788
}
10889
//add addresses as text
10990
//self.geoContent(texts);
11091

92+
function handleLoad(response) {
93+
94+
$('#floorplans-wrap').append('<div id="floorplan-div-' + i + + j + '" class="floorplan-divs" style="margin-bottom: 1em;"></div>');
95+
96+
// Get accurate measurements from that.
97+
var nw = img.width;
98+
var nh = img.height;
99+
100+
console.log(nw+' '+nh+' '+img.src);
101+
var floor = L.map('floorplan-div-' + i + j, {
102+
crs: L.CRS.Simple,
103+
minZoom: 0
104+
});
105+
106+
if(nh>nw){
107+
$('#floorplan-div-'+i+j).height($('#floorplan-div-'+i+j).width());
108+
$('#floorplan-div-'+i+j).width(nw/nh*$('#floorplan-div-'+i+j).height());
109+
}else{
110+
$('#floorplan-div-'+i+j).height(nh/nw*$('#floorplan-div-'+i+j).width());
111+
}
112+
113+
var bounds = [[0, 0], [$('#floorplan-div-'+i+j).height(), $('#floorplan-div-'+i+j).width()]];
114+
var image = L.imageOverlay(img.src, bounds).addTo(floor);
115+
floor.fitBounds(bounds);
116+
}
117+
111118
}
112119
}
113120

0 commit comments

Comments
 (0)