Comments

daattaa’s picture

Status: Active » Closed (works as designed)

disregard this question, you can change the popup code inorder to get this to work.

        onSelect: function(feature) {
      	if(feature.cluster.length > 1){
	        	//zoom max
	        	zoom = 15;
	        	map.zoomTo(parseFloat(zoom));
                map.setCenter(feature.geometry.getBounds().getCenterLonLat());
                map.moveByPx(parseFloat(options.offset_x), parseFloat(options.offset_y));
                
	        }else{
                        // do what you would normaly do
                }
 
kloewer’s picture

Added this snippet to:

/openlayers/plugins/behaviors/openlayers_behavior_popup.js

Is there a more drupal-like way?

naught101’s picture

Status: Closed (works as designed) » Active

Seems like this should be it's own feature, not a hack.

pol’s picture

Component: OL API » OL Behaviors
Category: support » task

Indeed, this is something to do.

naught101’s picture

I cam across this because I'm actually interested in a zoom-to-feature feature (e.g. for zooming to states from a country view). Would this be the same behaviour, or should I open a separate issue?

pol’s picture

There is already a Zoom To Layer behavior in OL, it doesn't work for you ?

naught101’s picture

No, I don't have a Zoom to Feature behaviour at all (2.x, git, just pulled). I have a "zoom to layer" behaviour, which zooms to a layer on map load, but what I mean is a zoom-to-feature-on-click, after the map is loaded.

pol’s picture

Sorry my bad, I meant "Zoom to layer" behavior which should calculated the maxExtend of the features and zoom accordingly.

What do you mean by "zoom-to-feature-on-click" ? Can you describe it ?

Maybe another issue would be better.

naught101’s picture

Say you have a map of the United States, with each state drawn as a polygon. I would like to be able to click on a state, and zoom in to the that state.

I think this could be the basically the same code as zoom to cluster, just with a different bounding box, although I'm not familiar enough with OL to be able to see if the above snippet actually gets a bounding box for the cluster...

pol’s picture

Ok I understand now.

I think the code in #1 would do the trick.

What you can do is create a new option in the behavior, then in the corresponding JS, take in account with a condition based on the option you added, the code in #1.

If you provide a patch, I would probably include it in OL for the next beta.

naught101’s picture

Status: Active » Needs work
StatusFileSize
new2.66 KB

Patch attached, with comments in code.

I think though, that this might be better off as a separate behaviour.

naught101’s picture

StatusFileSize
new2.65 KB

Try this, previous wasn't zooming out. This still isn't zooming out fully. It appears to zoom out to the layer extent, but one zoom level too close, so parts of the layer are cut off...

naught101’s picture

Status: Needs work » Needs review
pol’s picture

Status: Needs review » Fixed

Excellent, I just tested it and it works pretty good ! This goes in, thank you very much !

naught101’s picture

Whoa, that was a pretty half-arsed patch, are you sure you want to leave that in with all those dodgy comments? As stated in my previous comment, the zoom out isn't quite working correctly (it should work the same as the zoom-to-layer behaviour does). Also, this will zoom to points, I assume to the maximum zoom level, which may not be the desired behaviour...

pol’s picture

Status: Fixed » Active

Hello there,

I know, but JS is absolutely not my cup of tea and any help is greatly welcome :-)

If you have some ideas on how to improve the behavior, come one, let's do it together!

naught101’s picture

StatusFileSize
new3.64 KB

Here's the start of a patch for a separate behaviour.

Problems:

  • Doesn't zoom out properly (appears to just zoom out a couple of steps from the feature)
  • Seems to be blocking the popup behaviour.
  • Probably zooms in on points too, I haven't checked. This is probably not the preferred behaviour?
naught101’s picture

So, as far as I can tell, open layers doesn't allow multiple behaviours on select. You have to do it all in the same behaviour. Which basically means that if you want them to play together, every act-on-select behaviour has to be lumped into one, unless there is some kind of meta-behaviour that runs the functions defined by the other behaviours. Perhaps, for now, it makes sense to just include this in the pop-up behaviour, and that behaviour could be changed to a meta "on-select" behaviour that has popup, zoom, etc. as options later on.

For now, I will go back to the original patch, and try to get the zoom-out working.

acbramley’s picture

Great to see this is being worked on as I want something similar. What I'm wanting is to be able to zoom to clusters on click, but still get the popups for the individual features. Is it possible to extend the patch to add another option with something like "Only zoom to clusters, popup for features" I imagine this could be quite a common use case.

