openlayers-3 change external wms layer styles - css

Is it possible change the style of a external wms layer??
im trying to use this layer:
https://firms.modaps.eosdis.nasa.gov/wms/?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&LAYERS=fires24&width=400&height=250&BBOX=-26,34,35,82
with this code on openlayers3
var fill = new ol.style.Fill({color: 'GREEN'});
var stroke = new ol.style.Stroke({color: 'GREEN'});
var styles = [new ol.style.Style({
image: new ol.style.Circle({
fill: fill,
stroke: stroke,
radius: 5
})
})];
var fires = new ol.layer.Image({
name: 'fires',
source: new ol.source.ImageWMS({
url: 'https://firms.modaps.eosdis.nasa.gov/wms/',
params: {
'LAYERS': 'fires24',
'VERSION': '1.1.1'
}
}),
style: styles
});
the layer is displayed correctly but without my own styles.
Is it possible to do that or replace with a custom icon?

The WMS link you use is returning a PNG file, which I believe OpenLayers cannot style 'after the fact'. Once you've got it it's immutable - it's not 'data' but an image with transparency that is overlaid on top of your underlying map source.
There are some params you can pass into a wms call (as you've done) and the standard looks like it can support you passing styles into the call to the WMS server to get it to use those when rendering the image.
I've got a list of possible parameters from the geoserver website (a GIS server) - http://docs.geoserver.org/stable/en/user/services/wms/reference.html
Looking at that link it looks like sld or sld_body parameters may work. SLD is like OL styles but in XML. Details of these stylesheets are here - http://docs.geoserver.org/stable/en/user/styling/index.html#styling
I've had a go at this jsfiddle : https://jsfiddle.net/y7fj57dj/ but it's not working as such - it could either be my SLD (I'm not up to speed with it) or the NASA server doesn't know what to do with it/is ignoring it.
You may need to contact NASA server admins to confirm if you can style the WMS calls (support#earthdata.nasa.gov, retrieved by going to https://firms.modaps.eosdis.nasa.gov/wms/?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetCapabilities).

Related

Aframe gltf-model demo with envmap

It's very convenient to load GLTF- model in aframe, but no case is found that contains envmap texture. I'd like to see that the official can provide the same case as three official. pmremGenerator.fromEquirectangular(texture) function is used to make gltf model produce real reflection effect
https://threejs.org/examples/#webgl_loader_gltf
https://threejs.org/examples/#webgl_materials_envmaps_hdr
One way would be creating a custom component, which will:
wait until the model is loaded
traverse through the object's children
if they have a material property - apply the envMap
The envmap needs to be a CubeTexture - which adds another level of complication, when you want to use a panorama. You can use a the WebGLRenderTargetCube - It's an object which provides a texture from a Cube Camera 'watching' the panorama.
Overall The component code could look like this:
// create the 'cubecamera' objct
var targetCube = new THREE.WebGLRenderTargetCube(512, 512);
var renderer = this.el.sceneEl.renderer;
// wait until the model is loaded
this.el.addEventListener("model-loaded", e => {
let mesh = this.el.getObject3D("mesh");
// load the texture
var texture = new THREE.TextureLoader().load( URL,
function() {
// create a cube texture from the panorama
var cubeTex = targetCube.fromEquirectangularTexture(renderer, texture);
mesh.traverse(function(node) {
// if a node has a material attribute - it can have a envMap
if (node.material) {
node.material.envMap = cubeTex.texture;
node.material.envMap.intensity = 3;
node.material.needsUpdate = true;
}
});
}
Check it out in this glitch.
I was having the same issue and i found that cube-env-map from a-frame-extras works like a charm.
View component on GitHub
Its docs describe it as:
Applies a CubeTexture as the envMap of an entity, without otherwise
modifying the preset materials
And the code is super simple:
yarn add aframe-extras
import 'aframe-extras'
<a-entity
gltf-model="src: url('/path/to/file.glb')"
cube-env-map="path: /cubeMapFolder/;
extension: jpg;
reflectivity: 0.9;">
</a-entity>
In THREE demo, I remember that WebGLRenderTargetCube was used to produce envmap, but recently it was found thatPMREMGenerator was basically used to generate envmap texture with mipmap. It also supports HDR image format, making gltf model better than JPG texture.
I don't know how these JS modules PMREMGenerator and RGBELoader are used together with the components of Aframe. Can someone provide such an example in Aframe ,Thanks
That's the same High dynamic range (RGBE) Image-based Lighting (IBL) using run-time generated pre-filtered roughness mipmaps (PMREM)

QT QML - Changing Mapbox font size

I'm using QT 5.12.4 with the MapboxGl plugin and I'm trying to figure out how to make the street names display in a larger font but I'm very confused about how to specify a text size. I need to change the size dynamically so using a predefined style is not going to meet the requirements.
The two confusing aspects are that Mapbox's documentation has to be translated into "MapParameters" for QML and I'm clueless as to what exactly is needed to change the text size. Between reading through the documentation and playing with the mapbox studio it seems like I need to modify the "road-label" layer. If anyone has some sample code of how to change the text size I would really appreciate it if you could share.
https://docs.mapbox.com/mapbox-gl-js/style-spec/#layout-symbol-text-size
MapParameter
{
type: "layout"
property var layer: "road-label"
property var textSize: 20
}
What you did looks correct. You need to define a MapParameter with the type layout because the text-size is a layout property in the Mapbox Style Specification. We cannot use - on QML variable names, so we camelCase it to textSize. After that you can bind textSize to anything you want.
You need to make sure that the layer road-label exists on the style at the moment the MapParameter is added.
I solved the problem and the key was getting the JSON for the predefined style that I was using (navigation-preview-day-v2). This post showed me how to get the pre-defined sytle:
URL for Mapbox style sheet JSON
For the navigation-preview-day-v2 style, the URL would be:
https://api.mapbox.com/styles/v1/mapbox/navigation-preview-day-v2?access_token=(your token here)
Run the JSON through a formatter so you can read it and find the layer(s) where the street names are rendered. In this case, there are four layers:
road-label-small
road-label-medium
road-label-large
road-label-extra-large
Here is an example of how to form the MapParameter in QML for the font size:
MapParameter
{
type: "layout"
property var layer: "road-label-large"
property var textSize:
{
"base": 1,
"stops":
[
[9, 10],
[20, 16]
]
}
}
You can also import the JSON into Mapbox Studio to review or manipulate the style. In my case I wanted to dynamically scale the font size so in my QML I added a scale factor and the resulting MapParameter is:
MapParameter
{
type: "layout"
property var layer: "road-label-large"
property var textSize:
{
"base": 1,
"stops":
[
[9, Math.floor(10 * fontScaleFactor)],
[20, Math.floor(16 * fontScaleFactor)]
]
}
}

Animating a series of PNG images in a-frame / AR.JS

I am currently experimenting with A-Frame and AR.js for a project I'm working on. I was wondering if it's possible to animate a series of PNG files eg. img-1.png, img-2.png, and so on in a-frame without individually adding animation for each frame?
I'm aware of an A-frame GIF component but GIFs are harder to maintain and can only output limited colors (and also trouble with opacity).
Any insights/help would be appreciated. Thanks!
How about a component, which loads up the .pngs as textures, and swaps them in a fixed interval:
AFRAME.registerComponent("slideshow", {
init: function() {
load up and store the images
var loader = new THREE.TextureLoader()
this.array = []
this.array.push(loader.load("one.png"))
this.array.push(loader.load("two.png"))
Instead of doing this one by one, you could do this in a loop ("img-" + i + ".png").
Also you could provide a list using the schema.
Wait until the entity is loaded:
this.el.addEventListener('loaded', e => {
let mesh = this.getObject3D('mesh')
let material = mesh.material
swap the material.map texture in the tick() or within an interval:
let i = 0
setInterval(e => {
// if we're at the last element - swap to the first one
if (i >= this.array.length) i = 0
this.material.map = this.array[i++]
this.material.needsUpdate = true
and it should be working like in this fiddle, when attached to an entity:
<a-box slideshow></a-box>
Why this.array ? For example you can easily access it in the remove() function and dispose the textures to free up memory.
Why not just do setAttribute('material', 'src', 'img-' + i + '.png') ?
I believe with more images it may by highly inefficcient.

OpenLayers3 Not Displaying Image

I am writing a map application using openlayers3. I am upgrading from openlayers2 which works well. My issue is that the image returned from my wms server is not displaying in the div. The image returned is a png image. I know it returns a correct image because I save it in my api call to the WMS server as well as check the debugging tools in my browser and the image shows up, returned as a "image/png". I also have a div with id="map" and I set the width and height of the div. The zoom in and zoom out controls show up for the map but the actual image does not.
Code:
map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Image({
extent: parameters.maxExtent,
source: new ol.source.ImageWMS({
url: '../../WMS/floorplan?',
params: { 'LAYERS': '#Model.LayerName', 'VERSION': '1.3.0', 'FORMAT': "image/png", 'SHAPEFILE': '#Model.ShapeFile'},
ratio: 0.8,
serverType: 'mapserver'
})
})
],
view: new ol.View({
projection: '#Model.Projection',
center: [#Model.CenterLon, #Model.CenterLat],
extent: parameters.maxExtent,
zoom: 0.5
})
});
It seems setting a ratio on the ImageWMS source that is less than one causes this. See http://jsfiddle.net/zL9jhgqf/ (setting ratio to one and running it again makes it work).
source: new ol.source.ImageWMS({
url: 'http://demo.boundlessgeo.com/geoserver/wms',
params: {'LAYERS': 'topp:states'},
ratio: 0.8,
serverType: 'geoserver'
})
I created an issue about it, since I don't know what the expected behaviour is: https://github.com/openlayers/ol3/issues/3926
BTW. What is the use case for having a WMS layer covering less than the viewport?

Openlayers Feature.Vector only uses default style

I'm changing from markers to vector layer and I can't make my site to use any sort of non-default icon, whatever I put in externalGraphic style attribute doesnt have effect on map. I just see orange circles. To be exact, no matter what I put in Openlayers.Style to style my point features, I get default look of icons.
It should be easy, but I try for days and can't make it work, so I came here for help. When warstwa_ikon was markers layer everything was fine, but I need extra functionality.
Thats my styling code:
var StylIkony = new OpenLayers.Style({
externalGraphic : '${symbol}',
graphicWidth : 15,
graphicHeight : 15,
cursor : 'pointer'
});
var StylWarstwyIkon = new OpenLayers.StyleMap ({
default: StylIkony,
delete: StylIkony,
select: StylIkony,
temporary: StylIkony
});
warstwa_ikon = new OpenLayers.Layer.Vector("Ikony Lokali",{ eventListeners: { "featureselected": WywolajRamke }});
warstwa_ikon.StyleMap = StylWarstwyIkon;
map.addLayer(warstwa_ikon);
Thats already executed code from generating Features:
WspolrzedneIkony = new OpenLayers.Geometry.Point(2279231, 7127620);
Ikona = new OpenLayers.Feature.Vector(WspolrzedneIkony,
{ "symbol": "../GRAFIKI/IkonyLokali/10.png", "idLokalu": 1 });
warstwa_ikon.addFeatures([Ikona]);
WspolrzedneIkony = new OpenLayers.Geometry.Point(2279245, 7127630);
Ikona = newOpenLayers.Feature.Vector(WspolrzedneIkony,
{ "symbol": "../GRAFIKI/IkonyLokali/6.png", "idLokalu": 2 });
warstwa_ikon.addFeatures([Ikona]);
Thats DOM of my vector layers (warstwa_ikon) StyleMap:
http://s24.postimg.org/hwfjakg0l/stylemap.png
Thats DOM of my vector layer first Feature, which should be styled:
http://s9.postimg.org/oxlocyku7/feature.png
Sorry, I can't include normal images yet. I should add that this is not a problem with accessing icon image file, I can't get layer to use any sort of images, even from internet links.
Declares StyleMap on layer creation as:
warstwa_ikon = new OpenLayers.Layer.Vector("Ikony Lokali", {
styleMap: StylWarstwyIkon,
eventListeners: ...
});
and removes:
warstwa_ikon.StyleMap = StylWarstwyIkon;

Resources