Skip to content

Commit

Permalink
Merge pull request #887 from theduckylittle/gm-333/move-location-to-s…
Browse files Browse the repository at this point in the history
…ketch-layer

Place find me results on the sketch layer
  • Loading branch information
klassenjs authored Nov 8, 2024
2 parents ad5c24e + 287a79e commit dbc885b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
23 changes: 12 additions & 11 deletions src/gm3/reducers/mapSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,19 @@ const reducer = createReducer(
state[mapSourceName].featuresVersion = 0;
}

// copy assumes a raw dump where the ID does not matter.
for (let i = 0, ii = features.length; !copy && i < ii; i++) {
features[i] = {
...features[i],
properties: {
...features[i].properties,
[ID_PROP]: uuid(),
},
};
}
// ensure features are a list.
const inFeatures = Array.isArray(features) ? features : [features];
const nextFeatures = copy
? inFeatures
: inFeatures.map((feature) => ({
...feature,
properties: {
...feature.properties,
[ID_PROP]: uuid(),
},
}));
state[mapSourceName].features =
state[mapSourceName].features.concat(features);
state[mapSourceName].features.concat(nextFeatures);
state[mapSourceName].featuresVersion += 1;
},
[clearFeatures]: (state, { payload: mapSourceName }) => {
Expand Down
12 changes: 7 additions & 5 deletions src/services/findme.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2017 Dan "Ducky" Little
* Copyright (c) 2016-2024 Dan "Ducky" Little
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -31,7 +31,7 @@
function FindMeAction(Application, options) {

// allow the targetting of a layer, but default to the highlight layer
this.targetLayer = options.targetLayer ? options.targetLayer : 'results/results';
this.targetLayer = options.targetLayer ? options.targetLayer : 'sketch/default';

// default the map projection to web-mercator
this.mapProjection = options.mapProjection ? options.mapProjection : 'EPSG:3857';
Expand All @@ -50,7 +50,11 @@ function FindMeAction(Application, options) {
*/
this.run = function(selection, fields) {
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(this.gotoPosition.bind(this), (e) => { console.error(e); alert("Find Me: " + e.message); }, { enableHighAccuracy: true });
navigator.geolocation.getCurrentPosition(
this.gotoPosition.bind(this),
(e) => { console.error(e); alert("Find Me: " + e.message); },
{ enableHighAccuracy: true }
);
} else {
alert('Geolocation is not supported.');
}
Expand All @@ -76,8 +80,6 @@ function FindMeAction(Application, options) {
// put the feature in map projection.
var map_feature = gm3.util.projectFeatures([fake_feature], 'EPSG:4326', this.mapProjection)[0];

Application.clearFeatures(this.targetLayer);

// mark the location in the highlight layer
Application.addFeatures(this.targetLayer, map_feature);

Expand Down

0 comments on commit dbc885b

Please sign in to comment.