import VectorSource from 'ol/source/Vector.js';
import { bbox } from 'ol/loadingstrategy';
-import { transformToLatLonExtent } from './OpenLayersUtils.js';
+import { transformToEpsg4326LatLonExtent } from './OpenLayersUtils.js';
export default class BboxVectorSource extends VectorSource {
constructor(options) {
static processOptions(options) {
options.strategy = bbox;
options.url = function(extent, resolution, projection) {
- var bbox = transformToLatLonExtent(extent, projection);
+ var bbox = transformToEpsg4326LatLonExtent(extent, projection);
const baseUrl = options.baseUrl;
// invert bbox order in order to have minLat,minLon,maxLat,maxLon as required by WFS 2.0.0
*/
import { fromLonLat, getPointResolution } from 'ol/proj.js';
-import { transformExtent } from 'ol/proj.js';
import TileLayer from 'ol/layer/Tile.js';
import * as SLDReader from '@nieuwlandgeo/sldreader';
import MapPart from './MapPart.js';
+import { transformToOlLonLatExtent } from './OpenLayersUtils.js';
/** OpenLayers implementation of MapPart. */
export default class OpenLayersMapPart extends MapPart {
}
fit(extent, options) {
- var transformed = transformExtent(extent, 'EPSG:4326', this.#map.getView().getProjection());
+ var transformed = transformToOlLonLatExtent(extent, this.#map.getView().getProjection());
this.#map.getView().fit(transformed, options);
}
import { transformExtent } from 'ol/proj.js';
-export function transformToLatLonExtent(extent, projection) {
+export function transformToEpsg4326LatLonExtent(extent, projection) {
const proj = projection.getCode();
if (proj === 'EPSG:4326')
return toLatLonExtent(extent);
return toLatLonExtent(transformed);
}
+/** From EPSG:4326 lat/lon to a proj lon/lat */
+export function transformToOlLonLatExtent(extent, projection) {
+ const proj = projection.getCode();
+ if (proj === 'EPSG:4326')
+ return toLonLatExtent(extent);
+ const reordered = toLonLatExtent(extent);
+ var transformed = transformExtent(reordered, 'EPSG:4326', proj);
+ return transformed;
+}
+
+/** Converts from an extent in OpenLayers order (lon/lat) to WFS 2.0 order (lat/lon). */
export function toLatLonExtent(extent) {
return [extent[1], extent[0], extent[3], extent[2]];
-}
\ No newline at end of file
+}
+
+/** Converts from an extent in WFS 2.0 order (lat/lon) to OpenLayers order (lon/lat) . */
+export function toLonLatExtent(extent) {
+ return [extent[1], extent[0], extent[3], extent[2]];
+}
+
import org.argeo.api.acr.Content;
import org.argeo.api.acr.search.AndFilter;
import org.argeo.app.api.EntityType;
-import org.argeo.app.api.WGS84PosName;
-import org.argeo.app.geo.JTS;
-import org.locationtech.jts.geom.Coordinate;
+import org.argeo.app.geo.acr.GeoEntityUtils;
import org.locationtech.jts.geom.Geometry;
-import org.locationtech.jts.geom.Point;
import jakarta.json.stream.JsonGenerator;
static Geometry getGeoPointGeometry(Content c) {
if (c.hasContentClass(EntityType.geopoint)) {
- double latitude = c.get(WGS84PosName.lat, Double.class).get();
- double longitude = c.get(WGS84PosName.lon, Double.class).get();
-
- Coordinate coordinate = new Coordinate(longitude, latitude);
- Point the_geom = JTS.GEOMETRY_FACTORY.createPoint(coordinate);
- return the_geom;
+ return GeoEntityUtils.toPoint(c);
+// double latitude = c.get(WGS84PosName.lat, Double.class).get();
+// double longitude = c.get(WGS84PosName.lon, Double.class).get();
+//
+// Coordinate coordinate = new Coordinate(longitude, latitude);
+// Point the_geom = JTS.GEOMETRY_FACTORY.createPoint(coordinate);
+// return the_geom;
}
return null;
}
/** Writes a pair of coordinates [lat,lon]. */
public static void writeCoordinate(JsonGenerator g, Coordinate coordinate) {
- g.write(coordinate.getX());
+ // !! longitude is first in GeoJSON
g.write(coordinate.getY());
+ g.write(coordinate.getX());
double z = coordinate.getZ();
if (!Double.isNaN(z)) {
g.write(z);
return (T) res;
}
- /** Reads a coordinate sequence [[lat,lon],[lat,lon]]. */
+ /** Reads a coordinate pair [lon,lat]. */
public static Coordinate readCoordinate(JsonArray arr) {
assert arr.size() >= 2;
- return new Coordinate(arr.getJsonNumber(0).doubleValue(), arr.getJsonNumber(1).doubleValue());
+ // !! longitude is first in GeoJSon
+ return new Coordinate(arr.getJsonNumber(1).doubleValue(), arr.getJsonNumber(0).doubleValue());
}
- /** Reads a coordinate pair [lat,lon]. */
+ /** Reads a coordinate sequence [[lon,lat],[lon,lat]]. */
public static Coordinate[] readCoordinates(JsonArray arr) {
Coordinate[] coords = new Coordinate[arr.size()];
for (int i = 0; i < arr.size(); i++)
Double latitude = Double.parseDouble(attributes.getValue("lat"));
Double longitude = Double.parseDouble(attributes.getValue("lon"));
// TODO elevation in 3D context
- Coordinate coordinate = new Coordinate(longitude, latitude);
+ Coordinate coordinate = new Coordinate(latitude, longitude);
coordinates.add(coordinate);
}
}
throw new IllegalArgumentException("Unsupported format " + clss);
}
}
-
+
/** @deprecated Use {@link #parseGpxTrackTo(InputStream, Class)} instead. */
@Deprecated
public static SimpleFeature parseGpxToPolygon(InputStream in) throws IOException {
import org.argeo.app.geo.GeoUtils;
import org.argeo.app.geo.GpxUtils;
import org.argeo.app.geo.JTS;
+import org.argeo.app.geo.acr.GeoEntityUtils;
import org.argeo.cms.acr.json.AcrJsonUtils;
import org.argeo.cms.auth.RemoteAuthUtils;
import org.argeo.cms.http.HttpHeader;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Envelope;
import org.locationtech.jts.geom.Geometry;
-import org.locationtech.jts.geom.Point;
import org.locationtech.jts.geom.Polygon;
import com.sun.net.httpserver.HttpExchange;
protected Geometry getDefaultGeometry(Content content) {
if (content.hasContentClass(EntityType.geopoint)) {
- double latitude = content.get(WGS84PosName.lat, Double.class).get();
- double longitude = content.get(WGS84PosName.lon, Double.class).get();
-
- Coordinate coordinate = new Coordinate(longitude, latitude);
- Point the_geom = JTS.GEOMETRY_FACTORY.createPoint(coordinate);
- return the_geom;
+ return GeoEntityUtils.toPoint(content);
}
return null;
}