walkermatt / ol-popup

OpenLayers popup overlay

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ol.Overlay.Popup is not a constructor

rrm364 opened this issue · comments

I am trying to use Popups on a map I have created and I am having trouble. Popups work fine on the example that I cloned onto my laptop. However, I cannot use it on my own maps. I add the following two lines to my own map.

In the head I add,
<link rel="stylesheet" href="https://raw.githubusercontent.com/walkermatt/ol3-popup/master/src/ol3-popup.css" />

And I add in the body I add
<script src="https://raw.githubusercontent.com/walkermatt/ol3-popup/master/src/ol3-popup.js"></script>

However, I get the ol.Overlay.Popup is not a constructor error when I do this and add
var popup = new ol.Overlay.Popup(); map.addOverlay(popup);

To the map. I tried using the copying the cloned files into the directory my maps were in but I ended up with the same problem both ways. Any ideas of what is wrong?

@rrm364 from the error it sounds as though the script isn't loaded by the time you try and create an instance with var popup = new ol.Overlay.Popup();. Make sure you include the script after OpenLayers 3 and before your script that creates an instance. You can check your browsers dev tools to ensure that the file is being loaded.

It's preferable to use a local copy of the files, pulling content direct from GitHub or rawgit.com is discouraged.

That solved it! I'm feelng incredibly foolish right now.