OpenLayers OpenLayers

Ticket #639: DragMarker.txt

File DragMarker.txt, 3.3 kB (added by openlayers, 4 months ago)
Line 
1 OpenLayers.Handler.Marker = OpenLayers.Class.create();
2 OpenLayers.Handler.Marker.prototype =
3   OpenLayers.Class.inherit(OpenLayers.Handler.Feature, {
4
5     handle: function(evt) {   
6             var type = evt.type;
7         var node = OpenLayers.Event.element(evt);
8         var feature = null;
9         for (var i = 0; i < this.layer.markers.length; i++) {
10             if (this.layer.markers[i].icon.imageDiv.firstChild == node) {
11                 feature = this.layer.markers[i];
12                 break;
13             }
14         }
15         var selected = false;
16         if(feature) {
17             if(this.geometryTypes == null) {
18                 // over a new, out of the last and over a new, or still on the last
19                 if(!this.feature) {
20                     // over a new feature
21                     this.callback('over', [feature]);
22                 } else if(this.feature != feature) {
23                     // out of the last and over a new
24                     this.callback('out', [this.feature]);
25                     this.callback('over', [feature]);
26                 }
27                 this.feature = feature;
28                 this.callback(type, [feature]);
29                 selected = true;
30             } else {
31                 if(this.feature && (this.feature != feature)) {
32                     // out of the last and over a new
33                     this.callback('out', [this.feature]);
34                     this.feature = null;
35                 }
36                 selected = false;
37             }
38         } else {
39             if(this.feature) {
40                 // out of the last
41                 this.callback('out', [this.feature]);
42                 this.feature = null;
43             }
44             selected = false;
45         }
46         return selected;
47     },
48
49
50     CLASS_NAME: "OpenLayers.Handler.Marker"
51 });
52
53 OpenLayers.Control.DragMarker = OpenLayers.Class.create();
54 OpenLayers.Control.DragMarker.prototype =
55   OpenLayers.Class.inherit(OpenLayers.Control.DragFeature, {
56
57     initialize: function(layer, options) {
58         OpenLayers.Control.prototype.initialize.apply(this, [options]);
59         this.layer = layer;
60         this.handlers = {
61                 drag: new OpenLayers.Handler.Drag(
62                     this, OpenLayers.Util.extend({down: this.downFeature,
63                                                      move: this.moveFeature,
64                                                      up: this.upFeature,
65                                                      out: this.cancel,
66                                                      done: this.doneDragging
67                                                     }, this.dragCallbacks)
68                         ),
69                         feature: new OpenLayers.Handler.Marker(
70                             this, this.layer, OpenLayers.Util.extend({over: this.overFeature,
71                                                         out: this.outFeature
72                                                        }, this.featureCallbacks),
73                             {geometryTypes: this.geometryTypes}
74                         )
75                     };
76     },
77    
78     moveFeature: function(pixel) {
79         var px = this.feature.icon.px.add(pixel.x - this.lastPixel.x, pixel.y - this.lastPixel.y);;
80         this.feature.moveTo(px);
81         this.lastPixel = pixel;
82         this.onDrag(this.feature, pixel);
83     },
84
85     CLASS_NAME: "OpenLayers.Control.DragMarker"
86 });