0

What's wrong with my code? I want to get coordinates with mousePosition. I use openlayer v5.

var map = new ol.Map({
    target: 'map2',
    layers: [
        new ol.layer.Tile({
            source: new ol.source.OSM()
        })
    ],
    view: new ol.View({
        center: ol.proj.fromLonLat([116.041389, 3.073093]),
        zoom: 7.3
    })
});
var mousePositionControl = new ol.MousePosition({
    coordinateFormat: createStringXY(2),
    projection: 'EPSG:4326',
    className: 'custom-mouse-position',
    target: document.getElementById('mouse-position'),
    undefinedHTML: ' '
});

executing the above code will get an

"ReferenceError: createStringXY is not defined" error.

Narendra Jadhav
  • 10,052
  • 15
  • 33
  • 44
Ardhi Cho
  • 41
  • 1
  • 5
  • You need to use `ol.coordinate.createStringXY(2)` instead of this `createStringXY(2)`. – Narendra Jadhav Jan 07 '19 at 07:40
  • now error is "TypeError: ol.MousePosition is not a constructor"? – Ardhi Cho Jan 07 '19 at 08:00
  • `ol.control.MousePosition` If you are using full build OpenLayers 5 refer to the OpenLayers 4 API for syntax https://openlayers.org/en/v4.6.5/apidoc/ol.control.MousePosition.html – Mike Jan 07 '19 at 09:48

0 Answers0