workshop ol projection
by Francesco Boccacci
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.5.0/proj4.js"></script>
<script src="https://epsg.io/3003.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.4.3/css/ol.css">
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.4.3/build/ol.js"></script>
<body>
<div id="map" class="map"></div>
</body>
CSS
html, body {
height: 100%;
width: 100%;
margin: 0;
}
.map {
height: 100%;
width: 100%;
}
JavaScript
/*https://openlayers.org/en/latest/apidoc/module-ol_proj_proj4.html#.register*/
ol.proj.proj4.register(proj4)
const projection3003 = ol.proj.get('EPSG:3003');
//projection3003.setExtent([ 1241482.0019, 973563.1609, 1830078.9331, 5215189.0853])
const firenze_gbw = [1681450.785672498, 4848967.319261061];
const firenze_gmerc = ol.proj.transform(firenze_gbw,"EPSG:3003","EPSG:3857");
const map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
})
],
target: 'map',
view: new ol.View({
//center: firenze_gbw,
projection: projection3003,
center: [1681450.785672498, 4848967.319261061],
zoom: 10
})
});