-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
90 lines (81 loc) · 2.17 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
||=========================================================||
|| * @author Teban18 <https://github.com/Teban18> ||
||* @description This project pretend represent coordinates||
||* grafically in a map. by OpenLayers api ||
||=========================================================||
*/
import 'ol/ol.css';
import {Map, View} from 'ol';
import {Vector as VectorLayer, Tile as TileLayer} from 'ol/layer';
import {Vector as VectorSource, OSM} from 'ol/source';
import Feature from 'ol/Feature';
import Point from 'ol/geom/Point';
import {defaults as defaultControls, ScaleLine} from 'ol/control';
import TileWMS from 'ol/source/TileWMS';
import {PointStyle, Fill, Stroke, Style, Circle} from 'ol/style';
import CircleStyle from 'ol/style/Circle';
const source = new VectorSource();
function ajaxRequest(){
var request = new XMLHttpRequest();
request.open("GET","https://www.datos.gov.co/resource/wsrw-hr5d.json",true);
request.addEventListener("load", function() {
for (const iterator of JSON.parse(request.responseText)){
let data = {
'coordinates': [iterator.longitud,iterator.latitud],
'radius':20,
'fillcolor': 'rgba(255,0,0,0.2)',
'strokecolor': 'rgba(255,0,0,0.2)'
}
createFeature(data);
}
});
request.send();
}
function createFeature(data){
let features = [];
let figure = new Feature({
geometry: new Point(data.coordinates)
});
figure.setStyle(new Style({
image: new CircleStyle({
radius: data.radius,
fill: new Fill({
color: data.fillcolor}),
stroke: new Stroke({
color: data.strokecolor})
})
}));
features.push(figure);
source.addFeatures(features);
}
function createMap(){
new Map({
controls: defaultControls().extend([
new ScaleLine({
units: 'degrees'
})
]),
layers: [
new TileLayer({
source: new OSM({
params: {
'LAYERS': 'ne:NE1_HR_LC_SR_W_DR',
'TILED': true
}
})
}),
new VectorLayer({
source: source
})
],
target: 'map',
view: new View({
projection: 'EPSG:4326',
center: [0, 0],
zoom: 2
})
});
}
ajaxRequest();
createMap();