This repository has been archived by the owner on Apr 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
/
ImportFeature.js
82 lines (63 loc) · 2.6 KB
/
ImportFeature.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
/**
* @copyright 2011 geOps
* @license https://github.com/geops/ole/blob/master/license.txt
* @link https://github.com/geops/ole
*/
/**
* Class: OpenLayers.Editor.Control.ImportFeature
* The ImportFeature provides a button to import all selected features
* to a given layer. Layers from which selected features will be imported
* must have a property exportFeature set to true.
*
* Inherits from:
* - <OpenLayers.Control.Button>
*/
OpenLayers.Editor.Control.ImportFeature = OpenLayers.Class(OpenLayers.Control.Button, {
/**
* Property: layer
* {<OpenLayers.Layer.Vector>}
*/
layer: null,
title: OpenLayers.i18n('oleImportFeature'),
/**
* Constructor: OpenLayers.Editor.Control.DeleteFeature
* Create a new control for importing features.
*
* Parameters:
* layer - {<OpenLayers.Layer.Vector>} The layer to which selected
* features will be imported.
* options - {Object} An optional object whose properties will be used
* to extend the control.
*/
initialize: function (layer, options) {
this.layer = layer;
OpenLayers.Control.Button.prototype.initialize.apply(this, [options]);
this.trigger = this.importFeature;
this.title = OpenLayers.i18n('oleImportFeature');
this.displayClass = "oleControlDisabled " + this.displayClass;
},
/**
* Method: importFeature
*/
importFeature: function () {
var importFeatures = [];
if (this.map.editor.sourceLayers.length > 0) {
for (var i = 0, li = this.map.editor.sourceLayers.length; i < li; i++) {
for (var j = 0, lj = this.map.editor.sourceLayers[i].selectedFeatures.length; j < lj; j++) {
this.map.editor.sourceLayers[i].selectedFeatures[j].renderIntent = 'default';
importFeatures.push(this.map.editor.sourceLayers[i].selectedFeatures[j]);
}
this.map.editor.sourceLayers[i].removeFeatures(this.map.editor.sourceLayers[i].selectedFeatures);
this.map.editor.sourceLayers[i].events.triggerEvent('featureunselected');
}
if (importFeatures.length > 0) {
this.layer.addFeatures(importFeatures);
} else {
return this.map.editor.showStatus('error', OpenLayers.i18n('oleImportFeatureSourceFeature'));
}
} else {
return this.map.editor.showStatus('error', OpenLayers.i18n('oleImportFeatureSourceLayer'));
}
},
CLASS_NAME: 'OpenLayers.Editor.Control.ImportFeature'
});