#overviewMap;
+ select;
+
/** Styled layer descriptor */
#sld;
}),
],
});
+ this.select = new Select();
this.#map = new Map({
controls: defaultControls({
attribution: false,
// }),
target: this.getMapName(),
});
+ this.#map.addInteraction(this.select);
//this.#map.getView().set('projection', 'EPSG:4326', true);
}
return true;
});
if (feature !== null)
- mapPart.callbacks['onFeatureSingleClick'](feature.get('path'));
+ mapPart.callbacks['onFeatureSingleClick'](feature.get('cr:path'));
});
}
select.on('select', function(e) {
if (e.selected.length > 0) {
let feature = e.selected[0];
- mapPart.callbacks['onFeatureSelected'](feature.get('path'));
+ mapPart.callbacks['onFeatureSelected'](feature.get('cr:path'));
}
});
}
return;
}
const coordinate = e.coordinate;
- const path = selected.get('path');
+ const path = selected.get('cr:path');
if (path === null)
return true;
const res = mapPart.callbacks['onFeaturePopup'](path);
return 'map';
}
+ selectFeatures(layerName, featureIds) {
+ // we cannot use 'this' in the function provided to OpenLayers
+ let mapPart = this;
+ this.select.getFeatures().clear();
+ const layer = this.getLayerByName(layerName);
+ const source = layer.getSource();
+ for (const featureId of featureIds) {
+ let feature = source.getFeatureById(featureId);
+ if (feature === null) {
+ source.on('featuresloadend', function(e) {
+ feature = source.getFeatureById(featureId);
+ if (feature !== null)
+ mapPart.select.getFeatures().push(feature);
+ });
+ } else {
+ this.select.getFeatures().push(feature);
+ }
+ }
+ }
+
//
// STATIC FOR EXTENSION
//
return reference;
}
- String getJsReference() {
+ protected String getJsReference() {
return jsClient.getJsVarName(reference);
}
String createJsFunction(String name, Function<Object[], Object> toDo);
/** Get a global variable name. */
- public String getJsVarName(String name);
+ String getJsVarName(String name);
/**
* Completion stage when the client is ready (typically the page has loaded in
}
default boolean isInstanceOf(String reference, String jsClass) {
- return (Boolean) evaluate(getJsVarName(reference) + " instanceof " + jsClass);
+ return (Boolean) evaluate("return "+getJsVarName(reference) + " instanceof " + jsClass);
}
/*
}
public static void putGeometry(Content c, QName name, Geometry geometry) {
- QName jsonFileName = new ContentName(name.getNamespaceURI(), name.getLocalPart() + _GEOM_JSON);
+ QName jsonFileName = getJsonFileName(name);
Content geom = c.soleChild(jsonFileName).orElseGet(
() -> c.add(jsonFileName, Collections.singletonMap(DName.getcontenttype.qName(), "application/json")));
try (OutputStream out = geom.open(OutputStream.class)) {
updateBoundingBox(c);
}
+ public static boolean hasGeometry(Content c, QNamed name) {
+ return hasGeometry(c, name.qName());
+ }
+
+ public static boolean hasGeometry(Content c, QName name) {
+ QName jsonFileName = getJsonFileName(name);
+ return c.hasChild(jsonFileName);
+ }
+
public static <T extends Geometry> T getGeometry(Content c, QNamed name, Class<T> clss) {
return getGeometry(c, name.qName(), clss);
}
public static <T extends Geometry> T getGeometry(Content c, QName name, Class<T> clss) {
- QName jsonFileName = new ContentName(name.getNamespaceURI(), name.getLocalPart() + _GEOM_JSON);
+ QName jsonFileName = getJsonFileName(name);
Content geom = c.soleChild(jsonFileName).orElse(null);
if (geom == null)
return null;
}
}
+ private static QName getJsonFileName(QName name) {
+ QName jsonFileName = new ContentName(name.getNamespaceURI(), name.getLocalPart() + _GEOM_JSON);
+ return jsonFileName;
+ }
+
public static Point toPoint(Content c) {
if (c.hasContentClass(EntityType.geopoint)) {
Double lat = c.get(WGS84PosName.lat, Double.class).orElseThrow();
outputFormat = "application/json";
}
String bboxStr = getKvpParameter(parameters, BBOX);
- log.debug(bboxStr);
+ if (log.isTraceEnabled())
+ log.trace(bboxStr);
final Envelope bbox;
if (bboxStr != null) {
String srs;
package org.argeo.app.geo.ux;
import java.util.Map;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import org.argeo.app.geo.ux.MapPart.FeaturePopupEvent;
+import org.argeo.app.geo.ux.MapPart.FeatureSelectedEvent;
+import org.argeo.app.geo.ux.MapPart.FeatureSingleClickEvent;
import org.argeo.app.ol.AbstractOlObject;
import org.argeo.app.ol.Layer;
import org.argeo.app.ol.OlMap;
return mapPartName;
}
+ public void selectFeatures(String layerName, Object... ids) {
+ executeMethod(getMethodName(), layerName, (Object[]) ids);
+ }
+
+ /*
+ * CALLBACKS
+ */
+ public void onFeatureSelected(Consumer<FeatureSelectedEvent> toDo) {
+ addCallback("FeatureSelected", (arr) -> {
+ toDo.accept(new FeatureSelectedEvent((String) arr[0]));
+ return null;
+ });
+ }
+
+ public void onFeatureSingleClick(Consumer<FeatureSingleClickEvent> toDo) {
+ addCallback("FeatureSingleClick", (arr) -> {
+ toDo.accept(new FeatureSingleClickEvent((String) arr[0]));
+ return null;
+ });
+ }
+
+ public void onFeaturePopup(Function<FeaturePopupEvent, String> toDo) {
+ addCallback("FeaturePopup", (arr) -> {
+ return toDo.apply(new FeaturePopupEvent((String) arr[0]));
+ });
+ }
+
+ protected void addCallback(String suffix, Function<Object[], Object> toDo) {
+ getJsClient().getReadyStage().thenAccept((ready) -> {
+ String functionName = getJsClient().createJsFunction(getMapPartName() + "__on" + suffix, toDo);
+ getJsClient().execute(getJsReference() + ".callbacks['on" + suffix + "']=" + functionName + ";");
+ executeMethod("enable" + suffix);
+ });
+ }
+
}
executeMethod(getMethodName(), source);
}
+ public Source getSource() {
+ String reference = getReference() + ".getSource()";
+ return new Source(getJsClient(), reference);
+ }
+
public void setMinResolution(double minResolution) {
if (isNew())
getNewOptions().put("minResolution", minResolution);
public Source(Object... args) {
super(args);
}
+
+ public void refresh() {
+ executeMethod(getMethodName());
+ }
}