Funn_Bobby
Funn_Bobby

Reputation: 715

OpenLayers 3 draw path with coordinates

I'm trying to use the Geolocation service of Openlayers 3 to map the users movement and collect coordinates based on distance and then either provide a measurement or a polygon shape that will be displayed on the map.

I've done quite a bit of research and haven't found anything that would even really get me started toward my end goal. Is this possible with OpenLayers 3? Is there something already built in that I can use or would i have to build this from scratch using OpenLayers 3 components.

The code I currently have just turns OpenLayers location services on through the browser and tracks the location.

   new ol.Geolocation({
                projection: mapObj.getView().getProjection(),
                tracking: true,
                trackingOptions: {
                    enableHighAccuracy: true
                }
            })
                .on('change', function () {
                    geoLocationPosition = this.getPosition();
                    geoLocationHeading = this.getHeading() || 0;


             mapObj.getView().setCenter(geoLocationPosition);
                    var trackerStyle = new ol.style.Style({
                        stroke: new ol.style.Stroke({
                            color: '#383838',
                            width: 1
                        }),
                        fill: new ol.style.Fill({
                            color: '#319FD3'
                        })
                    });
                    geoLocationCircle.setStyle(trackerStyle);
                    geoLocationCircle.setGeometry(
                        new ol.geom.Circle(geoLocationPosition, 5)
                    );


                })



            };

Any help in guiding me in the right direction is appreciated!!

Upvotes: 0

Views: 1137

Answers (1)

Viglino Jean-Marc
Viglino Jean-Marc

Reputation: 1421

You can have a look at the ol-ext interaction GeolocationDraw that combines a geolocation with a draw interaction to track the location. https://viglino.github.io/ol-ext/examples/mobile/map.interaction.geolocationdraw.html

Here is the doc: http://viglino.github.io/ol-ext/doc/doc-pages/ol.interaction.GeolocationDraw.html

Upvotes: 1

Related Questions