I want to create the scenario shown in the OpenLayers Demos:
http://sandbox.zzolo.org/node/add/openlayers-cck-wkt-example
When I try to create a node I can set points on the map, but I can't change them. Every time when I click on the map it set's a new point. In the demo when I click on a point, the point get's highlighted and I can delete it by pressing DEL or the point can be moved. In my installation when I click on a point, a new point is set in the same place so I can't change or delete the point.
I can't find any setting in the menu to control this behaviour. I think it's a bug.
My configuration is very simple. Drupal 6.15 / latest dev version of OpenLayers 2 / latest dev version of CTools
OpenLayers Source: Default Setting
Created own preset with Base layer "Google Maps Hybrid"
CCK Widget type "OpenLayers Map" / Number of values: "5" / Feature Types: "Point"
Comment | File | Size | Author |
---|---|---|---|
#17 | 744360-openlayers_behavior_drawfeatures.js_.patch | 980 bytes | vlad.k |
#12 | 01_set_feautures.jpg | 57.13 KB | vlad.k |
#12 | 02_modify_feauture1.jpg | 56.23 KB | vlad.k |
#12 | 03_modify_feauture2.jpg | 56.03 KB | vlad.k |
#12 | 04_modify_feauture3.jpg | 56.48 KB | vlad.k |
Comments
Comment #1
tmcw CreditAttribution: tmcw commentedThis isn't really a bug, because it's not a feature yet. The ModifyFeature control is finicky and I haven't gotten it to work perfectly. If it does work, you'll need to use 'd' to delete features, not the delete key (delete will typically bring your browser to the last page it visited). I'll need to test this a bit; usually I use vim bindings in whatever browsers, don't use these features.
Comment #2
vlad.k CreditAttribution: vlad.k commentedThank you for the quick answer. Can you please give me some more information?
1. Isn't the OpenLayers "ModifiyFeature-Control" implemented at all in Openlayers V2 Drupal Module?
2. Is there any posibility to move and delete points on a map in Openlayers V2?
3. Do you plan to implement this feature and do you (the OpenLayers module maintainers/developers) think that this feature is important?
4. Do you know how the above mentioned demo scenario is implemented? Is this OpenLayers V1 or is this a custom implementation/modification of the standard OpenLayers module?
Comment #3
tmcw CreditAttribution: tmcw commentedAs far as I know, the OpenLayers ModifyFeature control wasn't fully implemented in OpenLayers 2.x. There are plans to implement it in 2.x, but it has to be done right - it will likely be necessary to create a new button for the control so that it can be added to the EditingPanel control and toggled on and off. There is a ModifyFeature control in the OpenLayers javascript library, of course, but it isn't quite built out (just like how the EditingPanel control isn't really built out). So, yes, I think that this feature is important, but it wasn't essential for the first rendition of OpenLayers CCK. I'll likely build it soon (or will accept patches) that will implement it, but for the time being, there is no prepackaged way to move and delete points in OpenLayers 2.x.
Comment #4
vlad.k CreditAttribution: vlad.k commentedI need this feature. I would like to see it implemented in the OpenLayers 2.x Drupal module. I can think of two options to get this done quickly:
1. I would pay to get this feature implemented quickly if it is a price that I can afford.
2. I could help implement this feature. For this I would need some help from the module developers. The help would be some information about the module architecture and a discussion about the design concept so I can implement it "the right way" so that you are willing to commit the patch into the main OpenLayers 2.x branch.
What do you think?
Comment #5
zzolo CreditAttribution: zzolo commentedJust to point out that the 1.x version does have this feature. I am sure that it could be coded better but it does work fine and has for a while. Depending on the needs of your project, the 1.x version may be the better solution, though I cannot guarantee a completely automated upgrade path from 1.x to 2.x (though this is still being worked on).
As far as getting this into 2.x, as @tmcw stated, it is definitely in the queue. I am not sure if any of the developers have any specific time to be able to take on contract work (but I can only speak for myself).
I think the best place to start is from what @tmcw has said above and looking at the code that it exists. Otherwise, just understanding how we have implemented the "behaviors" in 2.x is the basics.
Comment #6
vlad.k CreditAttribution: vlad.k commentedI've done some research. Please correct me if I'm wrong.
- The ability to move and delete features on a map is a behaviour.
- Aditional behaviours can be added by custom modules.
-> Can you name any module that provides a behaviour for OpenLayer or is there any HowTo/Doc how a custom module can provide a behaviour for the OpenLayers module? Is that something like a CTools plugin? Hints of any kind (e.g. code snippets, docs, lines in a module file, etc.) would be grately appreciated.
- The behaviour must update the CCK WKT Field. Is there any API function that can be called to update that field in JavaScript on the client side?
I could build a module that provides a behaviour for OpenLayers. If I can provide this behaviour an eventhandler that calls a OpenLayers Javascript API function like "update CCK WKT Field" the module can be built without touching the OpenLayers module, only by using it's API. Is this correct?
Of course I would share this module with the community.
Comment #7
zzolo CreditAttribution: zzolo commentedThe best place to start on this is the openlayers_cck module. It implements all the hooks for a behavior and is a perfect example.
Ideally, it would be really cool if you made an actual patch for this project instead of a separate module (as we would like to get this functionality in).
The basic hooks and functions to implement (not looking at the code at the moment):
* hook_openlayers_api
* hook_openlayers_behaviors
* a callback function for the behavior in a separate file
* an included JS file for the actual behavior
I have not really though about this much, but it may be best to edit the existing behavior in the CCK module.
Comment #8
tmcw CreditAttribution: tmcw commentedOkay, so I think this is the best approach here:
The ModifyFeature abilities should be added to the DrawFeature control, rather as a separate control. You should find a way to have OpenLayers.Control.ModifyFeature be added to the EditingToolbar added in the drawfeature control.
So, in
modules/openlayers_cck/includes/behaviors/js/openlayers_cck_drawfeature.js
, see lines 73-78, which modify the controls in the EditingToolbar after it is created with line 60. You'll want to add something likecontrol.controls.push(new OpenLayers.Control.ModifyFeature)
, which will toggle the ModifyFeature control. Then you'll need to add a CSS style to make this visible - download the OpenLayers library fully and check out lines 185-215 which style the other controls within the EditingToolbar. There are other images for moving and removing features which I don't think are used in anyplace - you could use those.Yeah - I think that this should be part of the module, as well. You can get functionality immediately (faster than making another module) and we can review it quickly for inclusion.
Comment #9
tmcw CreditAttribution: tmcw commentedIt might be simpler than that. Here's a patch that adds a ModifyFeature control to the EditingToolbar control. It seems to work for me, but I'm not that confident and can't thoroughly test it today.
Comment #10
vlad.k CreditAttribution: vlad.k commentedHi tmcw,
I tried to apply the patch but eclipse says that it is not valid. I tried to apply it manually but I can't see any line number in the patch where to insert the lines in openlayers_cck_drawfeature.js. I inserted it before line 89 control.redraw(); but it does not work well. Where in openlayers_cck_drawfeature.js should the new code be added?
Comment #11
tmcw CreditAttribution: tmcw commentedIt should be added where you tried. Try applying it manually?
Comment #12
vlad.k CreditAttribution: vlad.k commentedI inserted the code in openlayers_cck_drawfeature.js here:
...
else {
c.push(control.controls[i]);
}
}
}
control.controls = c;
control.addControls(
new OpenLayers.Control.ModifyFeature(data_layer,
{
'displayClass': 'olControlModifyFeature'
})
);
control.redraw();
...
I have the following problem:
Comment #13
vlad.k CreditAttribution: vlad.k commentedHi the described error in the above comment was related to this issue http://drupal.org/node/763680.
I see that you moved the openlayers_behavior_drawfeatures.js outside of openlayers_CCK to the openlayers module and you also inserted the ModifyFeature control in this file:
var mcontrol = new OpenLayers.Control.ModifyFeature(data_layer);
data.openlayers.addControl(mcontrol);
But I still can't change the features on the Openlayers CCK widget. Is there any configuration that necessary for this to work?
Comment #14
vlad.k CreditAttribution: vlad.k commentedI got the ModifiyFeature Control to work. I don't know how to make a patch at the moment, but I'm trying hard, so please be generous.
The last lines in the openlayers_behavior_drawfeatures.js are:
var mcontrol = new OpenLayers.Control.ModifyFeature(data_layer);
data.openlayers.addControl(mcontrol);
but the control doesn't work.
I tried this and it worked for me:
var mcontrol = new OpenLayers.Control.ModifyFeature(data_layer, {
'displayClass': 'olControlModifyFeature'
});
control.addControls(mcontrol);
The control is now added direct to the EditingToolbar (not to the map itself) and with the correct displayClass set, it shows the correct icon.
There is still a little bug though. When the control is selected it doesn't "get yellow" like the other, so there is no visual sign that it has been selected, but it works. I can select features and move them around.
Can you please check this? If anyone has a solution for the bug maybe it can be commited to the module, because I think that most people that draw features on a map also want to have the possibility to change them.
Comment #15
mansspams CreditAttribution: mansspams commentedi am also waiting for this feature. I need this and also possibility to add pop ups with information from views. bravo to marsyas for creative spirit. Maintainers should definitely look into this.
Comment #16
tmcw CreditAttribution: tmcw commentedIf you guys can come up with a patch, then I'm sure that I could find the time to look it over and get it committed quickly. But currently my time on OpenLayers is oriented towards bugs and the core of the module (rather than CCK), so I likely won't have time to write this code soon.
Comment #17
vlad.k CreditAttribution: vlad.k commentedHere's a patch that adds the ModifiyFeature Control to the EditingToolbar of the Openlayers CCK input map. Deleting Features is done with the 'DEL' or 'd' keys. Additionally two styles have to be set. I inserted the style in my theme styles.css:
.olControlEditingToolbar .olControlModifyFeatureItemActive {
background-position: -0px -23px;
}
.olControlEditingToolbar .olControlModifyFeatureItemInactive {
background-position: -0px -0px;
}
Comment #18
tmcw CreditAttribution: tmcw commentedGreat, thanks marsyas! Did a slight reroll of the patch - switching to array literals (
[4, 5]
instead ofnew Array(4, 5)
) and piecing out the CSS into a stylesheet that's included by the behavior. Committed: http://drupal.org/cvs?commit=364190Comment #19
vlad.k CreditAttribution: vlad.k commentedHi tmcw,
I get an JavaScript error. You eliminated the variable that holds a reference to the selected feature (var feature_to_delete = this.feature). this.feature is null after you call this.selectControl.unselectAll(). We need to save the reference to the selected feature before we call unselectAll(). We also need to call unselectAll() before we delete the feature, because we get an JavaScript error if we don't do it. Please look into this again.
Comment #20
tmcw CreditAttribution: tmcw commentedMy bad, I've committed a fix: http://drupalcode.org/viewvc/drupal/contributions/modules/openlayers/inc...
Please test with the latest dev.
Comment #21
vlad.k CreditAttribution: vlad.k commentedYes, this works now, thank you!
Comment #22
tmcw CreditAttribution: tmcw commentedGreat, remarking as fixed.
Comment #24
seanberto CreditAttribution: seanberto commentedApologies if I've missed something in my config, but I can't seem to get this feature working on a CCK field using the most recent Sept 18th dev release. Is there a setting on the CCK field definition page for adding the modify feature?
Comment #25
tmcw CreditAttribution: tmcw commentedPlease open a new issue if there's a continuing problem, but this feature should automatically appear on CCK maps - it's the drag-looking button on the far left.