css-position


Relative positioning of custom controls with OpenLayers 3


A map that I am building with OpenLayers 3 has some buttons, which may or may not be available depending on some other things. So I want to keep the unavailable buttons hidden, and others will use their space. The available options can change, so sometimes a button may become (in)visible.
There are some tutorials for creating custom controls with OpenLayers 3. The problem is that all samples I have seen use absolute positioning for the controls. One needs to know how many controls will be visible, and hard-code the coordinates in CSS. Or change the coordinates using Javascript. I.e., from the above link:
.rotate-north {
top: 65px;
left: .5em;
}
I have tried just setting the element with position:relative, but then they appear below the map, as the controls are added to the page after the map. So, one could use relative positioning with negative coordinates, but then if the map changes size you have to rewrite the coordinates in Javascript.
.ol-control.left-top {
position: relative;
top: -400px; /*map height*/
}
Is there a way to elegantly implement relative-positioned custom controls with OpenLayers 3, ideally with only CSS?
I guess I am trying to get a similar functionality as in the Google Maps API:
map.controls[google.maps.ControlPosition.LEFT_TOP].push(controlDiv);
Though it is not a good solution for my use case, since it is not supported by Android 4.3 and earlier, one could use CSS calc as suggested by #Jonatas:
html:
<div class="parent">
<div class="map"></div>
<div class="control"><button>CONTROL</button></div>
</div>
css:
.map {
width: 100%;
height: calc(100vh - 2em);
background-color: green;
}
.control {
position: relative;
left: .5em;
top: calc(-100vh + 2em + .5em);
}
This would probably have to use viewport units (also not supported by Android 4.3 and earlier), as calc can only calculate values based on the parent element.
jsfiddle: https://jsfiddle.net/adlerhn/zjt53nmf/

Related Links

I'm trying to put a fixed divsion at the top of the page but when I scroll with FF, lines are lost
fixed position z-index not working
how to create adjustable gap between elements (div)
How to properly apply a css hack for IE11 transition misbehaviour
How do you make leaflet popup window full screen on small screens?
Fix a div to the bottom while scrolling with skrollr
Sticky Footer at bottom of PAGE, not just bottom of WINDOW
How to set div absolute position from the parent div
Polymer paper-fab with position:fixed behaves strangely when used with core-list that has a scrollTarget
What is the use of “static” positioning in CSS?
CSS: fixed position
Style sheet positioning won't keep everything in place
Div on top 100%
CSS float image align
google sites html box tool css postion absolute
Manual Positioning of Shareaholic ShareBar Plugin

Categories

HOME
google-app-engine
eclipse
turing-machines
deep-learning
developer-tools
c++11
flex
can
database-normalization
azure-container-service
jtextpane
trac
title
openpyxl
mel
shared-libraries
google-picker
xmonad
cfml
spring-async
named-entity-recognition
visual-studio-extensions
joptionpane
exploit
pic32
interbase
nstimer
handler
wcag
rpgle
vex
winpe
gitlab-api
mockjax
sql-server-2000
wacom
joomla2.5
installscript
python-import
lubridate
video-capture
protege4
reactivekit
p4merge
apollostack
http-request
drupal-theming
ovf
lampp
builder
x-ray
pdf-conversion
lsyncd
mouseleave
gpg-signature
objectscript
sandcastle
grails-plugin
ziparchive
adafruit
mongodb-php
drawstring
android-wake-lock
cfchart
upx
aspen
kendo-upload
libvlc
boomerang
video-player
rubaxa-sortable
binomial-theorem
cgi-bin
vacuum
pyobjc
zxspectrum
dot.js
cryptographichashfunction
mass-assignment
primitive-types
rickshaw
entry-point
cbind
lambda-architecture
parallel-testing
hibernate-entitymanager
gd-graph
oocss
workitem
intersect
xcode3.2
faye
usertype
predicatebuilder
hibernateexception
android-holo-everywhere
http-daemon
photolibrary
diagrams
undefined-index
lxr
xpsdocument
technical-debt
movieplayer
idatareader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App