Interactive interface for browsing global, full-resolution satellite imagery
WIP polygon rendering
Jason Kent01936c24322f
diff --git a/web/js/map/model.js b/web/js/map/model.jsindex 365f60a5b..68f071c0c 100644--- a/web/js/map/model.js+++ b/web/js/map/model.js@@ -11,24 +11,28 @@ export default function mapModel(models, config) {self.selectedMap = null;self.ui = null;self.rotation = 0;+const init = function() {if (!config.projections) {return;}- Object.values(config.projections).forEach((proj) => {- if (proj.crs && proj.proj4) {- self.register(proj.crs, proj.proj4);+ Object.values(config.projections).forEach((def) => {+ if (def.crs && def.proj4) {+ self.register(def);}});};- self.register = function(crs, def) {- if (def && proj4) {- proj4.defs(crs, def);++ self.register = function(def) {+ if (def && def.proj4) {+ proj4.defs(def.crs, def.proj4);register(proj4);- olProj.get(crs).setExtent(def.maxExtent);+ const olProjInstance = olProj.get(def.crs);+ olProjInstance.setExtent(def.maxExtent);}};+/** Emits update event*@@ -42,14 +46,17 @@ export default function mapModel(models, config) {self.update = function(extent) {self.extent = extent;};+// Give other components access to zoom Levelself.updateMap = function(map, ui) {self.selectedMap = map;self.ui = ui;};+self.getZoom = function() {return self.selectedMap ? self.selectedMap.getView().getZoom() : null;};+/** Sets map view from parsed URL*diff --git a/web/js/map/natural-events/event-markers.js b/web/js/map/natural-events/event-markers.jsindex a87a205f3..8d4fcc53e 100644--- a/web/js/map/natural-events/event-markers.js+++ b/web/js/map/natural-events/event-markers.js@@ -93,11 +93,12 @@ class EventMarkers extends React.Component {if (geometry.type === 'Polygon') {const coordinatesTransform = coordinates[0].map(transformCoords);const extent = olExtent.boundingExtent(coordinatesTransform);- coordinates = olExtent.getCenter(extent);+if (isSelected) {- marker.boundingBox = createBoundingBox(coordinatesTransform);+ marker.boundingBox = createBoundingBox(coordinates, event.title, crs);map.addLayer(marker.boundingBox);}+ coordinates = olExtent.getCenter(extent);} else {// if normal geometries, transform given lon/lat arraycoordinates = transformCoords(coordinates);@@ -106,7 +107,7 @@ class EventMarkers extends React.Component {const extent = olExtent.boundingExtent(geometry.coordinates[0]);coordinates = olExtent.getCenter(extent);if (isSelected) {- marker.boundingBox = createBoundingBox(geometry.coordinates);+ marker.boundingBox = createBoundingBox(geometry.coordinates, event.title);map.addLayer(marker.boundingBox);}}@@ -133,8 +134,10 @@ class EventMarkers extends React.Component {return collection;}, []);- map.renderSync(); // Marker position will be off until this is called- this.setState({ markers });+ this.setState({ markers }, () => {+ map.getView().changed();+ map.renderSync(); // Marker position will be off until this is called+ });}addInteractions(marker, event, date, isSelected) {@@ -224,12 +227,12 @@ const createPin = function(id, category, isSelected, title) {});};-const createBoundingBox = function(coordinates) {+const createBoundingBox = function(coordinates, title, proj = 'EPSG:4326') {const lightStroke = new OlStyleStyle({stroke: new OlStyleStroke({color: [255, 255, 255, 0.6],width: 2,- lineDash: [4, 8],+ lineDash: [8, 12],lineDashOffset: 6,}),});@@ -237,19 +240,21 @@ const createBoundingBox = function(coordinates) {stroke: new OlStyleStroke({color: [0, 0, 0, 0.6],width: 2,- lineDash: [4, 8],+ lineDash: [8, 12],}),});+ const boxPolygon = new OlGeomPolygon(coordinates).transform('EPSG:4326', proj);+ const boxFeature = new OlFeature({+ geometry: boxPolygon,+ name: title,+ });+ const vectorSource = new OlSourceVector({+ features: [boxFeature],+ wrapX: false,+ });+return new OlLayerVector({- source: new OlSourceVector({- features: [- new OlFeature({- geometry: new OlGeomPolygon(coordinates),- name: 'NaturalEvent',- }),- ],- wrapX: false,- }),+ source: vectorSource,style: [lightStroke, darkStroke],});};diff --git a/web/js/map/natural-events/natural-events.js b/web/js/map/natural-events/natural-events.jsindex 26bb85786..37327d925 100644--- a/web/js/map/natural-events/natural-events.js+++ b/web/js/map/natural-events/natural-events.js@@ -136,21 +136,20 @@ class NaturalEvents extends React.Component {zoomToEvent = function(event, date, isSameEventID) {const { proj, map, mapUi } = this.props;- const { crs, id } = proj.selected;+ const { crs } = proj.selected;const category = event.categories[0].title;const zoom = isSameEventID ? map.getView().getZoom() : zoomLevelReference[category];const geometry = event.geometry.find((geom) => geom.date.split('T')[0] === date);// check for polygon geometries and/or perform projection coordinate transform- let coordinates = geometry.type === 'Polygon'- ? olExtent.boundingExtent(- olProj.transform(geometry.coordinates[0], 'EPSG:4326', crs),- )- : olProj.transform(geometry.coordinates, 'EPSG:4326', crs);-- // handle extent transform for polar- if (geometry.type === 'Polygon' && id !== 'geographic') {- coordinates = olProj.transformExtent(coordinates, 'EPSG:4326', crs);+ let coordinates;+ const transformCoords = (coords) => olProj.transform(coords, 'EPSG:4326', crs);++ if (geometry.type === 'Polygon') {+ const transformedCoords = geometry.coordinates[0].map(transformCoords);+ coordinates = olExtent.boundingExtent(transformedCoords);+ } else {+ coordinates = olProj.transform(geometry.coordinates, 'EPSG:4326', crs);}return mapUi.animate.fly(coordinates, zoom, null);};diff --git a/web/js/map/natural-events/util.js b/web/js/map/natural-events/util.jsindex 0444ae40e..2cb14c55f 100644--- a/web/js/map/natural-events/util.js+++ b/web/js/map/natural-events/util.js@@ -1,7 +1,7 @@import {find as lodashFind,} from 'lodash';-import * as olProj from 'ol/proj';+import { transform } from 'ol/proj';import { getCenter, boundingExtent, containsCoordinate } from 'ol/extent';import moment from 'moment';import util from '../../util/util';@@ -83,12 +83,12 @@ export function getEventsWithinExtent(if (selectedProj.id !== 'geographic') {if (geometry.type === 'Polygon') {const coordinatesTransform = coordinates[0].map(- (coordinate) => olProj.transform(coordinate, 'EPSG:4326', crs),+ (coordinate) => transform(coordinate, 'EPSG:4326', crs),);const geomExtent = boundingExtent(coordinatesTransform);coordinates = getCenter(geomExtent);} else {- coordinates = olProj.transform(coordinates, 'EPSG:4326', crs);+ coordinates = transform(coordinates, 'EPSG:4326', crs);}} else if (geometry.type === 'Polygon') {const geomExtent = boundingExtent(geometry.coordinates[0]);