UNPKG

1.68 kBJavaScriptView Raw
1goog.require('ol.Map');
2goog.require('ol.View');
3goog.require('ol.interaction.Draw');
4goog.require('ol.interaction.Modify');
5goog.require('ol.interaction.Snap');
6goog.require('ol.layer.Tile');
7goog.require('ol.layer.Vector');
8goog.require('ol.source.OSM');
9goog.require('ol.source.Vector');
10goog.require('ol.style.Circle');
11goog.require('ol.style.Fill');
12goog.require('ol.style.Stroke');
13goog.require('ol.style.Style');
14
15var raster = new ol.layer.Tile({
16 source: new ol.source.OSM()
17});
18
19var source = new ol.source.Vector();
20var vector = new ol.layer.Vector({
21 source: source,
22 style: new ol.style.Style({
23 fill: new ol.style.Fill({
24 color: 'rgba(255, 255, 255, 0.2)'
25 }),
26 stroke: new ol.style.Stroke({
27 color: '#ffcc33',
28 width: 2
29 }),
30 image: new ol.style.Circle({
31 radius: 7,
32 fill: new ol.style.Fill({
33 color: '#ffcc33'
34 })
35 })
36 })
37});
38
39var map = new ol.Map({
40 layers: [raster, vector],
41 target: 'map',
42 view: new ol.View({
43 center: [-11000000, 4600000],
44 zoom: 4
45 })
46});
47
48var modify = new ol.interaction.Modify({source: source});
49map.addInteraction(modify);
50
51var draw, snap; // global so we can remove them later
52var typeSelect = document.getElementById('type');
53
54function addInteractions() {
55 draw = new ol.interaction.Draw({
56 source: source,
57 type: /** @type {ol.geom.GeometryType} */ (typeSelect.value)
58 });
59 map.addInteraction(draw);
60 snap = new ol.interaction.Snap({source: source});
61 map.addInteraction(snap);
62
63}
64
65/**
66 * Handle change event.
67 */
68typeSelect.onchange = function() {
69 map.removeInteraction(draw);
70 map.removeInteraction(snap);
71 addInteractions();
72};
73
74addInteractions();