blob: 3ef1da3623f31319a4670a6662eff53c34220d55 (
plain)
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
|
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Geo Feature Explorer</title>
<link rel="stylesheet" href="https://openlayers.org/en/v4.1.0/css/ol.css" type="text/css">
</head>
<body>
<div id="map"></div>
<script src="https://openlayers.org/en/v4.1.0/build/ol.js"></script>
<script>
var raster = new ol.layer.Tile({
source: new ol.source.OSM()
});
var wkt = 'POLYGON((10.689 -25.092, 34.595 ' +
'-20.170, 38.814 -35.639, 13.502 ' +
'-39.155, 10.689 -25.092))';
var format = new ol.format.WKT();
var feature = format.readFeature(wkt, {
dataProjection: 'EPSG:4326',
featureProjection: 'EPSG:3857'
});
var vector = new ol.layer.Vector({
source: new ol.source.Vector({
features: [feature]
})
});
var map = new ol.Map({
layers: [raster, vector],
target: 'map',
view: new ol.View({
center: ol.proj.fromLonLat([2.3475075, 48.869163]),
zoom: 16
})
});
var select_click = new ol.interaction.Select({
condition: ol.events.condition.click
});
select_click.on('select', function(e) {
if (e.selected.length) {
var feature = e.selected[0];
}
});
map.addInteraction(select_click);
</script>
</body>
</html>
|