How to use the ol/proj.fromLonLat function in ol

To help you get started, we’ve selected a few ol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cos301-2019-se / Follow-Me-Drones / user-application / src / app / tab1 / map / map.component.ts View on Github external
})
      ],
      target: 'map',
      view: this.view
    });

    this.geolocation = new Geolocation({
      // enableHighAccuracy must be set to true to have the heading value.
      trackingOptions: {
        enableHighAccuracy: true
      },
      projection: this.view.getProjection()
    });

    const coord = [28.232592, -25.755710]; // TUKS IT BUILDING COORDS
    this.view.setCenter(fromLonLat(coord));

    this.getElement('track').addEventListener('change', () => {
      console.log('works');
      this.geolocation.setTracking(true);
    });

    this.geolocation.on('change', () => {
      this.getElement('accuracy').innerText = this.geolocation.getAccuracy() + ' [m]';
      this.getElement('altitude').innerText = this.geolocation.getAltitude() + ' [m]';
      this.getElement('altitudeAccuracy').innerText = this.geolocation.getAltitudeAccuracy() + ' [m]';
      this.getElement('heading').innerText = this.geolocation.getHeading() + ' [rad]';
      this.getElement('speed').innerText = this.geolocation.getSpeed() + ' [m/s]';
      this.getElement('lat').innerText = this.geolocation.getPosition()[0];
      this.getElement('lon').innerText = this.geolocation.getPosition()[1];
      // console.log( this.geolocation.getPosition());
      // alert('changed');
github terrestris / react-geo / src / Field / CoordinateReferenceSystemCombo / CoordinateReferenceSystemCombo.example.jsx View on Github external
import { render } from 'react-dom';
import { CoordinateReferenceSystemCombo } from '../../index.js';

import proj4 from 'proj4';
import OlMap from 'ol/map';
import OlView from 'ol/view';
import OlLayerTile from 'ol/layer/tile';
import OlSourceOsm from 'ol/source/osm';
import OlProjection from 'ol/proj';
import OlExtent from 'ol/extent';

//
// ***************************** SETUP *****************************************
//
const defaultView = new OlView({
  center: OlProjection.fromLonLat([37.40570, 8.81566]),
  zoom: 4
});
const map = new OlMap({
  layers: [
    new OlLayerTile({
      name: 'OSM',
      source: new OlSourceOsm()
    })
  ],
  view: defaultView
});

OlProjection.setProj4(proj4);

/**
 * set map projection and perform client-side raster reprojection from
github terrestris / react-geo / src / Grid / FeatureGrid / FeatureGrid.example.jsx View on Github external
import federalStates from '../../../assets/federal-states-ger.json';

import {
  FeatureGrid
} from '../../index.js';

const map = new OlMap({
  layers: [
    new OlLayerTile({
      name: 'OSM',
      source: new OlSourceOsm()
    })
  ],
  view: new OlView({
    center: OlProj.fromLonLat([37.40570, 8.81566]),
    zoom: 4
  })
});

const format = new OlFormatGeoJson();
const features = format.readFeatures(federalStates);

// eslint-disable-next-line require-jsdoc
const nameColumnRenderer = val =&gt; <a href="{`https://en.wikipedia.org/wiki/${val}`}">{val}</a>;

render(
  <div>
    <div>
      </div></div>
github jumpinjackie / jsdoc-typescript-plugin / test / ol-tests.ts View on Github external
sources.push(new TileWMS());
sources.push(new VectorTile({}));
sources.push(new WMTS({
    tileGrid: new WMTSTileGrid({
        resolutions: [],
        matrixIds: []
    }),
    projection: "EPSG:4326",
    layer: "blah",
    style: "default",
    matrixSet: "thereisnospoon"
}));
sources.push(new Zoomify());

olXml.parse("Bar");
const tx = olProj.fromLonLat([0, 0]);
const center = olExtent.getCenter([1, 2, 3, 4]);
github openlayers / workshop / src / en / examples / basics / popup.js View on Github external
navigator.geolocation.getCurrentPosition(function(pos) {
  const coords = fromLonLat([pos.coords.longitude, pos.coords.latitude]);
  map.getView().animate({center: coords, zoom: 10});
  //! [add-point]
  position.addFeature(new Feature(new Point(coords)));
  //! [add-point]
});
github county-of-simcoe-gis / SimcoeCountyWebViewer / src / helpers / helpers.js View on Github external
export function toWebMercatorFromLatLong(coords) {
  return fromLonLat(coords);
  //return transform(coords, "EPSG:4326", "EPSG:3857");
}
github openlayers / workshop / src / en / examples / basics / point-feature.js View on Github external
navigator.geolocation.getCurrentPosition(function(pos) {
  const coords = fromLonLat([pos.coords.longitude, pos.coords.latitude]);
  map.getView().animate({center: coords, zoom: 10});
  //! [add-point]
  position.addFeature(new Feature(new Point(coords)));
  //! [add-point]
});
github infra-geo-ouverte / igo2-lib / packages / geo / src / lib / map / shared / map.ts View on Github external
setView(options: MapViewOptions) {
    if (this.viewController !== undefined) {
      this.viewController.clearStateHistory();
    }

    const view = new olView(options);
    this.ol.setView(view);

    this.unsubscribeGeolocate();
    if (options) {
      if (options.center) {
        const projection = view.getProjection().getCode();
        const center = olproj.fromLonLat(options.center, projection);
        view.setCenter(center);
      }

      if (options.geolocate) {
        this.geolocate(true);
      }
    }
  }
github vmware-samples / vmware-blockchain-samples / supply-chain / src / app / world-map / world-map.component.ts View on Github external
addLocation(loc: any[], to: number[], idx: number = 0) {
    const point = new Feature(new Point(fromLonLat(to)));
    this.ordersPoint.push(point);

    if (idx !== 0) {
      const from = loc[idx - 1];
      const line = new LineString([fromLonLat(from), fromLonLat(to)]);
      const feature = new Feature({
        geometry: line,
        lonLat: to
      });
      this.ordersTracking.addFeature(feature);
    }
  }
github jumpinjackie / mapguide-react-layout / src / api / ol-factory.ts View on Github external
public transformCoordinateFromLonLat(lonlat: Coordinate2D, proj?: ProjectionLike): Coordinate2D {
        return olProj.fromLonLat(lonlat as number[], proj) as Coordinate2D;
    }
    public transformCoordinate(coordinate: Coordinate2D, source: ProjectionLike, target: ProjectionLike): Coordinate2D {