Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
OpenLayers 3 Wrapper for Vaadin
Ah ok. Bother; that probably restricts my ability to do it myself quickly.
Matti,
I am using MapCache to render map using OL3 addon but for some reason it fails. I believe this is due to no option available for setting "resolutions" in OLView. Rendering a map for just a city will have very small resolutions and the way OpenLayer3 calculates minResolution when "resolutions" are not provided is not accurate. It returns minResolution as NaN from "ol.View.createResolutionConstraint" function. This causes map to not render. Please let me know if you have plan to add option "resolutions" in OLView.
Hey Matti,
Is there a listener available for signalling the new view port when a map is zoomed/panned in the browser?
I couldn't find anything obvious. Did I miss it, or is that for furture implementation?
Cheers,
Joe
Anant Jagania: Matti,
I am using MapCache to render map using OL3 addon but for some reason it fails. I believe this is due to no option available for setting "resolutions" in OLView. Rendering a map for just a city will have very small resolutions and the way OpenLayer3 calculates minResolution when "resolutions" are not provided is not accurate. It returns minResolution as NaN from "ol.View.createResolutionConstraint" function. This causes map to not render. Please let me know if you have plan to add option "resolutions" in OLView.
Thank you for your message. Should be quite easy to add this option to the add-on. I'll add a ticket to myself. The option will most likely be available in the next release. Thank you for bringing the problem up.
-Matti
Josef Karthauser: Hey Matti,
Is there a listener available for signalling the new view port when a map is zoomed/panned in the browser?
I couldn't find anything obvious. Did I miss it, or is that for furture implementation?Cheers,
Joe
Hello Joe,
Please check whether OLView.addViewChangeListener provides the information you need.
Regards,
Matti
Very strange - I appeared to be using version 0.1.2 - which of course is why I didn't see that! (I think I started from the demo, which appears to be using a very old version! Might be work updating that so that others don't follow in my footsteps! :)
Cheers,
Joe
I've switched to version 1.0; but I'm getting a missing dependency error:
[ERROR] java.lang.RuntimeException: java.lang.NoClassDefFoundError: Unable to load class org.vaadin.addon.vol3.OLMap due to missing dependency Ljavafx/scene/control/ContextMenu;
Which artifact version should I be including? (I've got no practical experience of javafx).
Cheers,
Joe
There is a little typo in the File getFeatureInfoOptions.java in the current GitHub master:
[ERROR] /home/me/Programmierung/Java/v-ol3/gwt-ol3/src/main/java/org/vaadin/gwtol3/client/source/getFeatureInfoOptions.java:[8,8] class GetFeatureInfoOptions is public, should be declared in a file named GetFeatureInfoOptions.java
Regards, Wolf
Matti Hosio:
Anant Jagania: Matti,
I am using MapCache to render map using OL3 addon but for some reason it fails. I believe this is due to no option available for setting "resolutions" in OLView. Rendering a map for just a city will have very small resolutions and the way OpenLayer3 calculates minResolution when "resolutions" are not provided is not accurate. It returns minResolution as NaN from "ol.View.createResolutionConstraint" function. This causes map to not render. Please let me know if you have plan to add option "resolutions" in OLView.
Thank you for your message. Should be quite easy to add this option to the add-on. I'll add a ticket to myself. The option will most likely be available in the next release. Thank you for bringing the problem up.
-Matti
The feature is now available in the version 1.0.1
Wolf Michna: There is a little typo in the File getFeatureInfoOptions.java in the current GitHub master:
[ERROR] /home/me/Programmierung/Java/v-ol3/gwt-ol3/src/main/java/org/vaadin/gwtol3/client/source/getFeatureInfoOptions.java:[8,8] class GetFeatureInfoOptions is public, should be declared in a file named GetFeatureInfoOptions.java
Regards, Wolf
Thank you for pointing this out Wolf! Git was messing with me with the uppercase thing. Should be fixed now.
Cheers,
Matti
Josef Karthauser: I've switched to version 1.0; but I'm getting a missing dependency error:
[ERROR] java.lang.RuntimeException: java.lang.NoClassDefFoundError: Unable to load class org.vaadin.addon.vol3.OLMap due to missing dependency Ljavafx/scene/control/ContextMenu;
Which artifact version should I be including? (I've got no practical experience of javafx).
Cheers,
Joe
Hello Josef,
That was actually a bug in the add-on. There shouldn't be any references to javafx. The ContextMenu dependency that should be there is the context menu add-on by Peter Lehto in the vaadin directory. The bug is now fixed in the 1.0.1 version.
Thanks for reporting this,
Matti
Matti Hosio:
Josef Karthauser: I've switched to version 1.0; but I'm getting a missing dependency error:
[ERROR] java.lang.RuntimeException: java.lang.NoClassDefFoundError: Unable to load class org.vaadin.addon.vol3.OLMap due to missing dependency Ljavafx/scene/control/ContextMenu;
Which artifact version should I be including? (I've got no practical experience of javafx).
Cheers,
JoeHello Josef,
That was actually a bug in the add-on. There shouldn't be any references to javafx. The ContextMenu dependency that should be there is the context menu add-on by Peter Lehto in the vaadin directory. The bug is now fixed in the 1.0.1 version.
Thanks for reporting this,
Matti
That's great new Matti. Thanks! I thought it was a bug in my groovy compiler maven rules... been really pulling my hair out over it! (I like bugs that fix themselves! ;)
Thanks,
Joe
Matti Hosio:
Matti Hosio:
Anant Jagania: Matti,
I am using MapCache to render map using OL3 addon but for some reason it fails. I believe this is due to no option available for setting "resolutions" in OLView. Rendering a map for just a city will have very small resolutions and the way OpenLayer3 calculates minResolution when "resolutions" are not provided is not accurate. It returns minResolution as NaN from "ol.View.createResolutionConstraint" function. This causes map to not render. Please let me know if you have plan to add option "resolutions" in OLView.
Thank you for your message. Should be quite easy to add this option to the add-on. I'll add a ticket to myself. The option will most likely be available in the next release. Thank you for bringing the problem up.
-Matti
The feature is now available in the version 1.0.1
Thanks Matti,
Its working fine now. Just a minor suggestion is "setter" method should return "this" for consistancy.
Hi Matti,
the examples in the test branch are very helpful.
Is there an easy to use method to transform coordinates from MapProjection to InputProjection?
Best regards, Wolf
Matti,
ZoomControl and ZoomSliderControl are never added on the map. I also tried the ol3-demo Map and was not able to see zoom controls on it. Is there something missing from JavaScript?
Anant Jagania:
Matti Hosio:
Matti Hosio:
Anant Jagania: Matti,
I am using MapCache to render map using OL3 addon but for some reason it fails. I believe this is due to no option available for setting "resolutions" in OLView. Rendering a map for just a city will have very small resolutions and the way OpenLayer3 calculates minResolution when "resolutions" are not provided is not accurate. It returns minResolution as NaN from "ol.View.createResolutionConstraint" function. This causes map to not render. Please let me know if you have plan to add option "resolutions" in OLView.
Thank you for your message. Should be quite easy to add this option to the add-on. I'll add a ticket to myself. The option will most likely be available in the next release. Thank you for bringing the problem up.
-Matti
The feature is now available in the version 1.0.1
Thanks Matti,
Its working fine now. Just a minor suggestion is "setter" method should return "this" for consistancy.
In deed. Fixed now in the master branch. Will be included in the next release.
Thanks,
Matti
Wolf Michna: Hi Matti,
the examples in the test branch are very helpful.
Is there an easy to use method to transform coordinates from MapProjection to InputProjection?
Best regards, Wolf
The add-on does not provide server side api for coordinate manipulation. The main reason for this is that I try to keep the add-on dependencies at the very minimum. Instead I suggest you use some third party library such as Proj4J (http://trac.osgeo.org/proj4j/) for the conversion.
Best regards,
Matti
Anant Jagania: Matti,
ZoomControl and ZoomSliderControl are never added on the map. I also tried the ol3-demo Map and was not able to see zoom controls on it. Is there something missing from JavaScript?
Please elaborate a bit more. The online demo has the zoom control (+/-) buttons (not the slider though since that is not used in the demo). See: http://hosio.app.fi/ol3-demo/
Also the latest release has a test case for booth zoom types and I see them in my browser. Which browser are you using? Any sample code that fails to display the controls for you?
Cheers,
Matti
Matti Hosio:
Anant Jagania: Matti,
ZoomControl and ZoomSliderControl are never added on the map. I also tried the ol3-demo Map and was not able to see zoom controls on it. Is there something missing from JavaScript?
Please elaborate a bit more. The online demo has the zoom control (+/-) buttons (not the slider though since that is not used in the demo). See: http://hosio.app.fi/ol3-demo/
Also the latest release has a test case for booth zoom types and I see them in my browser. Which browser are you using? Any sample code that fails to display the controls for you?
Cheers,
Matti
I use chrome. The problem is OLMap.ClickListener. If you do not add any click listeners to Map then zoom controls will not be loaded. Remove context menu and click listeners from BasicMap in test and map control will not be added.
This is due to removeOnClickListener in Map.java (org.vaadin.gwtol3.client). This method is called while loading the Map for first time and if there is no click listener added then Map javascript object doesn't have property "__clickListeners" and removeOnClickListener fails. It would be benefitial if we added check if "__clickListeners" exists or not in removeOnClickListener.
Matti Hosio:
Jose Luis: Hi all,
I'm trying to change the feature icon using a style without succeding, the blue circle keeps showing up.
Can anyone tell me what I do wrong?.... OLFeature feature = new OLFeature(id); OLStyle style = StyleUtils.createDefaultStyle(); style.iconStyle = new OLIconStyle(); style.iconStyle.size = new double {32.0, 32.0}; style.iconStyle.src = "vaadin://img/Logo_Chrome.png"; //style.iconStyle.src = "http://icons.iconarchive.com/icons/appicns/simplified-app/256/appicns-Chrome-icon.png"; feature.setStyle(style); feature.setGeometry(geometry); ...
Thanks in advance
Hello Jose,
Something like this works for me:
OLStyle style= new OLStyle();
style.iconStyle=new OLIconStyle();
style.iconStyle.size=new double{32.0,32.0};
style.iconStyle.src = "VAADIN/img/flag.png";
pointFeature.setStyle(style);The problem in your solution is probably that the default style includes something that makes the ol3 draw the circle instead of the icon. Also please check the src param for the icon.
Regards,
Matti
Thanks for your reply Matti, it works propertly using your code.
Now i'm facing another problem when hiding the openlayer logo by calling the following method:
...
mapOptions.setShowOl3Logo(false);
...
It makes no effect at all.
I managed to hide it with CSS like this, but I don't think it is the best way
.ol-attribution.ol-logo-only {
visibility: hidden;
}
Thanks in advance
Hi Matti,
thank you for your help so far.
I am looking for the "marker layer functionality" - icon + html popup, realized in OpenLayers3 with vector layer and features and popover. An example or hint would be very helpful.
Regards,
Wolf
Anant Jagania:
Matti Hosio:
Anant Jagania: Matti,
ZoomControl and ZoomSliderControl are never added on the map. I also tried the ol3-demo Map and was not able to see zoom controls on it. Is there something missing from JavaScript?
Please elaborate a bit more. The online demo has the zoom control (+/-) buttons (not the slider though since that is not used in the demo). See: http://hosio.app.fi/ol3-demo/
Also the latest release has a test case for booth zoom types and I see them in my browser. Which browser are you using? Any sample code that fails to display the controls for you?
Cheers,
Matti
I use chrome. The problem is OLMap.ClickListener. If you do not add any click listeners to Map then zoom controls will not be loaded. Remove context menu and click listeners from BasicMap in test and map control will not be added.
This is due to removeOnClickListener in Map.java (org.vaadin.gwtol3.client). This method is called while loading the Map for first time and if there is no click listener added then Map javascript object doesn't have property "__clickListeners" and removeOnClickListener fails. It would be benefitial if we added check if "__clickListeners" exists or not in removeOnClickListener.
You are right! Thank you for spotting the bug. Fixed now in the master branch and will be released in the next version (today).
https://github.com/VOL3/v-ol3/issues/53
Cheers,
Matti
Wolf Michna: Hi Matti,
thank you for your help so far.
I am looking for the "marker layer functionality" - icon + html popup, realized in OpenLayers3 with vector layer and features and popover. An example or hint would be very helpful.
Regards,
Wolf
Hello Wolf,
There is not really advanced features to implement things like that but I added today the basic support. Please have a look at
https://github.com/VOL3/v-ol3/blob/master/v-ol3/src/test/java/org/vaadin/addon/vol3/demoandtestapp/IconFeatureMap.java
And upgrade to the latest version of the add-on.
Cheers,
Matti
Wolf Michna: Hi Matti,
thank you for your help so far.
I am looking for the "marker layer functionality" - icon + html popup, realized in OpenLayers3 with vector layer and features and popover. An example or hint would be very helpful.
Regards,
Wolf
Hello Wolf,
With the latest version, you can display basic html popovers (overlays) on specified map coordinates. Combine that with map click listeners or feature selection listeners (OLSelectInteraction) and you should be good to go. Basic example available in
https://github.com/VOL3/v-ol3/blob/master/v-ol3/src/test/java/org/vaadin/addon/vol3/demoandtestapp/IconFeatureMap.java
The limitation is that the popovers contain only raw html. Unfortunately no Vaadin components supported in there.
Cheers,
Matti
Jose Luis:
Matti Hosio:
Jose Luis: Hi all,
I'm trying to change the feature icon using a style without succeding, the blue circle keeps showing up.
Can anyone tell me what I do wrong?.... OLFeature feature = new OLFeature(id); OLStyle style = StyleUtils.createDefaultStyle(); style.iconStyle = new OLIconStyle(); style.iconStyle.size = new double {32.0, 32.0}; style.iconStyle.src = "vaadin://img/Logo_Chrome.png"; //style.iconStyle.src = "http://icons.iconarchive.com/icons/appicns/simplified-app/256/appicns-Chrome-icon.png"; feature.setStyle(style); feature.setGeometry(geometry); ...
Thanks in advance
Hello Jose,
Something like this works for me:
OLStyle style= new OLStyle();
style.iconStyle=new OLIconStyle();
style.iconStyle.size=new double{32.0,32.0};
style.iconStyle.src = "VAADIN/img/flag.png";
pointFeature.setStyle(style);The problem in your solution is probably that the default style includes something that makes the ol3 draw the circle instead of the icon. Also please check the src param for the icon.
Regards,
Matti
Thanks for your reply Matti, it works propertly using your code.
Now i'm facing another problem when hiding the openlayer logo by calling the following method:
... mapOptions.setShowOl3Logo(false); ...
It makes no effect at all.
I managed to hide it with CSS like this, but I don't think it is the best way.ol-attribution.ol-logo-only { visibility: hidden; }
Thanks in advance
Should be fixed now in the latest version. Thanks for the bug report, Jose.
Regards,
Matti
Matti Hosio:
Wolf Michna: Hi Matti,
thank you for your help so far.
I am looking for the "marker layer functionality" - icon + html popup, realized in OpenLayers3 with vector layer and features and popover. An example or hint would be very helpful.
Regards,
WolfHello Wolf,
There is not really advanced features to implement things like that but I added today the basic support. Please have a look at
https://github.com/VOL3/v-ol3/blob/master/v-ol3/src/test/java/org/vaadin/addon/vol3/demoandtestapp/IconFeatureMap.java
And upgrade to the latest version of the add-on.
Cheers,
Matti
Hello Matti,
thank you, this is a very good basic solution!
Cheers,
Wolf
Hi Matti,
Sorry if this is a trivial question; I'm struggling to work out how to set the centre of the view to a Wgs84 coordinate. I'm not sure what the default coordinate system is that's underlying the map, nor how to map Wgs84 coords into it.
Is this easy?
Thanks,
Joe
Hi Matti,
Current way of initializing map in OLMapConnector makes it hard for creating Map extension. This is due to client Map is created only when ConnectorHierarchy is changed. e.g. Adding some overlay like OverviewMap in the map extension. Map is not initialized (until ConnectorHierarchy is changed) and adding any control to Map fails. I suggest to initialize the client map during connector initialization.
@Connect(MapExtension.class)
public class MapExtensionConnector extends AbstractExtensionConnector {
@Override protected void extend(ServerConnector target) {
OLMapConnector olMapConnector = (OLMapConnector)target;
final MapWidget widget = olMapConnector.getWidget();
// Approach 1: Fails with Javascript errors of map being undefined
Map map = widget.getMap();
map.addControl(OverviewMap.create(extent, URL, layer));
// Approach 2: No Javascript error but overviewmap shows nothing but DIV element, no map
olMapConnector.addConnectorHierarchyChangeHandler(new ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler() {
public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) {
Map map = widget.getMap();
map.addControl(OverviewMap.create(extent, URL, layer));
}
});
}
}
Josef Karthauser: Hi Matti,
Sorry if this is a trivial question; I'm struggling to work out how to set the centre of the view to a Wgs84 coordinate. I'm not sure what the default coordinate system is that's underlying the map, nor how to map Wgs84 coords into it.
Is this easy?
Thanks,
Joe
Hello Josef,
Try to create your view like this:
OLViewOptions opts=new OLViewOptions();
opts.setInputProjection(Projections.EPSG4326);
OLView view=new OLView(opts);
Cheers,
Matti
Anant Jagania: Hi Matti,
Current way of initializing map in OLMapConnector makes it hard for creating Map extension. This is due to client Map is created only when ConnectorHierarchy is changed. e.g. Adding some overlay like OverviewMap in the map extension. Map is not initialized (until ConnectorHierarchy is changed) and adding any control to Map fails. I suggest to initialize the client map during connector initialization.
@Connect(MapExtension.class) public class MapExtensionConnector extends AbstractExtensionConnector { @Override protected void extend(ServerConnector target) { OLMapConnector olMapConnector = (OLMapConnector)target; final MapWidget widget = olMapConnector.getWidget(); // Approach 1: Fails with Javascript errors of map being undefined Map map = widget.getMap(); map.addControl(OverviewMap.create(extent, URL, layer)); // Approach 2: No Javascript error but overviewmap shows nothing but DIV element, no map olMapConnector.addConnectorHierarchyChangeHandler(new ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler() { public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { Map map = widget.getMap(); map.addControl(OverviewMap.create(extent, URL, layer)); } }); } }
Hello Anant,
The reason I defer the map initialization to connectionhierarchy change is that the state information is not available in the connector init. But I could add an initialization hook to the connector to make extending the wrapper a bit easier. I don't see directly why the Approach 2 would fail though.
-Matti
Matti Hosio:
Anant Jagania: Hi Matti,
Current way of initializing map in OLMapConnector makes it hard for creating Map extension. This is due to client Map is created only when ConnectorHierarchy is changed. e.g. Adding some overlay like OverviewMap in the map extension. Map is not initialized (until ConnectorHierarchy is changed) and adding any control to Map fails. I suggest to initialize the client map during connector initialization.
@Connect(MapExtension.class) public class MapExtensionConnector extends AbstractExtensionConnector { @Override protected void extend(ServerConnector target) { OLMapConnector olMapConnector = (OLMapConnector)target; final MapWidget widget = olMapConnector.getWidget(); // Approach 1: Fails with Javascript errors of map being undefined Map map = widget.getMap(); map.addControl(OverviewMap.create(extent, URL, layer)); // Approach 2: No Javascript error but overviewmap shows nothing but DIV element, no map olMapConnector.addConnectorHierarchyChangeHandler(new ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler() { public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { Map map = widget.getMap(); map.addControl(OverviewMap.create(extent, URL, layer)); } }); } }
Hello Anant,
The reason I defer the map initialization to connectionhierarchy change is that the state information is not available in the connector init. But I could add an initialization hook to the connector to make extending the wrapper a bit easier. I don't see directly why the Approach 2 would fail though.
-Matti
Does your overview map work if added to the map afterwards? I mean attaching the extension in response to a button click for instance?
-Matti
Matti Hosio:
Matti Hosio:
Anant Jagania: Hi Matti,
Current way of initializing map in OLMapConnector makes it hard for creating Map extension. This is due to client Map is created only when ConnectorHierarchy is changed. e.g. Adding some overlay like OverviewMap in the map extension. Map is not initialized (until ConnectorHierarchy is changed) and adding any control to Map fails. I suggest to initialize the client map during connector initialization.
@Connect(MapExtension.class) public class MapExtensionConnector extends AbstractExtensionConnector { @Override protected void extend(ServerConnector target) { OLMapConnector olMapConnector = (OLMapConnector)target; final MapWidget widget = olMapConnector.getWidget(); // Approach 1: Fails with Javascript errors of map being undefined Map map = widget.getMap(); map.addControl(OverviewMap.create(extent, URL, layer)); // Approach 2: No Javascript error but overviewmap shows nothing but DIV element, no map olMapConnector.addConnectorHierarchyChangeHandler(new ConnectorHierarchyChangeEvent.ConnectorHierarchyChangeHandler() { public void onConnectorHierarchyChange(ConnectorHierarchyChangeEvent connectorHierarchyChangeEvent) { Map map = widget.getMap(); map.addControl(OverviewMap.create(extent, URL, layer)); } }); } }
Hello Anant,
The reason I defer the map initialization to connectionhierarchy change is that the state information is not available in the connector init. But I could add an initialization hook to the connector to make extending the wrapper a bit easier. I don't see directly why the Approach 2 would fail though.
-Matti
Does your overview map work if added to the map afterwards? I mean attaching the extension in response to a button click for instance?
-Matti
Anyway, I added the initalization hook. Feel free to try version 1.0.3 and check if that works for you.
Regards,
Matti
Matti Hosio:
Josef Karthauser:
Sorry if this is a trivial question; I'm struggling to work out how to set the centre of the view to a Wgs84 coordinate. I'm not sure what the default coordinate system is that's underlying the map, nor how to map Wgs84 coords into it.
Try to create your view like this:
OLViewOptions opts=new OLViewOptions();
opts.setInputProjection(Projections.EPSG4326);
OLView view=new OLView(opts);Cheers,
Matti
Ahha, that's the ticket. Thanks Matti.
If I want to change the view position manually after the map has been displayed, how do I do that?
I've tried:
map.view.setCenter(new OLCoordinate((box.east + box.west) / 2.0, (box.north + box.south) / 2.0))
where my box coordinates are Wgs84, but the map doesn't scroll to the new centre when I do that. (I'm doing it in a different thread, so I don't know if that's a problem...) Is there something I need to call to get the client to sync with the server model?
Joe
Josef Karthauser:
If I want to change the view position manually after the map has been displayed, how do I do that?I've tried:
map.view.setCenter(new OLCoordinate((box.east + box.west) / 2.0, (box.north + box.south) / 2.0))
where my box coordinates are Wgs84, but the map doesn't scroll to the new centre when I do that. (I'm doing it in a different thread, so I don't know if that's a problem...) Is there something I need to call to get the client to sync with the server model?
Joe
It looks like roughly the coordinate is being set, but there is an offset which suggests that the OL3 view isn't quite Wgs84. (My box is coming from a BBOX param in a Google Earth request - what I'm trying to do is to use Google Earth as a remote control for my Vaadin app, so that the OL3 map view tracks the Google Earth position.)
Joe
Josef Karthauser:
Matti Hosio:
Josef Karthauser:
Sorry if this is a trivial question; I'm struggling to work out how to set the centre of the view to a Wgs84 coordinate. I'm not sure what the default coordinate system is that's underlying the map, nor how to map Wgs84 coords into it.
Try to create your view like this:
OLViewOptions opts=new OLViewOptions();
opts.setInputProjection(Projections.EPSG4326);
OLView view=new OLView(opts);Cheers,
Matti
Ahha, that's the ticket. Thanks Matti.
If I want to change the view position manually after the map has been displayed, how do I do that?
I've tried:
map.view.setCenter(new OLCoordinate((box.east + box.west) / 2.0, (box.north + box.south) / 2.0))
where my box coordinates are Wgs84, but the map doesn't scroll to the new centre when I do that. (I'm doing it in a different thread, so I don't know if that's a problem...) Is there something I need to call to get the client to sync with the server model?
Joe
The different thread is most likely the problem. In any Vaadin application, if you do any UI changes in a separate background thread, you should do the modifications inside UI.access and have push enabled.
Cheers,
Matti
Matti Hosio:
Josef Karthauser: Ahha, that's the ticket. Thanks Matti.
If I want to change the view position manually after the map has been displayed, how do I do that?
I've tried:
map.view.setCenter(new OLCoordinate((box.east + box.west) / 2.0, (box.north + box.south) / 2.0))
where my box coordinates are Wgs84, but the map doesn't scroll to the new centre when I do that. (I'm doing it in a different thread, so I don't know if that's a problem...) Is there something I need to call to get the client to sync with the server model?
The different thread is most likely the problem. In any Vaadin application, if you do any UI changes in a separate background thread, you should do the modifications inside UI.access and have push enabled.
Cheers,
Matti
Good; I thought that might be the case - I'll investigate how to do that.
With respect to the coodinate issue, (I'm sorry - I'm still in a bit of a confused state about coordiante transformations).
Using:
OLViewOptions opt = new OLViewOptions();
opt.setInputProjection(Projections.EPSG4326);
Is EPSG4326 exactly equivalent to Wgs84, and does that control the output projection too?
I suppose that part of the problem may be that I have a bounding box (west, east, north, south) that I'm trying to replicate with the view, and need to map into a centre and zoom (given that the map aspect ration might be different to the input bounding box). However, if I just average the box to get a rough centre [(e+w)/2,(n+s)/2] it see appears that the OL3 map centre is roughtly what I expect, but it's off by upward of a whole bounding box size. So, I'm wondering whether I also need to set a 'OutputProjection' so that I can set the view centre in exactly WSG84 as well.
Am I confused?
Cheers Matti! :)
Joe
Josef Karthauser:
Matti Hosio:
Josef Karthauser: Ahha, that's the ticket. Thanks Matti.
If I want to change the view position manually after the map has been displayed, how do I do that?
I've tried:
map.view.setCenter(new OLCoordinate((box.east + box.west) / 2.0, (box.north + box.south) / 2.0))
where my box coordinates are Wgs84, but the map doesn't scroll to the new centre when I do that. (I'm doing it in a different thread, so I don't know if that's a problem...) Is there something I need to call to get the client to sync with the server model?
The different thread is most likely the problem. In any Vaadin application, if you do any UI changes in a separate background thread, you should do the modifications inside UI.access and have push enabled.
Cheers,
Matti
Good; I thought that might be the case - I'll investigate how to do that.
With respect to the coodinate issue, (I'm sorry - I'm still in a bit of a confused state about coordiante transformations).
Using:
OLViewOptions opt = new OLViewOptions();
opt.setInputProjection(Projections.EPSG4326);Is EPSG4326 exactly equivalent to Wgs84, and does that control the output projection too?
I suppose that part of the problem may be that I have a bounding box (west, east, north, south) that I'm trying to replicate with the view, and need to map into a centre and zoom (given that the map aspect ration might be different to the input bounding box). However, if I just average the box to get a rough centre [(e+w)/2,(n+s)/2] it see appears that the OL3 map centre is roughtly what I expect, but it's off by upward of a whole bounding box size. So, I'm wondering whether I also need to set a 'OutputProjection' so that I can set the view centre in exactly WSG84 as well.
Am I confused?
Cheers Matti! :)
Joe
Hunting around on google, I came across the following reference to OpenLayers and OpenStreetMap:
http://wiki.openstreetmap.org/wiki/OpenLayers_Simple_Example
var fromProj ection = new OpenLayers.Projection("EPSG:4326"); // transform from WGS 1984
var toProjection = new OpenLayers.Projection("EPSG:900913"); // to Spherical Mercator Projection
var extent = new OpenLayers.Bounds(-1.32,51.71,-1.18,51.80).transform(fromProjection,toProjection);
function init() {
var options = {};
map = new OpenLayers.Map("Map", options);
var newLayer = new OpenLayers.Layer.OSM( "New Layer", "URL_TO_TILES/${z}/${x}/${y}.png", {zoomOffset: 13, resolutions: [19.1092570678711,9.55462853393555,4.77731426696777,2.38865713348389]} );
map.addLayer(newLayer);
map.setCenter(new OpenLayers.LonLat(-1.25,51.75).transform(fromProjection,toProjection), 0); // 0=relative zoom level }
}
This suggests that there's a different approach, other than using EPSG4326; I'm not sure how to replicate that in OL3. Do I need to use an external library to do the conversion? Or, have I missed the LonLat interface in OL3?
Ok, it looks like it is working! My OL3 component was larger than the browser window and so the centre point wasn't where I was expecting it to be! Looks like setting the centre on the EPSG4326 view, as previously recommended, is working just fine.
I'm still struggling to work out how to get the OL3 component view box in Wgs84 coordinates though. Getting the centre is ok, but how do I transform that and the zoom parameter into pair of coordinates which express the size of the view port in the browser in map coords?
I want to do a database search for the view port box, and then populate the map component with features from that database search.
Sorry I'm being so needy - I'm still on a learning curve!
Many thanks for your help so far!
Cheers,
Joe
Josef Karthauser:
Josef Karthauser:
Matti Hosio:
Josef Karthauser: Ahha, that's the ticket. Thanks Matti.
If I want to change the view position manually after the map has been displayed, how do I do that?
I've tried:
map.view.setCenter(new OLCoordinate((box.east + box.west) / 2.0, (box.north + box.south) / 2.0))
where my box coordinates are Wgs84, but the map doesn't scroll to the new centre when I do that. (I'm doing it in a different thread, so I don't know if that's a problem...) Is there something I need to call to get the client to sync with the server model?
The different thread is most likely the problem. In any Vaadin application, if you do any UI changes in a separate background thread, you should do the modifications inside UI.access and have push enabled.
Cheers,
Matti
Good; I thought that might be the case - I'll investigate how to do that.
With respect to the coodinate issue, (I'm sorry - I'm still in a bit of a confused state about coordiante transformations).
Using:
OLViewOptions opt = new OLViewOptions();
opt.setInputProjection(Projections.EPSG4326);Is EPSG4326 exactly equivalent to Wgs84, and does that control the output projection too?
I suppose that part of the problem may be that I have a bounding box (west, east, north, south) that I'm trying to replicate with the view, and need to map into a centre and zoom (given that the map aspect ration might be different to the input bounding box). However, if I just average the box to get a rough centre [(e+w)/2,(n+s)/2] it see appears that the OL3 map centre is roughtly what I expect, but it's off by upward of a whole bounding box size. So, I'm wondering whether I also need to set a 'OutputProjection' so that I can set the view centre in exactly WSG84 as well.
Am I confused?
Cheers Matti! :)
Joe
I am by no means a GIS expert but as far as I know EPSG4326 is a projection based on Wgs84. If you are showing a map on a flat screen, you are doing some type of a projection anyways. So EPSG4326 is based on WGS84 but is not the same thing.
Also there is no OutputProjection option. The input projection should handle conversion from api calls to map coordinate system and back. If you want to focus to a bounding box, why not just use view.fitExtent api instead of view.setCenter?
Finally, I would guess the problems you are hitting are related to projections. I would suggest that you do some more research related to projections the google earth uses and then to the projection your map source uses. As said, I am no GIS expert so really can not help you there much further. Maybe other members of the community know better?
Anyone in the forum reading this, feel free to take over if you have done something like this before.
Regards,
Matti