ol3 update layer after time change - openlayers-3

I want to refresh my ol.layer.Tile with an ol.source.TileWMS as source, but calling source.updateParams has no effects and chrome inspector tool doesn't show network activities, such as geoserver requests. So where is the trick?
I use ol v3.16.0

You can using the params with parameter STYLE
For example:
var params = {LAYERS: layerId, VERSION: '1.3.0', STYLES: style};
var source = layer.getSource();
source.updateParams(params);
Inside, style is the name of style in the geoserver

I solved by upgrading to v3.18.2

Related

points not showing on map using a source.Vector loader function

I am having a problem showing a few points on the map where the geojson file is loaded from the server. The geojson file changes so I want a good way to refresh the map layer. To do this, I created the source.Vector (Version 3.17.1 of OpenLayers)
var locationSource = new ol.source.Vector({
format: new ol.format.GeoJSON({
defaultDataProjection :'EPSG:4326'
}),
loader: vectorLoader,
strategy: ol.loadingstrategy.all
});
function vectorLoader which executes a XHR call to retrieve the latest version of the geojson file. This has been simulated in the jsfiddle below
jsfiddle
The geojson file has valid json because the points on the map show if I use a source.Vector object which uses the url property instead of a loader like this:
var locationSource = new ol.source.Vector({
url: '/openlayers/location.geojson',
format: new ol.format.GeoJSON({
defaultDataProjection :'EPSG:4326'
})
});
I would use this but it is horrible about using cached versions of the geojson file when a new file is available. I want something that is more reliable which is why I'm trying to get this to work with a loader.
The jsfiddle link above has all the code and it seems to run fine but the the points never show up on the map after addFeatures, located here:
onSuccess: function(response) {
var format = new ol.format.GeoJSON();
var features = format.readFeatures(response, {
featureProjection: 'EPSG:4326'
});
source.addFeatures(features);
console.info(source.getFeatures());
map.updateSize();
source.changed();
You will see that no points show on the map for the data provided in the jsfiddle. I feel like I am missing something basic here but after finding many solutions, none work..I seems like the style function needs to be executed again after the 'addFeatures` load completes. This can be seen in the console log for the jsfiddle above.
Indeed this is just a minor issue you were missing.
First of all radius was not defined, this is probably pulled from a variable which you haven't copied to your fiddle.
The main issue though is the wrong projection used when you read your features featureProjection: 'EPSG:4326', it should be changed to featureProjection: 'EPSG:3857', since the default projection in an OpenLayers view is Web Mercator. It could also be the case, that you wanted to define the data projection explicitly while reading your GeoJSON, for this you should set dataProjection: 'EPSG:4326'.
A working example can be found in this fiddle: https://jsfiddle.net/9oukr51t/

Open URL with a set Target

EDIT:
The solution I am seeking is a command line to be run to accomplish this from a batch file in Windows.
How would I mimic a browser function to open a URL with a specific target so that if that tab is already open it will load there instead of creating a new tab?
So instead of the default http://url.com with the target "_blank", I could change this to "w00t", etc.
I am using Chrome exclusively, so if this were to be a Chrome specific command, that would be acceptable.
You could create a HTML-page and add the following code like this:
<script>
var url = getQueryVariable("url");
var target = getQueryVariable("target");
window.open(url,target);
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if (pair[0] == variable) {
return pair[1];
}
}
}
</script>
I have this script hosted here: scriptcoded.github.io/redirect
You could then call it from a batch-file using this command:
START scriptcoded.github.io/redirect?url=http://www.google.com&target=w00t
Use ?url=http://www.google.com&target=_blank to set the redirect.
The only problems I find with this method is that some browsers blocks the new window and that the tab won't close. Yes, we could use window.close();, but it will only close tabs that were opened by the webpage itself.
Hope it helps!
set name for html tag of target page like this:
<html name="w00t">
Note: A link to URL with target name, sets the name for target window automatically:
Google

What does the PF function do in Primefaces?

