0

I would like to add polygon geojson in the EPSG:2178 projection. The polygon should be displayed in central Europe but I see my geojson in Asia. Where have I made a mistake? Where can I find information about ol.View "center"?

<!doctype html>
<html lang="en">
  <head>
    <link rel='stylesheet' href='css/ol.css'>
    <style>
      #map {
        height: 100%;
        width: 100%;
      }
    </style>
    <title>OpenLayers 3 example</title>
    <script src="build/ol.js" type="text/javascript"></script>
  </head>
  <body>
    <h1>My Map</h1>
    <div id="map"></div>
    <script type="text/javascript">
      var map = new ol.Map({
        target: 'map',
        layers: [
           new ol.layer.Tile({
              source: new ol.source.OSM()
           }),

   new ol.layer.Vector({
      title: 'added Layer',
      source: new ol.source.GeoJSON({
         projection : 'EPSG:2178',
         url: 'gjson/eg.geojson'
      })
  })
        ],
        view: new ol.View({
          center:[0,0],
          zoom:2

        })
      });
    </script>
  </body>
</html>
1

First of all you should update your ol version, ol.source.GeoJSON doesn't exist anymore see the new example

Second if you want that your coordinates are automatically transformed to the map projection system (by default it's EPSG:3857), you need to include Proj4js librairy and the definition of your projection:

<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.12/proj4.js"></script>
<script src="//epsg.io/2178.js"></script>

Finally, if you are stuck with this version of OpenLayers, the definiton of your ol.source.GeoJSON should be :

new ol.source.GeoJSON({
  defaultProjection : 'EPSG:2178',
  projection : 'EPSG:3857', // This is the destination projection not the data projection
  url: 'gjson/eg.geojson'
})

See the ol.source.GeoJSON doc

Hope this helps.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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