Skip to content

Commit

Permalink
Perform createLegend at the same time as areas
Browse files Browse the repository at this point in the history
Perform createLegend at the same time as areas
  • Loading branch information
neveldo committed Nov 14, 2017
1 parent a10d957 commit a74e84d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
10 changes: 6 additions & 4 deletions examples/advanced/legend_show_hide.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@
attrs: {
fill: "#2579b5"
},
label: "Between 10 millions and 50 millions inhabitants"
label: "Between 10 millions and 50 millions inhabitants",
clicked: true
},
{
min: 50000000,
Expand All @@ -101,8 +102,8 @@
]
},
plot: {
title: "Cities population"
, slices: [
title: "Cities population",
slices: [
{
max: 500000,
attrs: {
Expand Down Expand Up @@ -138,7 +139,8 @@
"stroke-width": 1
},
label: "More than 1 million inhabitants",
size: 30
size: 30,
clicked: true
}
]
}
Expand Down
7 changes: 4 additions & 3 deletions examples/basic/legend_SVG_paths.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
.mapael .zoomOut {
top: 50px;
}

</style>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" charset="utf-8"></script>
Expand Down Expand Up @@ -124,7 +124,8 @@
height: 30,
attrs: {
fill: "#8AD12C"
}
},
clicked: true
}, {
label: "Value 2",
sliceValue: "Value 2",
Expand Down Expand Up @@ -221,4 +222,4 @@ <h1>Map with SVG paths defined through the legend to plot some cities</h1>


</body>
</html>
</html>
9 changes: 5 additions & 4 deletions js/jquery.mapael.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,6 @@
if (self.options.map.width) {
// NOT responsive: map has a fixed width
self.paper.setSize(self.options.map.width, self.mapConf.height * (self.options.map.width / self.mapConf.width));

// Create the legends for plots taking into account the scale of the map
self.createLegends("plot", self.plots, (self.options.map.width / self.mapConf.width));
} else {
// Responsive: handle resizing of the map
self.initResponsiveSize();
Expand Down Expand Up @@ -249,6 +246,9 @@
// Create the legends for areas
self.createLegends("area", self.areas, 1);

// Create the legends for plots taking into account the scale of the map
self.createLegends("plot", self.plots, self.paper.width / self.mapConf.width);

// Attach update event
self.$container.on("update." + pluginName, function (e, opt) {
self.onUpdateEvent(e, opt);
Expand Down Expand Up @@ -341,7 +341,8 @@
self.paper.setSize(containerWidth, self.mapConf.height * newScale);

// Create plots legend again to take into account the new scale
if (isInit || self.options.legend.redrawOnResize) {
// Do not do this on init (it will be done later)
if (isInit !== true && self.options.legend.redrawOnResize) {
self.createLegends("plot", self.plots, newScale);
}
}
Expand Down

0 comments on commit a74e84d

Please sign in to comment.