I have following HTML page:

<!doctype html>
<html lang="en">
    <link rel="stylesheet" href="http://openlayers.org/en/v3.3.0/css/ol.css" type="text/css">
      .map {
        height: 400px;
        width: 100%;
    <script src="http://openlayers.org/en/v3.3.0/build/ol.js" type="text/javascript"></script>
    <title>OpenLayers 3 example</title>
    <h2>My Map</h2>
    <div id="map" class="map"></div>
    <script type="text/javascript">
      var map = new ol.Map({
        target: 'map',
        controls: [
                        new OpenLayers.Control.Navigation(),
                        new OpenLayers.Control.PanZoomBar(),
                        new OpenLayers.Control.LayerSwitcher({'ascending':false}),
                        new OpenLayers.Control.Permalink(),
                        new OpenLayers.Control.ScaleLine(),
                        new OpenLayers.Control.Permalink('permalink'),
                        new OpenLayers.Control.MousePosition(),
                        new OpenLayers.Control.OverviewMap(),
                        new OpenLayers.Control.KeyboardDefaults()
        layers: [
          new ol.layer.Tile({
            source: new ol.source.MapQuest({layer: 'sat'})
          new ol.layer.Tile({
            source: new ol.source.OSM()
        view: new ol.View({
          center: ol.proj.transform([132.18333, 43.35], 'EPSG:4326', 'EPSG:3857'),
          zoom: 15

When I open it, it complains about Uncaught ReferenceError: OpenLayers is not defined at the line new OpenLayers.Control.Navigation(),.

How can I fix it?

  • 1
    You're mixing OpenLayers 2 and 3 code. OL2 uses the OpenLayers.* namespace, OL3 uses ol.* namespace. How to fix it? Settle on one version and stick to it.
    – kryger
    Mar 19 '15 at 21:58

That's because OpenLayers. is the v2.x namespace, also the controls have changed a bit.

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.