eXMarty
eXMarty

Reputation: 51

Point fixed to view (eg. cross of center view)

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

Answers (2)

ahocevar
ahocevar

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

bartvde
bartvde

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

Related Questions