0

Since most of the example available in Internet is working based on Internet.

I would like to download and use. I don't want to use either CDN or openlayer.org in my code.

Tim Diekmann
  • 7,755
  • 11
  • 41
  • 69
  • If openlayers is just css and js files then yes - you can download it locally and use rather than use a CDN, just like any other web library. I suggest you just.... try it – Nick.Mc Apr 15 '18 at 11:25
  • Is there any working example. Kindly share with me if you have any. – Ravindra Babu Apr 16 '18 at 02:19
  • In your HTML, use a reference to the file on your local web server in your code, rather than a CDN. You must have existing code that references a CDN right? This is just an exercise in using the correct file reference – Nick.Mc Apr 16 '18 at 02:24
  • Hi, i have tried that. sample code i have taken from internet and verified, its working fine when i have internet connection. If i want to use same approach when i don't have internet. Kindly advise on this please. http://openlayers.org/en/latest/doc/quickstart.html – Ravindra Babu Apr 18 '18 at 03:28

1 Answers1

2

Is it possible to use openlayers without a CDN?

Yes. Like any library, you can download locally. This page has some download links to get the CSS and JS files: https://openlayers.org/download/

You download and unzip those into a folder that is accessible from your web server. Usually this is a scripts subfolder

Then you simply reference them as explained here:

https://www.w3schools.com/css/css_howto.asp https://www.w3schools.com/tags/att_script_src.asp

(note these are very basic W3C references. You should really know this)

So if you downloaded those .js and .css files into a scripts subdirectory you do this:

<script src="scripts/theopenlayersscriptfile.js"></script>
<link rel="stylesheet" type="text/css" href="scripts/theopenlayerscssfile.css">

Edit:

After some experimenting and investigation, you mention that it is trying to access https://c.tile.openstreetmap.org/4/6/6.png

I googled and found this link https://wiki.openstreetmap.org/wiki/OpenLayers_Local_Tiles_Example

Which says

With this example you can browse your tiles stored localy without any webserver. I use this to check my tiles I downloaded to use in Osmtracker. But you can also browse Tiles rendered by any other techniques.

The instructions at this link appear to explain exactly what you want to do - it has references to all of the files you are trying to use.

Nick.Mc
  • 18,304
  • 6
  • 61
  • 91
  • Yes, Understand but my query is :- Is it possible to create base maps using open layers (without internet connectivity). example is given in below link. http://openlayers.org/en/latest/doc/quickstart.html. Same example i want to try using without internet. Kindly advise. – Ravindra Babu Apr 18 '18 at 03:16
  • I don't know. I don't know if openlayers needs to go back to get information. It will say it in the doco somewhere. Also you could try it and see. – Nick.Mc Apr 18 '18 at 03:46
  • I can see your deleted answer. Please add this information to your question, and MOST IMPORTANTLY do not use the words 'not working'. Actually describe what is happening. Also use F12 console to inspect web requests and see what is going on. – Nick.Mc Apr 18 '18 at 03:47
  • I am trying to build an offline web application using openlayers as shown in the sample code below. However the map does not load with the error (as shown in the firebug): Error: "https://c.tile.openstreetmap.org/4/6/6.png" Anyone who has already tried doing this and know exactly the steps to be done for it? . – Ravindra Babu Apr 18 '18 at 09:07
  • This may help: https://wiki.openstreetmap.org/wiki/OpenLayers_Local_Tiles_Example. I am very certainly not going to post a step by step guide. I’ve never used this before but all the information you need is on the web but you need to have some basic web programming knowledge – Nick.Mc Apr 18 '18 at 09:30
  • Did this answer help or not? – Nick.Mc Apr 25 '18 at 23:15