0

Following OpenLayers examples, I try to reproject OSM in a custom projection. The view is empty, no OSM tile is downloaded.

index.js :

import {get as getProjection} from 'ol/proj';
import Map from 'ol/Map';
import 'ol/ol.css';
import OSM from 'ol/source/OSM';
import proj4 from 'proj4';
import {register} from 'ol/proj/proj4';
import TileLayer from 'ol/layer/Tile';
import TileWMS from 'ol/source/TileWMS';
import View from 'ol/View';
import * as Gp from 'geoportal-extensions-openlayers';

proj4.defs('EPSG:2154','+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3' + 
'+x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
register(proj4);
var franceProjection = getProjection('EPSG:2154');

 var couches = [
  new TileLayer({
  source: new OSM()
})
];
var map = new Map({
 target: 'map',
 layers: couches,
 view: new View({
projection: 'EPSG:2154',
center: [524326, 6700656],
zoom: 14
 })     
});

package.json

{
"name": "iliad_ol5.3.0",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "parcel index.html",
"build": "parcel build --public-url . index.html"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"geoportal-extensions-openlayers": "^3.0.7",
"ol": "^5.3.0",
"proj4": "^2.6.0"
},
"devDependencies": {
"parcel-bundler": "^1.12.4"
},
"description": ""
}

I know that it is a basic projection issue but even that's hard for me.

2
  • In map view specification leave out map.setView( call and retain just view definition new View( ….
    – TomazicM
    Mar 4, 2020 at 14:05
  • same result : view empty and in network debug window no tile downloaded (FF).
    – Leehan
    Mar 4, 2020 at 14:15

1 Answer 1

2

The code below works without any problems, so there must be problem either in your environment (imports) or in your code after removing map.setView( function.

proj4.defs('EPSG:2154','+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3' + 
'+x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs');
ol.proj.proj4.register(proj4);
var franceProjection = ol.proj.get('EPSG:2154');

var couches = [
  new ol.layer.Tile({
    source: new ol.source.OSM()
  })
];
var map = new ol.Map({
 target: 'map',
 view: new ol.View({
  projection: 'EPSG:2154',
  center: [524326, 6700656],
  zoom: 14
 }),
 layers: couches
});    
3
  • Thanks. I tried you code and the result was nearly the same : map empty but blue buttons + and - from OL disappeared ; I rebuilt the dev env as recommanded on OL openlayers.org/en/latest/doc/tutorials/bundle.html site, used my code in the first message but nothing changed, except the comeback of blue buttons... I can add OSM in 3857 but as soon as I want to use EPSG:2154 the map is empty.
    – Leehan
    Mar 5, 2020 at 8:31
  • If there are no errors in the console and all the files all loading correctly, then I'm at loss here since I don't have the same environment. Obviously there is some problem with proj4.
    – TomazicM
    Mar 5, 2020 at 8:47
  • I tried with proj4 2.5.0 but no tile dowloaded as well. They are not listed in network debug window.
    – Leehan
    Mar 5, 2020 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.