Reputation: 51
What is the optimal way to position the fixed point of view (not to the point on the map). Using for showing middle of the view, while watching GPS positioning and moving center of the map according to current coordinates.
Upvotes: 4
Views: 1653
Reputation: 5647
You can do this with pure html and css. Inside your map div, place another div:
<div id="map" class="map">
<div id="center"></div>
</div>
Then add some css to position it in the center of the map viewport:
#center {
top: 50%;
left: 50%;
width: 20px;
height: 20px;
margin-top: -20px;
margin-left: -20px;
padding-top: 10px;
padding-left: 10px;
border: 2px solid red;
z-index: 10000;
position: relative;
}
I created a JSFiddle so you can play with it: http://jsfiddle.net/wce6zqor/.
Upvotes: 3
Reputation: 2126
Use an overlay with positioning center-center
var pos = map.getView().getCenter();
pin = new ol.Overlay({
position: pos,
element: 'test',
positioning: 'center-center'
});
map.addOverlay(pin);
Upvotes: 0