(and the oddities of number evaluation in JavaScript)
Type conversion, typecasting, and coercion are different ways of, implicitly or explicitly, changing an entity of one data type into another. [--wikipedia][wikipedia]
import View from 'ol/View' | |
import Map from 'ol/Map' | |
import TileLayer from 'ol/layer/Tile' | |
import OSM from 'ol/source/OSM' | |
import VectorLayer from 'ol/layer/Vector' | |
import VectorSource from 'ol/source/Vector' | |
import GeoJSON from 'ol/format/GeoJSON' | |
import Style from 'ol/style/Style' | |
import Fill from 'ol/style/Fill' | |
/* New import */ |
/* New import at the top*/ | |
import { fromLonLat } from 'ol/proj' | |
// Wait for source to render | |
countriesSource.once('addfeature', () => { | |
// For each visited place | |
visitedPlaces.forEach(place => { | |
// Obtain map coordinates from longitude and latitude | |
const coordinate = fromLonLat(place) |
window.onload = () => { | |
const target = document.getElementById('map') | |
// countriesSource is a variable holding the vector source with countries from countries.geojson | |
const countriesSource = new VectorSource({ | |
url: 'https://raw.githubusercontent.com/bernardobelchior/openlayers-scratch-map-tutorial/start/countries.geojson', | |
format: new GeoJSON(), | |
}) | |
new Map({ |
/* [longitude, latitude] */ | |
const visitedPlaces = [ | |
[-0.118092, 51.509865], // London, United Kingdom | |
[-8.61099, 41.14961], // Porto, Portugal | |
[-73.935242, 40.730610], // New York, USA | |
[37.618423, 55.751244], // Moscow, Russia | |
] |
import View from 'ol/View'; | |
import Map from 'ol/Map'; | |
import TileLayer from 'ol/layer/Tile'; | |
import OSM from 'ol/source/OSM'; | |
import VectorLayer from 'ol/layer/Vector'; | |
import VectorSource from 'ol/source/Vector'; | |
import GeoJSON from 'ol/format/GeoJSON'; | |
/* New imports */ | |
import Style from 'ol/style/Style'; | |
import Fill from 'ol/style/Fill'; |
import View from 'ol/View'; | |
import Map from 'ol/Map'; | |
import TileLayer from 'ol/layer/Tile'; | |
import OSM from 'ol/source/OSM'; | |
/* New imports */ | |
import VectorLayer from 'ol/layer/Vector'; | |
import VectorSource from 'ol/source/Vector'; | |
import GeoJSON from 'ol/format/GeoJSON'; | |
window.onload = () => { |
import View from 'ol/View'; | |
import Map from 'ol/Map'; | |
/* New imports */ | |
import TileLayer from 'ol/layer/Tile'; | |
import OSM from 'ol/source/OSM'; | |
window.onload = () => { | |
const target = document.getElementById('map') | |
new Map({ |
import View from 'ol/View'; | |
import Map from 'ol/Map'; | |
// Wait for the page to load, otherwise getElementById may not work. | |
window.onload = () => { | |
const target = document.getElementById('map') | |
// Create a new map with the target as the div#map, and without layers - for now. | |
new Map({ | |
target, |
<!DOCTYPE html> | |
<html lang="en" style="height: 100%;"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>OpenLayers Scratch Map Tutorial</title> | |
<link rel="stylesheet" href="https://cdn.rawgit.com/openlayers/openlayers.github.io/master/en/v5.1.3/css/ol.css" | |
type="text/css"> | |
</head> | |
<body style="margin: 0; height: 100%"> |