Skip to content

Instantly share code, notes, and snippets.

View bernardobelchior's full-sized avatar

Bernardo Belchior bernardobelchior

View GitHub Profile
@bernardobelchior
bernardobelchior / index.js
Last active August 27, 2018 17:55
final index.js
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 */
@bernardobelchior
bernardobelchior / index.js
Last active August 27, 2018 17:55
delete countries index.js
/* 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)
@bernardobelchior
bernardobelchior / index.js
Last active August 27, 2018 17:56
variables index.js
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({
@bernardobelchior
bernardobelchior / index.js
Created August 27, 2018 17:34
visited places index.js
/* [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
]
@bernardobelchior
bernardobelchior / index.js
Last active August 27, 2018 17:12
style index.js
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';
@bernardobelchior
bernardobelchior / index.js
Created August 27, 2018 16:59
countries.geojson index.js
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 = () => {
@bernardobelchior
bernardobelchior / index.js
Last active August 27, 2018 16:46
OSM index.js
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({
@bernardobelchior
bernardobelchior / index.js
Last active August 27, 2018 16:42
map index.js
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%">

Unary operators

(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]


Unary operators, or "typeof +'foo' === huh?"