On many places one can find usage of a function PF with Primefaces. For example in this answer
From what I have seen so far it seems to be a magic "make it work a little better" function. But I don't believe in this kind of stuff so:
What does this function do?
And where can I find documentation about it?
PF is a Javascript function.
In Primefaces 4.0 the Javascript scope of widgets changed. Prior to version 4.0 you could open a dialog widget with widgetVar.show();.
In Primefaces 4.0 and above the widgets are stored in a Javascript widget array. When you call PF('widgetVar') it is looking for the widget in the array and returning it.
PF=function(d){
var c=b.widgets[d];
if(!c){
if(a.console&&console.log){
console.log("Widget for var '"+d+"' not available!")
}
b.error("Widget for var '"+d+"' not available!")
}
return c
};
I could not find much on this either this is what I was able to decipher using Chrome's developer tools.
The PF function is a part of PrimeFaces's JavaScript API. It looks up a Javascript object that is the backbone of the JSF component on the client-side. Here is its definition (source):
PF = function(widgetVar) {
var widgetInstance = PrimeFaces.widgets[widgetVar];
if (!widgetInstance) {
PrimeFaces.error("Widget for var '" + widgetVar + "' not available!");
}
return widgetInstance;
};
PF is a shortcut for PrimeFaces.widgets['someWidgetId'], which just looks-up a Javascript object in global scope, and so the Javascript object can also be retrieved using window['someWidgetId'].
The PrimeFaces's Javascript API has no official documentation online, so to understand what you can really "do" with the Javascript object, you'll need to take a deep dive into PrimeFaces.
See also
"Intro To PrimeFaces widgetVar" blog post
PrimeFaces source code
For other Primefaces users coming here when upgrading to version 4.0 and above, it's possible to bypass the need to use PF('yourWidgetVar').someFunction() and just use yourWidgetVar.someFunction() directly as you would have before version 4.0. You just need the following configuration in web.xml:
<context-param>
<param-name>primefaces.LEGACY_WIDGET_NAMESPACE</param-name>
<param-value>true</param-value>
</context-param>
From the Primefaces User Guide:
Enables window scope so that widgets can be accessed using
widgetVar.method() in addition to default PF namespace approach like
PF('widgetVar').method().
Obviously you'd be susceptible to the namespace clash/pollution this feature was created to avoid, but it's useful if you want to migrate to a new version in little steps and isolate what incompatibilities the new version has introduced.

HTMLDocument object from HTTP read()

I need to call at server side, an URL and work with the HTML content off the response. For this I'm using the HTTP library from Dart like this :
http.read('myUrl').then((contents) {
//contents to HTMLDocument format //Need to transform the String contents to HTML object
});
And I want to convert the response to a HTMLDocument (or other object I don't know) to be able to retrieve element in it by HTML tag or CSS class, like with JQuery for example.
Does anybody have an idea to perform this ?
You canuse html5lib package from pub. It allows to parse HTML and present it DOM like element tree on server side. The element tree will eventually "be compatible with dart:html, so the same code will work on the client and the server" in the future. See the readme for a getting started example.
"I need to call at server side"
Not sure exactly what you mean.
If you are running in the browser and calling the server you could try using a DocumentFragment. Something like this:
http.read(url).then((html) {
var fragment = new DocumentFragment(html);
var element = fragment.query('.foo');
// code here...
});
Otherwise if you're running server side, as the other answer mentions, html5lib is the way to go. Last time I looked the query() method in html5lib only supported tagname queries not classes, or ids.

Accessing Nested iframes from Extension

I need to access a nested iframe at an arbitrary number of levels deep from a Firefox extension's overlay (an iframe within an iframe within an iframe within...). The overlay receives the event from the iframe, but the DOM accessor method returns nil.
function resizeIframe(evt){
var iframeHeight = evt.target.getAttribute("height");
var frame_id = evt.target.getAttribute("frame_id");
var ifr = content.document.getElementById('ifrm'+frame_id);//returns nil
ifr.style.height = iframeHeight+'px';
}
I'm looking for a robust way to do this, but I would be happy with anything that works at this point. Thanks!
Use window.frameElement property:
var ifr = evt.target.ownerDocument.defaultView.frameElement;
From Firefox 34 onward, we can point the developer tools at a specific iframe within a document.
You can refer to this Mozilla Developer Guide for detail explanation about extension provided by Mozilla to access nested iframes.

Resources