I developend a small application using OpenLayers 4 JavaScript library. As per my bussiness requirement I need to add a elevationprofile widjit to display elevationprofile chart for drawpath. I tried with a google maps api elevation service sample code like below.

function displayPathElevation(path, elevator, map) {
        // Display a polyline of the elevation path.
        new google.maps.Polyline({
          path: path,
          strokeColor: '#0000CC',
          strokeOpacity: 0.4,
          map: map

But in the above code for 'map' parameter I passed my openlayer map which is below,

var map = new ol.Map({
        controls: ol.control.defaults().extend([
          new ol.control.OverviewMap()
        layers: layers,
        target: 'map',
        view: new ol.View({
            center: [8258001.79515761, 2282774.58088226],
            zoom: 11

then getting the following error

InvalidValueError: setMap: not an instance of Map.

How do I use an OpenLayers map in Google maps elevation service or ArcGIS Elevation service?


You can have a look at http://viglino.github.io/ol-ext/examples/control/map.control.profil.html The ol.control.Profil add a control to an ol.Map that will handle the elevation profile. @+

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.