X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=blobdiff_plain;f=environment%2Forg.argeo.geo.ui%2Fsrc%2Forg%2Fargeo%2Fsupport%2Fopenlayers%2FOpenLayersMap.java;h=5357149c81e4dc5d3ec859ca5a2c925afef8559e;hp=6fce760aee9a42bb63a8f7a97faafc01cec947ef;hb=9218d0d47a4e6ebe497974ad7dfc637da63f11f6;hpb=29b0d284bfdbfe90d477f783dfd10ee4f31bf09a diff --git a/environment/org.argeo.geo.ui/src/org/argeo/support/openlayers/OpenLayersMap.java b/environment/org.argeo.geo.ui/src/org/argeo/support/openlayers/OpenLayersMap.java index 6fce760..5357149 100644 --- a/environment/org.argeo.geo.ui/src/org/argeo/support/openlayers/OpenLayersMap.java +++ b/environment/org.argeo.geo.ui/src/org/argeo/support/openlayers/OpenLayersMap.java @@ -41,7 +41,11 @@ public class OpenLayersMap extends Composite { private String vectorSource = null; private String gpxSource = null; + private String vectorSourceStyle; + private List geoJsonSources = new ArrayList<>(); + private Map vectorSources = new HashMap<>(); + private Map layerStyles = new HashMap<>(); private CmsView cmsView; @@ -101,7 +105,7 @@ public class OpenLayersMap extends Composite { this.zoom = zoom; } - public void addPoints(List geoPoints) throws RepositoryException { + protected String asVectorSource(List geoPoints) throws RepositoryException { boolean first = true; StringBuffer sb = new StringBuffer("new ol.source.Vector({ features: ["); for (int i = 0; i < geoPoints.size(); i++) { @@ -117,22 +121,63 @@ public class OpenLayersMap extends Composite { sb.append("new ol.geom.Point(ol.proj.fromLonLat(["); sb.append(lng).append(',').append(lat); sb.append("]))"); - sb.append(",path:'").append(node.getPath()).append("'"); + sb.append(",path:\"").append(node.getPath()).append("\""); + sb.append(",name:\"").append(node.getName()).append("\""); + String entityType = null; + if (node.isNodeType(EntityType.local.get())) { + entityType = node.getProperty(EntityNames.ENTITY_TYPE).getString(); + sb.append(", type:'").append(entityType).append("'"); + } sb.append("})"); } } - sb.append("] })"); - this.vectorSource = sb.toString(); + sb.append("]"); + sb.append(" })"); + return sb.toString(); + } + + public void addPoints(List geoPoints) throws RepositoryException { + this.vectorSource = asVectorSource(geoPoints); if (log.isTraceEnabled()) log.trace("Vector source: " + vectorSource); renderVectorSource(); } + public void addPoints(String layerName, List geoPoints, String style) throws RepositoryException { + this.vectorSources.put(layerName, asVectorSource(geoPoints)); + if (style != null) { + layerStyles.put(layerName, style); + } + renderVectorSources(); + } + protected void renderVectorSource() { if (vectorSource == null) return; - if (isRenderCompleted()) - browser.evaluate("map.addLayer(new ol.layer.Vector({ source: " + vectorSource + "}));"); + if (isRenderCompleted()) { +// String style = ", style: new ol.style.Style({ image: new ol.style.Icon({ src: '/pkg/org.djapps.on.openheritage.ui/map_oc.png' }) })"; + String style = vectorSourceStyle != null ? ", style: " + vectorSourceStyle : ""; +// String style = ""; + String toEvaluate = "map.addLayer(new ol.layer.Vector({ source: " + vectorSource + style + "}));"; +// System.out.println(toEvaluate); + browser.execute(toEvaluate); + } + } + + protected void renderVectorSources() { + if (vectorSources.isEmpty()) + return; + if (isRenderCompleted()) { + StringBuilder toExecute = new StringBuilder(); + for (String name : vectorSources.keySet()) { + String style = layerStyles.containsKey(name) ? ", style: " + layerStyles.get(name) : ""; + String toEvaluate = "map.addLayer(new ol.layer.Vector({ source: " + vectorSources.get(name) + style + + ",name: '" + name + "'}));"; + toExecute.append(toEvaluate); + } + System.out.println(toExecute); + browser.execute(toExecute.toString()); + } } public void addPoint(Double lng, Double lat) { @@ -174,6 +219,10 @@ public class OpenLayersMap extends Composite { } } + public void setVectorSourceStyle(String vectorSourceStyle) { + this.vectorSourceStyle = vectorSourceStyle; + } + private class RenderCompleted extends BrowserFunction { RenderCompleted(Browser browser, String name) { @@ -190,12 +239,14 @@ public class OpenLayersMap extends Composite { if (centerLat != null && centerLng != null) { setCenter(centerLng, centerLat); } - if (vectorSource != null) - renderVectorSource(); - if (gpxSource != null) - renderGpxSource(); if (!geoJsonSources.isEmpty()) renderGeoJsonSources(); + if (gpxSource != null) + renderGpxSource(); + if (vectorSource != null) + renderVectorSource(); + if (!vectorSources.isEmpty()) + renderVectorSources(); } return null; } catch (Exception e) {