I'm trying to add a new Feature with LineStrings whenever a button is clicked(after initialize), and I'm wondering how to do this without doing a refresh. Currently, when the button is clicked, the new Feature is added to map, but is not shown before I do a refresh of the page. What is the proper or easiest way to do this. The button I'm using is an AjaxButton, that not refreshes the page as I dont want it to be refreshed. My current solution is simply to remove(this.map)
and then add(this.map)
as this will load in the new map with the new Feature on the next refresh, but yeah, I want this to happend without needing the refresh.
Asked
Active
Viewed 136 times
0

Lars Karlsen
- 117
- 9
-
Does that solve your problem? https://stackoverflow.com/questions/30997633/openlayers-3-force-a-map-refresh – Grmpfhmbl Jun 13 '18 at 10:06
1 Answers
0
OpenLayersMap
has #update(AjaxRequestTarget)
method for this.
AjaxButton button = new AjaxButton("someId") {
@Override protected void onSubmit(AjaxRequestTarget target) {
// add feature
map.update(target); // this will repaint just the map
}
}

martin-g
- 17,243
- 2
- 23
- 35
-
Doesn't seem like map has an update function. Here is the class for it: http://wicketstuff.org/core/javadoc6/apidocs/org/wicketstuff/openlayers3/DefaultOpenLayersMap.html – Lars Karlsen Jun 11 '18 at 10:50
-
And here is the source code: https://github.com/wicketstuff/core/blob/1fa257603ed918d54a32f0e92bd949aa86afb65c/openlayers-parent/openlayers/src/main/java/org/wicketstuff/openlayers/OpenLayersMap.java#L835 (this is master branch from today). – martin-g Jun 11 '18 at 10:56
-
OK. I see the difference. I looked at openlayers project, while you use openlayers3. It has `updateLayers()`: https://github.com/wicketstuff/core/blob/master/openlayers3-parent/openlayers3/src/main/java/org/wicketstuff/openlayers3/OpenLayersMap.java#L379 – martin-g Jun 11 '18 at 10:58
-
Hmm. This didn't do anything. I added the new layer into map, and called map.updateLayers, and nothing happened. If i refresh afterwards, the new layer is there tho. – Lars Karlsen Jun 11 '18 at 11:50
-
It looks like this function only iterates trough each layer and call `.setVisible` and `.setOpacity` on it. I don't think this will push the new feature's javascript up to the browser (?) – Lars Karlsen Jun 11 '18 at 12:27