yourcelf / olwidget

Javascript library to replace textareas that contain WKT data with editable OpenLayers maps, and a django app using it for django forms and admin.
Other
91 stars 44 forks source link

mapDivStyle and map_div_style width/height only work with px not % #107

Open turukawa opened 12 years ago

turukawa commented 12 years ago

I'd like to use a default of 100% for width and height but that causes the view to fail.

OLWIDGET_DEFAULT_OPTIONS = {

"map_div_style": {"width": "100%", "height": "100%"}}

Any ideas on how to fix this?

Thanks.

turukawa commented 12 years ago

This may not be elegant, but I've solved the problem I had as follows:

<script type="text/javascript">
var div = OpenLayers.Util.getElement("map");
div.style.height = window.innerHeight + "px";
olwidget_map.updateSize();
var extent = new OpenLayers.Bounds();
for (var i = 0; i < olwidget_map.vectorLayers.length; i++) {
    var vl = olwidget_map.vectorLayers[i];
    if (vl.opts.cluster) {
        for (var j = 0; j < vl.features.length; j++) {
            for (var k = 0; k < vl.features[j].cluster.length; k++) {
                extent.extend(vl.features[j].cluster[k].geometry.getBounds());
            }
        }
    } else {
        extent.extend(vl.getDataExtent());
    }
}
if (!extent.equals(new OpenLayers.Bounds())) {
    olwidget_map.zoomToExtent(extent);
    olwidget_map.zoomTo(Math.min(olwidget_map.getZoom(), olwidget_map.opts.zoomToDataExtentMin));
}
</script>