Reviewed & tested by the community
Project:
Openlayers
Version:
7.x-2.x-dev
Component:
OL Behaviors
Priority:
Normal
Category:
Feature request
Assigned:
Issue tags:
Reporter:
Created:
5 Apr 2012 at 17:56 UTC
Updated:
19 Feb 2016 at 00:58 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
daattaa commenteddisregard this question, you can change the popup code inorder to get this to work.
Comment #2
kloewer commentedAdded this snippet to:
/openlayers/plugins/behaviors/openlayers_behavior_popup.jsIs there a more drupal-like way?
Comment #3
naught101 commentedSeems like this should be it's own feature, not a hack.
Comment #4
polIndeed, this is something to do.
Comment #5
naught101 commentedI 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?
Comment #6
polThere is already a Zoom To Layer behavior in OL, it doesn't work for you ?
Comment #7
naught101 commentedNo, 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.
Comment #8
polSorry 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.
Comment #9
naught101 commentedSay 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...
Comment #10
polOk 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.
Comment #11
naught101 commentedPatch attached, with comments in code.
I think though, that this might be better off as a separate behaviour.
Comment #12
naught101 commentedTry 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...
Comment #13
naught101 commentedComment #14
polExcellent, I just tested it and it works pretty good ! This goes in, thank you very much !
Comment #15
naught101 commentedWhoa, 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...
Comment #16
polHello 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!
Comment #17
naught101 commentedHere's the start of a patch for a separate behaviour.
Problems:
Comment #18
naught101 commentedSo, 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.
Comment #19
acbramley commentedGreat 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
Comment #20
acbramley commentedThis 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?)
Comment #21
acbramley commentedEven better, this splits the setting between clusters and points so you can enable them individually.
Comment #22
naught101 commentedThe best I have is:
(feature.geometry.CLASS_NAME==="OpenLayers.Feature.MultiPolygon" || feature.geometry.CLASS_NAME==="OpenLayers.Feature.Polygon")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... :/
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...
Comment #23
acbramley commentedOk 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).
Comment #24
naught101 commentedMaybe just leave the zoom out feature off entirely.
Comment #25
acbramley commentedYeah I'm fine with that as it's not something I need or can see a huge use case for
Comment #26
acbramley commentedI'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.
Comment #27
polGreat stuff :-)
Committed ! Thank you very much !!!
Comment #29
acbramley commentedLooks like we have a solution, will post modified patch
Comment #30
acbramley commentedAnd 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
Comment #32
polAny update on this one before the next beta ?
Comment #33
basvredelingI'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.
Comment #34
polOkay, I'll wait a bit for the next beta then.
Comment #35
Zombocom123 commentedHello,
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?
Comment #36
basvredeling@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?
Comment #38
basvredelingI'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
Comment #39
basvredelingThis 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.
Comment #40
basvredeling