Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

use overlay for location marker

Jason Kenteeb54ecdf34c
diff --git a/web/js/components/location-search/location-marker.js b/web/js/components/location-search/location-marker.js
new file mode 100644
index 000000000..daa7e9605
--- /dev/null
+++ b/web/js/components/location-search/location-marker.js
@@ -0,0 +1,21 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+
+export default function LocationMarker ({ reverseGeocodeResults, addCoordinatesTooltip }) {
+ return (
+ <>
+ <img
+ id="marker-pin"
+ src="images/map-pin.png"
+ height="32"
+ width="20"
+ onClick={() => addCoordinatesTooltip(reverseGeocodeResults)}
+ />
+ </>
+ );
+}
+
+LocationMarker.propTypes = {
+ reverseGeocodeResults: PropTypes.object,
+ addCoordinatesTooltip: PropTypes.func,
+};
diff --git a/web/js/map/ui.js b/web/js/map/ui.js
index 5751e906a..d0f9828ac 100644
--- a/web/js/map/ui.js
+++ b/web/js/map/ui.js
@@ -303,7 +303,7 @@ export default function mapui(models, config, store, ui) {
const removeCoordinatesMarker = () => {
if (self.activeMarker) {
self.activeMarker.setMap(null);
- self.selected.removeLayer(self.activeMarker);
+ self.selected.removeOverlay(self.activeMarker);
}
// remove tooltip from all projections
removeCoordinatesTooltip();
@@ -379,7 +379,7 @@ export default function mapui(models, config, store, ui) {
}
// clear previous marker (if present) and get new marker
removeCoordinatesMarker();
- const marker = getCoordinatesMarker(proj, coordinates, results);
+ const marker = getCoordinatesMarker(proj, coordinates, results, addCoordinatesTooltip);
// prevent marker if outside of extent
if (!marker) {
@@ -387,7 +387,7 @@ export default function mapui(models, config, store, ui) {
}
self.activeMarker = marker;
- self.selected.addLayer(marker);
+ self.selected.addOverlay(marker);
self.selected.renderSync();
if (shouldFlyToCoordinates) {
diff --git a/web/js/modules/location-search/util.js b/web/js/modules/location-search/util.js
index 0552e6520..f5bd0ed63 100644
--- a/web/js/modules/location-search/util.js
+++ b/web/js/modules/location-search/util.js
@@ -1,14 +1,10 @@
+import React from 'react';
+import ReactDOM from 'react-dom';
import update from 'immutability-helper';
import lodashIsNaN from 'lodash/isNaN';
-import OlPoint from 'ol/geom/Point';
-import OlFeature from 'ol/Feature';
-import OlLayerVector from 'ol/layer/Vector';
-import OlSourceVector from 'ol/source/Vector';
-import {
- Style as OlStyle,
- Icon as OlIcon,
-} from 'ol/style';
+import OlOverlay from 'ol/Overlay';
import { containsXY } from 'ol/extent';
+import LocationMarker from '../../components/location-search/location-marker';
import { coordinatesCRSTransform } from '../projection/util';
import safeLocalStorage from '../../util/local-storage';
import { fly } from '../../map/util';
@@ -56,7 +52,7 @@ export function areCoordinatesWithinExtent(proj, coordinates) {
* @param {Array} coordinates
* @param {Object} reverseGeocodeResults
*/
-export function getCoordinatesMarker(proj, coordinates, reverseGeocodeResults) {
+export function getCoordinatesMarker(proj, coordinates, reverseGeocodeResults, addCoordinatesTooltip) {
const { crs } = proj.selected;
// only add marker within current map extent
@@ -66,13 +62,13 @@ export function getCoordinatesMarker(proj, coordinates, reverseGeocodeResults) {
}
// transform coordinates if not CRS EPSG:4326
- let transformedCoordinates = false;
+ let transformedCoords = coordinates;
if (proj !== 'geographic') {
- transformedCoordinates = coordinatesCRSTransform(coordinates, 'EPSG:4326', crs);
+ transformedCoords = coordinatesCRSTransform(coordinates, 'EPSG:4326', crs);
}
// create Ol vector layer map pin
- const marker = createPin(coordinates, transformedCoordinates, reverseGeocodeResults);
+ const marker = createPin(transformedCoords, reverseGeocodeResults, addCoordinatesTooltip);
return marker;
}
@@ -82,37 +78,25 @@ export function getCoordinatesMarker(proj, coordinates, reverseGeocodeResults) {
* @param {Array} transformedCoordinates
* @param {Object} reverseGeocodeResults
*/
-const createPin = function(coordinates, transformedCoordinates = false, reverseGeocodeResults = {}) {
- const [longitude, latitude] = coordinates;
- const iconFeature = new OlFeature({
- geometry: new OlPoint(transformedCoordinates || coordinates),
- reverseGeocodeResults,
- latitude,
- longitude,
- });
-
- const iconStyle = new OlStyle({
- image: new OlIcon({
- anchorOrigin: 'bottom-left',
- anchorXUnits: 'fraction',
- anchorYUnits: 'pixels',
- scale: 0.5,
- src: 'images/map-pin.png',
+const createPin = function(coordinates, reverseGeocodeResults = {}, addCoordinatesTooltip) {
+ const overlayEl = document.createElement('div');
+ ReactDOM.render(
+ React.createElement(LocationMarker, {
+ reverseGeocodeResults,
+ coordinates,
+ addCoordinatesTooltip,
}),
+ overlayEl,
+ );
+ const markerPin = new OlOverlay({
+ element: overlayEl,
+ positioning: 'bottom-center',
+ stopEvent: false,
+ id: 'coordinates-map-pin',
});
+ markerPin.setPosition(coordinates);
- iconFeature.setStyle(iconStyle);
- iconFeature.setId('coordinates-map-marker');
-
- const vectorSource = new OlSourceVector({
- wrapX: false,
- features: [iconFeature],
- });
- const vectorLayer = new OlLayerVector({
- source: vectorSource,
- });
-
- return vectorLayer;
+ return markerPin;
};
/**