I am new in OpenLayers 3. I am working with GeoServer 2.6.2 and I would like to create a web mapping with OpenLayers 3.

I am working with a custom projection from El Salvador (Central America). It is not an EPSG projection. I show you in Proj4 format:

+proj=lcc +lat_1=14.25 +lat_2=13.3166667 +lat_0=13.783333333333333    
+lon_0=-89 +x_0=500000.00004 +y_0=295809.17715 +k_0=0.999967040229754        
+a=6378206.4 +rf=294.9786982138982 +units=m  +no_defs 

OpenLayers library does not recognize this projection. I should define it before calling the WFS Service. I consulted many examples on the web page OpenLayers, but I cannot solve the problem.

Could someone help me?

I tried applying the code @Gabor mentioned, but I can not make it work. This is the JavaScript code that I have created:

proj4.defs('EPSG:1000', "+proj=lcc +lat_1=14.25 +lat_2=13.3166667 +lat_0=13.783333333333333 +lon_0=-89 +x_0=500000.00004 +y_0=295809.17715 +k_0=0.999967040229754 +a=6378206 +rf=294.9786982138982 +units=m  +no_defs +towgs84=0,105.5,197.2,0,0,0,0"); 

var projSalvador = ol.proj.get('EPSG:1000');
var view = new ol.View({                    
        projection: "EPSG:3857",
        center: [-9888991.9947, 1533959.4220],
var vector2Source = new ol.source.ServerVector({
  format: new ol.format.GeoJSON(),
  loader: function(extent, resolution, projection) {
    var url = 'http://localhost/geoserver/workspace/wfs?service=WFS&' +
            'version=1.1.0&request=GetFeature&typename=workspace:Polygon&' +
            'outputFormat=application/json&format_options=callback:loadFeatures' +
            '&srsname=EPSG:6823&bbox=' + extent.join(',') + ',EPSG:3857';
      url: url,
      dataType: 'jsonp'
  strategy: ol.loadingstrategy.createTile(new ol.tilegrid.XYZ({
    maxZoom: 19
  projection: projSalvador,

var loadFeatures = function(response) {

var vector2 = new ol.layer.Vector({
  source: vector2Source,
  style: new ol.style.Style({
    stroke: new ol.style.Stroke({
      color: 'rgba(0, 0, 255, 1.0)',
      width: 2

Browser gives me next problem with this code:

  • "Uncaught SyntaxError: Unexpected token :" (SyntaxError in url wfs code). OpenLayers can not give me any feature, like I can see in json code [{"type":"FeatureCollection","totalFeatures":0,"features":[{"type":"Feature","id":"Parcela.9415","geometry"....].

I can not find and fix the problem.

Can anyone help me?

1 Answer 1


You can define any projection with a valid Proj4 definition in OpenLayers. OpenLayers 3 can use Proj4JS version 2.2+. First, you have to define the custom projection with Proj4JS:

proj4.defs("NAMEFORMYCUSTOMPROJ", "+proj=lcc +lat_1=14.25 +lat_2=13.3166667 +lat_0=13.783333333333333" + 
"+lon_0=-89 +x_0=500000.00004 +y_0=295809.17715 +k_0=0.999967040229754 +a=6378206" + 
"+rf=294.9786982138982 +units=m  +no_defs +towgs84=0,105.5,197.2,0,0,0,0");

With your custom projection defined, you can save the projection object to a variable,

var projection = ol.proj.get("NAMEFORMYCUSTOMPROJ");

or refer to it with the name string in the constructor.

new ol.source.ServerVector({
    projection: "NAMEFORMYCUSTOMPROJ",

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.