N8BIZ
N8BIZ

Reputation: 151

Openlayers ol is not defined

Here is what I'm importing:

import React, { useState, useEffect, useRef } from 'react';
import 'ol/ol.css';
import ExtentInteraction from 'ol/interaction/Extent';
import { Map, View } from 'ol';
import { OSM } from 'ol/source';
import { Tile as TileLayer } from 'ol/layer';
import { shiftKeyOnly } from 'ol/events/condition';
import { Stroke, Style } from 'ol/style';
import { Control, defaults as defaultControls } from 'ol/control';

Here is my usage of ol that is being flagged:

    const controls = map.getControls();
    controls.forEach((control) => {
        console.log(control instanceof ol.control.Zoom);
    });

The error is that ol is undefined. Is this an issue with my import or is there another reference that needs to be used?

Upvotes: 1

Views: 1060

Answers (1)

pzaenger
pzaenger

Reputation: 11973

Import Zoom also from ol/control:

import { Control, Zoom, defaults as defaultControls } from 'ol/control';

...

controls.forEach((control) => {
  console.log(control instanceof Zoom);
});

Upvotes: 1

Related Questions