Not sure if this has been identified yet, but the CCK input widget does not respect the "number of values" settings for fields.

I have not looked to see how you have updated the CCK data storage stuff yet, but the main reason I did it the way I did in 1.x was to be able to easy count the features and replace them as needed.

Comments

tmcw’s picture

Indeed, currently none of the what's-allowed things about the cck module are working. This is mostly because I don't want the OpenLayers module to do any real parsing of WKT. We need to recreate these things on the Javascript end if they're deemed necessary. The CCK editor could also be built out (currently you can't undo or select/delete a feature).

What do you mean by replace the features?

zzolo’s picture

I agree, theres no reason to do any heavy lifting, but I think we should respect the idea of limiting the number of features allowed per field, just like any other CCK field. Also, deleting is very important.

Well, the 1.x version limits the number of features depending on the field setting, and if you reach the max, it simply replaces the last feature with the new one you add. It's hard to say what is the best usability case for this, but I rather think the replacement method is nice.

tmcw’s picture

I think that there are practical reasons to limit the number of features one is able to input, but if we are to do it right, then the field should actually be multiple fields for each feature, or something of that sort - 'proper' multiple entities. 'Faking it' by counting occurrences of text in a text field isn't a good idea.

Also, deleting is very important.

I don't really follow the second part - what is deleting in this context and why is it important?

zzolo’s picture

I tried a lot of different ways of doing it in CCK. The way we have done it in 1.x, I think stores the values properly, but I don't know for sure. But it definitely feels hackish, so any improvement is appreciated.

Deleting is being able to remove a feature from the map (field).

tmcw’s picture

So, I think that the best option here is to prevent users from adding more than n features if the field is limited to that number, and then they either need to undo and redraw a feature (should we have an undo button) or use the draw feature control (which will be in the editing toolbar) to delete other features to fill space.

This will likely need some kind of notification in the UI, like a message under the map. This shouldn't be invisible. I think that this method is more predictable and possibly less destructive than simply removing the previous additions when you add something over the limit.

zzolo’s picture

This sounds good.

If an Undo function is easy to implement I would support it, but if not, I don't think its all that worth it. One can easily hit cancel to not save the changes.

An obvious message is needed. It might be best to put an overlay on the map so that users see it more easily. It could show up when a feature is selected.

vlad.k’s picture

"Well, the 1.x version limits the number of features depending on the field setting, and if you reach the max, it simply replaces the last feature with the new one you add. It's hard to say what is the best usability case for this, but I rather think the replacement method is nice."

This is definitely the best solution if the maximum number of features is one. The aproach described in #5 should only be taken into consideration if the maximum number of features is more then one.

zzolo’s picture

StatusFileSize
new5.02 KB

I have created a basic (not working) patch. It sets everything up to limit features by creating a new paramter to the draw feature behavior. It also translates CCK's multiple to the limit as well.

I am not sure the best way to manage the limit. I would assume in the update function there should be a check and a removal if we are over.

tmcw’s picture

Good to see progress here. I've noticed that we have kind of different commenting styles, which is fine, but please keep the comment transform() modifies geometry in the final patch - it's rather important, since transform is somewhat unexpected in that behavior and it goes a long way toward explaining why that code exists. Saying that it's reprojecting features is also kind of wrong, since it's reprojecting a copy of the features which are never used on the map. I'm more into comments that explain the why than the what of code - like specifying unusual turns in code like transform.

Anonymous’s picture

What is the current status of this patch? It does not appear to be complete, is there any way to currently restrict the number of points (features) users can add? If not how do users delete points? How do users move points?

Use case:
User takes photograph.
User uploads photo to node.
User selects point on map where photograph taken, but gets it wrong on first click.
User wants to move point, so clicks again.... oops... now user has two points.
User tries to manually edit WKT, map doesn't respond.
User cancels node creation and has to start again... ?

What options does the user have when not getting it right first time? Is there a way to edit features that I'm missing?

Thanks!

ddorian’s picture

any progression at this

Sanjo’s picture

Status: Active » Needs work

+1

tmcw’s picture

Status: Needs work » Needs review
StatusFileSize
new9.39 KB

Okay, this is, after all, fairly simple to patch. Here's a patch that rewrites a bunch of the code in drawfeatures, eliminating a bunch of variables and making it a bit more robust. It also removes the function that was put into the window. object by that behavior, and enforces the feature limit.

Please test, thanks.

tmcw’s picture

Status: Needs review » Fixed

Further reviewed, committed: http://drupal.org/cvs?commit=404072

strk’s picture

Status: Fixed » Needs review

function openlayers_behavior_drawfeatures_update(features) {
WktWriter = new OpenLayers.Format.WKT();
if (this.feature_limit < features.object.features.length) {
features.feature.layer.removeFeatures(features.object.features.shift());
}

The code above fails to respect 'unlimited', which I belive would be encoded as this.feature_limit being 0.
Haven't tried, but had problems having unlimited features.

Also, when updating an existing system where many features are added bug having
a limit of 1 each click only drops a single old feature, not all except the new one.

tmcw’s picture

StatusFileSize
new1.31 KB

Indeed - try this patch that fixes both of those things.

strk’s picture

Ok for the first issue (respecting unlimited) as for the second, there seems to be a bigger problem:

features.feature.layer is null

I'll inspect and provide a fix myself

strk’s picture

Status: Needs review » Fixed

Ok, the thing is that the same 'update' function is invoked on both 'featureadded' and 'featureremoved', with the latter being triggered by the former on removeFeature. The call on 'featureremoved' seems to lack the 'layer' attribute for some reason (a bug in OL?).

Anyway the double invocation doesn't seem to be nice to have. And in any case we only want to perform
the removal on 'featureadded'. Committed:

http://drupal.org/cvs?commit=404270

strk’s picture

Status: Fixed » Needs review

tmwc: what's the point of performing these check on each iteration?
features.type == 'featureadded' && this.feature_limit

They only need to be performed once, which my patch did...
I'm referring to
http://drupalcode.org/viewvc/drupal/contributions/modules/openlayers/inc...

tmcw’s picture

Didn't seem to make sense as a performance optimization, given that the loop runs, in most cases, once per call. The only case in which it actually iterates is when somebody has created a lot of points and now wants them deleted, and even in that case, it only iterates through the points once. So, yeah, the performance hit - which is likely microscopic, given that there's no scoping problem and it's just testing equality - doesn't seem worth the extra control statement.

tmcw’s picture

Status: Needs review » Fixed

Okay? Remarking as fixed..

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.