Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var view = new ol.View({
- center: [0, 0],
- zoom: 4
- });
- var map = new ol.Map({
- layers: [
- new ol.layer.Tile({
- source: new ol.source.OSM()
- })
- ],
- target: 'map',
- controls: ol.control.defaults({
- attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
- collapsible: false
- })
- }),
- view: view
- });
- var geolocation = new ol.Geolocation({
- projection: map.getView().getProjection(),
- tracking: true,
- trackingOptions: {
- enableHighAccuracy: true,
- maximumAge: 2000
- }
- });
- var iconStyle = new ol.style.Style({
- image: new ol.style.Circle({
- radius: 9,
- fill: new ol.style.Fill({
- color: '#9779CC'
- }),
- stroke: new ol.style.Stroke({
- color: '#fAf',
- width: 2
- })
- })
- });
- // add an empty iconFeature to the source of the layer
- var iconFeature = new ol.Feature();
- var iconSource = new ol.source.Vector({
- features: [iconFeature]
- });
- var iconLayer = new ol.layer.Vector({
- source: iconSource,
- style : iconStyle
- });
- map.addLayer(iconLayer);
- geolocation.on('change', function() {
- var pos = geolocation.getPosition();
- var pos2="-5.73487946125,37.33522475130639";
- iconFeature.setGeometry(new ol.geom.Point(pos));
- view.setCenter(pos);
- //view.setZoom(18);
- // iconFeature.setGeometry(new ol.geom.Point(pos2));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement