1 | goog.require('ol.Map');
|
2 | goog.require('ol.View');
|
3 | goog.require('ol.interaction.Draw');
|
4 | goog.require('ol.layer.Tile');
|
5 | goog.require('ol.layer.Vector');
|
6 | goog.require('ol.source.OSM');
|
7 | goog.require('ol.source.Vector');
|
8 |
|
9 | var raster = new ol.layer.Tile({
|
10 | source: new ol.source.OSM()
|
11 | });
|
12 |
|
13 | var source = new ol.source.Vector({wrapX: false});
|
14 |
|
15 | var vector = new ol.layer.Vector({
|
16 | source: source
|
17 | });
|
18 |
|
19 | var map = new ol.Map({
|
20 | layers: [raster, vector],
|
21 | target: 'map',
|
22 | view: new ol.View({
|
23 | center: [-11000000, 4600000],
|
24 | zoom: 4
|
25 | })
|
26 | });
|
27 |
|
28 | var typeSelect = document.getElementById('type');
|
29 |
|
30 | var draw;
|
31 | function addInteraction() {
|
32 | var value = typeSelect.value;
|
33 | if (value !== 'None') {
|
34 | draw = new ol.interaction.Draw({
|
35 | source: source,
|
36 | type: (typeSelect.value),
|
37 | freehand: true
|
38 | });
|
39 | map.addInteraction(draw);
|
40 | }
|
41 | }
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 | typeSelect.onchange = function() {
|
48 | map.removeInteraction(draw);
|
49 | addInteraction();
|
50 | };
|
51 |
|
52 | addInteraction();
|