Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Openlayer 3 coordinates

I have a latitude and longitude of some point. How to conver its to the OpenLayer 3 map coordinate system? My code is:

...requiries...


    var coord = [55.7522200, 37.61556005];
    //coord =  ol.proj.transform(coord,'EPSG:4326', 'EPSG:3857');
    var vectorSource = new ol.source.GeoJSON(
         ({
          object: {
            'type': 'FeatureCollection',
            'crs': {
              'type': 'name',
              'properties': {
                'name': 'EPSG:3857'
              }
            },
            'features': [
              {
                'type': 'Feature',
                'geometry': {
                  'type': 'Point',
                  'coordinates': coord
                }
              }
            ]
          }
        }));

    ...
    var map = ...

Could you gave me an example for converting the var coords on JavaScript. You can see this example of code at link http://openlayers.org/en/v3.0.0/examples/geojson.html

like image 935
DmitriySidyakin Avatar asked Dec 26 '22 01:12

DmitriySidyakin


1 Answers

If you have a coordinate [lon, lat] (in that order) you can transform it using:

var newCoord = ol.proj.transform([lon, lat], 'EPSG:4326', 'EPSG:3857');
like image 93
erilem Avatar answered Feb 16 '23 00:02

erilem