Skip to content

Commit

Permalink
adding geolocation
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcnc committed Mar 11, 2017
1 parent 0232941 commit ac5c7fc
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,35 @@ <h2>Date:</h2>
visible: false,
});

var geolocation = new ol.Geolocation({
projection: ol.proj.get('EPSG:3857'),
tracking: true
});
var userLocation = new ol.Feature();
userLocation.setStyle(new ol.style.Style({
image: new ol.style.Circle({
radius: 6,
fill: new ol.style.Fill({
color: '#3399CC'
}),
stroke: new ol.style.Stroke({
color: '#fff',
width: 2
})
})
}));
geolocation.on('change:position', function() {
var coordinates = geolocation.getPosition();
userLocation.setGeometry(coordinates ? new ol.geom.Point(coordinates) : null);
map.getView().setCenter(coordinates);
map.getView().setZoom(18);
});
var userLocationLayer = new ol.layer.Vector({
source: new ol.source.Vector({
features: [userLocation]
})
});

var map = new ol.Map({
layers: [
new ol.layer.Tile({
Expand All @@ -299,7 +328,8 @@ <h2>Date:</h2>
})
}),
neighborhoodsLayer,
councilDistrictsLayer
councilDistrictsLayer,
userLocationLayer
],
target: 'map',
view: new ol.View({
Expand Down

0 comments on commit ac5c7fc

Please sign in to comment.