Add building z-limit function to shader and web ui (#462)
This commit is contained in:
parent
0367507dae
commit
abac84e82a
@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright 2017 Izumi Kawashima
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the
|
||||
* terms of the GNU Lesser General Public License as published by the Free Software
|
||||
* Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
||||
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License along with
|
||||
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.oscim.web.client;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class BuildingSolutionControl {
|
||||
private final String divQuerySelector;
|
||||
public final int MAX_VALUE = 65536;
|
||||
private Collection<ValueChangeListener> listeners = new HashSet<>();
|
||||
|
||||
public BuildingSolutionControl(String divQuerySelector) {
|
||||
this.divQuerySelector = divQuerySelector;
|
||||
}
|
||||
|
||||
public void init() {
|
||||
initNative(divQuerySelector);
|
||||
refresh();
|
||||
}
|
||||
|
||||
private native void initNative(String divQuerySelector)/*-{
|
||||
var bsc = $doc.querySelector(divQuerySelector);
|
||||
var that = this;
|
||||
function onUpdate(val){
|
||||
that.@org.oscim.web.client.BuildingSolutionControl::fireValueChangeListeners(I)(val);
|
||||
}
|
||||
bsc.addEventListener("input",function(){onUpdate(this.value);});
|
||||
bsc.addEventListener("change",function(){onUpdate(this.value);});
|
||||
}-*/;
|
||||
|
||||
private native void refresh()/*-{
|
||||
|
||||
}-*/;
|
||||
|
||||
public void addValueChangeListener(ValueChangeListener l) {
|
||||
this.listeners.add(l);
|
||||
}
|
||||
|
||||
public void removeValueChangeListener(ValueChangeListener l) {
|
||||
this.listeners.remove(l);
|
||||
}
|
||||
|
||||
private void fireValueChangeListeners(int val) {
|
||||
for (ValueChangeListener l : this.listeners) {
|
||||
l.onValueChange(val, MAX_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
public interface ValueChangeListener {
|
||||
void onValueChange(int val, int max);
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2016 Izumi Kawashima
|
||||
* Copyright 2016-2017 Izumi Kawashima
|
||||
* Copyright 2017 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
@ -36,6 +36,7 @@ import org.oscim.layers.tile.buildings.BuildingLayer;
|
||||
import org.oscim.layers.tile.buildings.S3DBTileLayer;
|
||||
import org.oscim.layers.tile.vector.VectorTileLayer;
|
||||
import org.oscim.layers.tile.vector.labeling.LabelLayer;
|
||||
import org.oscim.renderer.ExtrusionRenderer;
|
||||
import org.oscim.renderer.MapRenderer;
|
||||
import org.oscim.theme.StreamRenderTheme;
|
||||
import org.oscim.theme.VtmThemes;
|
||||
@ -49,6 +50,8 @@ import org.slf4j.LoggerFactory;
|
||||
class GwtMap extends GdxMap {
|
||||
static final Logger log = LoggerFactory.getLogger(GwtMap.class);
|
||||
|
||||
BuildingLayer mBuildingLayer;
|
||||
BuildingSolutionControl mBuildingSolutionControl;
|
||||
SearchBox mSearchBox;
|
||||
|
||||
@Override
|
||||
@ -144,18 +147,34 @@ class GwtMap extends GdxMap {
|
||||
boolean nolabels = mapUrl.params.containsKey("nolabels");
|
||||
boolean nobuildings = mapUrl.params.containsKey("nobuildings");
|
||||
|
||||
if (!nobuildings && !s3db)
|
||||
mMap.layers().add(new BuildingLayer(mMap, l));
|
||||
if (!nobuildings && !s3db) {
|
||||
mBuildingLayer = new BuildingLayer(mMap, l);
|
||||
((ExtrusionRenderer) mBuildingLayer.getRenderer()).setZLimit((float) 65536 / 10);
|
||||
mMap.layers().add(mBuildingLayer);
|
||||
}
|
||||
|
||||
if (!nolabels)
|
||||
mMap.layers().add(new LabelLayer(mMap, l));
|
||||
}
|
||||
|
||||
mSearchBox = new SearchBox(mMap);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createLayers() {
|
||||
mBuildingSolutionControl = new BuildingSolutionControl("#building-solution-input");
|
||||
mBuildingSolutionControl.addValueChangeListener(new BuildingSolutionControl.ValueChangeListener() {
|
||||
@Override
|
||||
public void onValueChange(int val, int max) {
|
||||
if (mBuildingLayer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
((ExtrusionRenderer) mBuildingLayer.getRenderer()).setZLimit((float) val / 10);
|
||||
|
||||
mMap.updateMap(true);
|
||||
}
|
||||
});
|
||||
mBuildingSolutionControl.init();
|
||||
}
|
||||
}
|
||||
|
@ -104,3 +104,17 @@ html,body {
|
||||
background-color: #DDDDDD;
|
||||
opacity: 0.5;
|
||||
}
|
||||
|
||||
#building-solution{
|
||||
z-index: 20001;
|
||||
position: absolute;
|
||||
top: 40px;
|
||||
left: 0px;
|
||||
}
|
||||
input[type=range][orient=vertical]{
|
||||
writing-mode: bt-lr; /* IE */
|
||||
-webkit-appearance: slider-vertical; /* WebKit */
|
||||
width: 8px;
|
||||
height: 175px;
|
||||
padding: 0 5px;
|
||||
}
|
||||
|
@ -73,5 +73,8 @@
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div id="building-solution">
|
||||
<input type="range" orient="vertical" id="building-solution-input" min="0" max="65536" value="65536"/>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -5,6 +5,7 @@ uniform mat4 u_mvp;
|
||||
uniform vec4 u_color[4];
|
||||
uniform int u_mode;
|
||||
uniform float u_alpha;
|
||||
uniform float u_zlimit;
|
||||
attribute vec4 a_pos;
|
||||
attribute vec2 a_light;
|
||||
varying vec4 color;
|
||||
@ -13,7 +14,11 @@ const float ff = 255.0;
|
||||
void
|
||||
main(){
|
||||
// change height by u_alpha
|
||||
gl_Position = u_mvp * vec4(a_pos.xy, a_pos.z * u_alpha, 1.0);
|
||||
float height = a_pos.z * u_alpha;
|
||||
if (height > u_zlimit) {
|
||||
height = u_zlimit;
|
||||
}
|
||||
gl_Position = u_mvp * vec4(a_pos.xy, height, 1.0);
|
||||
// depth = gl_Position.z;
|
||||
if (u_mode == -1) {
|
||||
;
|
||||
|
@ -1,5 +1,7 @@
|
||||
/*
|
||||
* Copyright 2013 Hannes Janetzek
|
||||
* Copyright 2017 Izumi Kawashima
|
||||
* Copyright 2017 devemux86
|
||||
*
|
||||
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
|
||||
*
|
||||
@ -38,13 +40,15 @@ public abstract class ExtrusionRenderer extends LayerRenderer {
|
||||
protected int mBucketsCnt;
|
||||
protected float mAlpha = 1;
|
||||
|
||||
private float mZLimit = Float.MAX_VALUE;
|
||||
|
||||
public ExtrusionRenderer(boolean mesh, boolean alpha) {
|
||||
mMode = mesh ? 1 : 0;
|
||||
mTranslucent = alpha;
|
||||
}
|
||||
|
||||
public static class Shader extends GLShader {
|
||||
int uMVP, uColor, uAlpha, uMode, aPos, aLight;
|
||||
int uMVP, uColor, uAlpha, uMode, aPos, aLight, uZLimit;
|
||||
|
||||
public Shader(String shader) {
|
||||
if (!create(shader))
|
||||
@ -54,6 +58,7 @@ public abstract class ExtrusionRenderer extends LayerRenderer {
|
||||
uColor = getUniform("u_color");
|
||||
uAlpha = getUniform("u_alpha");
|
||||
uMode = getUniform("u_mode");
|
||||
uZLimit = getUniform("u_zlimit");
|
||||
aPos = getAttrib("a_pos");
|
||||
aLight = getAttrib("a_light");
|
||||
}
|
||||
@ -114,6 +119,7 @@ public abstract class ExtrusionRenderer extends LayerRenderer {
|
||||
|
||||
gl.depthFunc(GL.LESS);
|
||||
gl.uniform1f(s.uAlpha, mAlpha);
|
||||
gl.uniform1f(s.uZLimit, mZLimit);
|
||||
|
||||
ExtrusionBuckets[] ebs = mExtrusionBucketSet;
|
||||
|
||||
@ -268,4 +274,8 @@ public abstract class ExtrusionRenderer extends LayerRenderer {
|
||||
}
|
||||
v.mvp.setAsUniform(s.uMVP);
|
||||
}
|
||||
|
||||
public void setZLimit(float zLimit) {
|
||||
mZLimit = zLimit;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user