EDIT: This could easily be another behavior I realise, and is probably better as one. Right now there are errors with the patch #12 as it zooms to a single point when clicking a cluster and presents JS errors as it still tries to popup the cluster

Uncaught TypeError: Cannot read property 'drupalID' of null line 134 openlayers_behavior_cluster.js
acbramley’s picture

StatusFileSize
new3.01 KB

This patch only zooms to clusters and correctly calculates the extent of the cluster so all points are shown instead of zooming to one point which completely defeats the purpose of being able to zoom to a cluster! It also returns after zooming on click to avoid the popup js error (why should we popup after zooming anyway?)

acbramley’s picture

Status: Active » Needs review
StatusFileSize
new4.06 KB

Even better, this splits the setting between clusters and points so you can enable them individually.

naught101’s picture

Status: Needs review » Needs work
+++ b/plugins/behaviors/openlayers_behavior_popup.js
@@ -60,6 +60,30 @@ Drupal.openlayers.addBehavior('openlayers_behavior_popup', function (data, optio
+        // but I'm not sure how to check for polygon.

The best I have is:
(feature.geometry.CLASS_NAME==="OpenLayers.Feature.MultiPolygon" || feature.geometry.CLASS_NAME==="OpenLayers.Feature.Polygon")

+++ b/plugins/behaviors/openlayers_behavior_popup.js
@@ -60,6 +60,30 @@ Drupal.openlayers.addBehavior('openlayers_behavior_popup', function (data, optio
+            // Don't pop up once we are zoomed.

This probably isn't suitable for polygons, where I think pop-up should happen on zoom.

Also, this is where the feature name starts to become inappropriate - you're not popping-up on a pop-up behaviour... :/

+++ b/plugins/behaviors/openlayers_behavior_popup.js
@@ -85,6 +109,13 @@ Drupal.openlayers.addBehavior('openlayers_behavior_popup', function (data, optio
+          // best behaviour here. This doesn't currently work, because there's
+          // no situation where a feature is unselected except when another is,
+          // and it just zooms to the next feature.

This is wrong (my fault) features are unselected when part of the map with no features is clicked. But the zoom out method is still wrong. Also, the zoom-back-out feature is probably better if it's optional (although that means that there are going to be a LOT of options in the popup behaviour...

acbramley’s picture

Ok cheers, all of that is stuff hanging over from the original patch. I was confused by the unselect() function for zooming into clusters as how do you unselect that? I found it a bit buggy when I was doing multiple zooms into clusters, any advice would be helpful as I need this functionality for my current project so am happy to spend time on getting it working nicely.

With regards to the multiple behaviour thing, I understand that and it grinds me a bit seeing zoom keywords in a popup behaviour but it was mentioned earlier that 2 separate behaviours will conflict so it will not be possible to have zoom AND popup on click (i.e for my use case popup on points, zoom on clusters).

naught101’s picture

Maybe just leave the zoom out feature off entirely.

acbramley’s picture

Yeah I'm fine with that as it's not something I need or can see a huge use case for

acbramley’s picture

Status: Needs work » Needs review
StatusFileSize
new4.24 KB

I've removed the unselect zoom out code and instead wrapped the popup removal code in a conditional to stop the error where a feature that had been zoomed to did not have a popup.

I've also added better conditions to the zooming code to fix some bugs with different combinations of settings than I had, along with adding better comments.

pol’s picture

Status: Needs review » Fixed

Great stuff :-)

Committed ! Thank you very much !!!

Status: Fixed » Closed (fixed)

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

acbramley’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs work

Looks like we have a solution, will post modified patch

From "openlayers_behavior_popup.js":
Original version:

// Check if we have any zoom settings set. If zoom to point is enabled,
// it will disable the popup behavior for points,
// and the same for clusters.
if (options.zoomToPoint || options.zoomToCluster) {
var fullExtent;
// If we have zoomToCluster enabled and the feature is a cluster,
// accumulate the fullExtent of all points in the cluster.
var isCluster = typeof feature.cluster != 'undefined' && feature.cluster.length > 1;
if (options.zoomToCluster && isCluster) {
for (var i = 0; i < feature.cluster.length; i++) {
point = feature.cluster[i];
if (fullExtent instanceof OpenLayers.Bounds) {
fullExtent.extend(point.geometry.getBounds());
} else {
fullExtent = point.geometry.getBounds();
}
}
}
// Otherwise, if zoomToPoint is enabled and it's not a cluster, set
// the fullExtent to the bounds of the point.
else if (options.zoomToPoint && !isCluster){
fullExtent = feature.geometry.getBounds();
}

Corrected version (with the correction in bold):

// Check if we have any zoom settings set. If zoom to point is enabled,
// it will disable the popup behavior for points,
// and the same for clusters.
if (options.zoomToPoint || options.zoomToCluster) {
var fullExtent;
// If we have zoomToCluster enabled and the feature is a cluster,
// accumulate the fullExtent of all points in the cluster.
var isCluster = typeof feature.cluster != 'undefined' && feature.cluster.length > 1;
if (options.zoomToCluster && isCluster) {
for (var i = 0; i < feature.cluster.length; i++) {
point = feature.cluster[i];
if (fullExtent instanceof OpenLayers.Bounds) {
fullExtent.extend(point.geometry.getBounds());
} else {
fullExtent = feature.geometry.getBounds();
}
}
}
// Otherwise, if zoomToPoint is enabled and it's not a cluster, set
// the fullExtent to the bounds of the point.
else if (options.zoomToPoint && !isCluster){
fullExtent = feature.geometry.getBounds();
}
So now every marker will go back to its original places after they become not part of a cluster! :)
acbramley’s picture

Assigned: Unassigned » acbramley
Category: Task » Feature request
Status: Needs work » Needs review
StatusFileSize
new3.86 KB

And here's the patch (rolled against 7.x-2.x, I haven't got an instance to test this and I'm quite busy so would be greatly appreciative if someone could test this and let me know if it works :)

Cheers

  • Pol committed 6412b43 on 7.x-3.1.x
    Issue #1516758 by acbramley | daattaa: 2.X: Zoom to cluster.
    
  • Pol committed 847114a on 7.x-3.1.x
    Revert "Issue #1516758: 2.X: Zoom to cluster."
    
    Don't be so hasty...
  • Pol committed bc084e0 on 7.x-3.1.x authored by naught101
    Issue #1516758: 2.X: Zoom to cluster.
    
pol’s picture

Any update on this one before the next beta ?

basvredeling’s picture

Status: Needs review » Needs work

I've tested it... zoom to cluster works (but zoom to point doesn't). Also, on my current project the patch didn't apply cleanly (probably line numbers changed) but on my d7 dev stack it did (weirdly enough, it's exactly the same version). The patch needs a bit of work still.

I'm working on a patch for identical behavior in the olfp behavior.

pol’s picture

Okay, I'll wait a bit for the next beta then.

Zombocom123’s picture

Hello,
I'm using this patch on a map with clustering activated and there are some points with exactly the same coordinates.
In this case at maximum zoom it will try to zoom further on a cluster rather than show the nodes list when clicking, i think this is not how it should work, in particular in the case of clusters that are still shown when at max zoom.
I suggest to make it so that if you are at max zoom then clicking on a cluster or a point will show the normal popup instead of trying to zoom furhter.

There is a very simple way to achieve that by changing line 89 (after applying the last patch) of "openlayers_behavior_popup.js":

if ((options.zoomToPoint || options.zoomToCluster) && map.getZoom()<17) {

but that 17 is too "dirty", how do you get the max zoom available for a map in Openlayers?

basvredeling’s picture

@valepu: On maxZoom, you could implement something like this: http://gis.stackexchange.com/questions/15436/google-markers-at-same-addr...
, where the markers are expanded along a circle to make them all visible. See the images in the second answer.

BTW, why don't we just implement the zoom to cluster behavior right now, and leave the zoom to point for another issue?

  • Pol committed 6412b43 on 7.x-3.x
    Issue #1516758 by acbramley | daattaa: 2.X: Zoom to cluster.
    
  • Pol committed 847114a on 7.x-3.x
    Revert "Issue #1516758: 2.X: Zoom to cluster."
    
    Don't be so hasty...
  • Pol committed bc084e0 on 7.x-3.x authored by naught101
    Issue #1516758: 2.X: Zoom to cluster.
    
basvredeling’s picture

Issue summary: View changes
Status: Needs work » Reviewed & tested by the community

I've retested the patch from #30 again on a different client site. And there it works just fine. So I went back to another test-setup. And I could not reproduce my earlier findings from #33 there either. So, both zoom to cluster and zoom to point work. This patch still needs to go into 2.x

basvredeling’s picture

Issue tags: +7.x-2.0 blocker

This patch still applies and is ready to be committed.
As part of #2670484: Stable 7.x-2.0 release tagging this to be evaluated for 7.x-2.0 release.

basvredeling’s picture