Advertisement
Guest User

Untitled

a guest
Jul 18th, 2017
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     var view = new ol.View({
  2.         center: [0, 0],
  3.         zoom: 4
  4.       });
  5.  
  6.       var map = new ol.Map({
  7.         layers: [
  8.           new ol.layer.Tile({
  9.             source: new ol.source.OSM()
  10.           })
  11.         ],
  12.         target: 'map',
  13.         controls: ol.control.defaults({
  14.               attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
  15.                 collapsible: false
  16.               })
  17.         }),
  18.         view: view
  19.       });
  20.  
  21.    
  22.    
  23.       var geolocation = new ol.Geolocation({
  24.     projection: map.getView().getProjection(),
  25.     tracking: true,
  26.     trackingOptions: {
  27.       enableHighAccuracy: true,
  28.       maximumAge: 2000  
  29.     }
  30.   });
  31.  
  32.  
  33.   var iconStyle = new ol.style.Style({
  34.   image: new ol.style.Circle({
  35.           radius: 9,
  36.           fill: new ol.style.Fill({
  37.             color: '#9779CC'
  38.           }),
  39.           stroke: new ol.style.Stroke({
  40.             color: '#fAf',
  41.             width: 2
  42.           })
  43.         })
  44.       });
  45.  
  46. // add an empty iconFeature to the source of the layer
  47.   var iconFeature = new ol.Feature();  
  48.   var iconSource = new ol.source.Vector({
  49.     features: [iconFeature]
  50.   });    
  51.   var iconLayer = new ol.layer.Vector({
  52.     source: iconSource,
  53.     style : iconStyle
  54.   });    
  55.   map.addLayer(iconLayer);
  56.  
  57.  geolocation.on('change', function() {
  58.     var pos = geolocation.getPosition();
  59.     var pos2="-5.73487946125,37.33522475130639";      
  60.  
  61.     iconFeature.setGeometry(new ol.geom.Point(pos));
  62.     view.setCenter(pos);
  63.     //view.setZoom(18);
  64.    
  65.     // iconFeature.setGeometry(new ol.geom.Point(pos2));
  66.   });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement