Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenLayers snippet example #17

Open
jbelien opened this issue Sep 25, 2024 · 3 comments
Open

OpenLayers snippet example #17

jbelien opened this issue Sep 25, 2024 · 3 comments

Comments

@jbelien
Copy link

jbelien commented Sep 25, 2024

Using Leaflet?

A Leaflet-based snippet is coming soon.

Could you also add an OpenLayers snippet ?

Thanks a lot for setting up OpenFreeMap! ❤️

@hyperknot
Copy link
Owner

Absolutely I'd be more than happy to add it, especially if someone contributes the example code.

I've just looked around, probably the official OpenMapTiles example is the best for this list:
https://openlayers.org/ol-mapbox-style/examples/

@hyperknot
Copy link
Owner

Asked here: openlayers/openlayers#16223

@hyperknot
Copy link
Owner

Got an answer from @ahocevar, here is the minimum example:

<script src="https://unpkg.com/ol@10/dist/ol.js"></script>
<script src="https://unpkg.com/ol-mapbox-style@12/dist/olms.js"></script>
<link rel="stylesheet" href="https://unpkg.com/ol@10/ol.css" type="text/css">
<div id="map" style="width: 100%; height: 500px"></div>
<script>
  const map = new ol.Map({
    target: 'map',
    view: new ol.View({
      center: ol.proj.fromLonLat([13.388, 52.517]),
      zoom: 9.5
    })
  });
  olms.apply(map, 'https://tiles.openfreemap.org/styles/liberty');
</script>

Or with modules:

import 'ol/ol.css';
import {apply} from 'ol-mapbox-style';

apply('map', ' https://tiles.openfreemap.org/styles/liberty');

I'll rework the examples in the documentation and include it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants