-
Notifications
You must be signed in to change notification settings - Fork 0
feat: geofence-based geographic targeting for programs #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 19.0
Are you sure you want to change the base?
Changes from all commits
48fa97b
fb3d0f0
535c5a4
9d970a6
b71955e
eda39a4
debda8d
d750b6a
407cc86
d764a57
3b1faba
7fb4faf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,9 @@ export class FieldGisEditMap extends Component { | |
| }); | ||
|
|
||
| onMounted(async () => { | ||
| maptilersdk.config.apiKey = this.mapTilerKey; | ||
| if (this.mapTilerKey) { | ||
| maptilersdk.config.apiKey = this.mapTilerKey; | ||
| } | ||
| const editInfo = await this.orm.call( | ||
| this.props.record.resModel, | ||
| "get_edit_info_for_gis_column", | ||
|
|
@@ -67,11 +69,9 @@ export class FieldGisEditMap extends Component { | |
| if (response.mapTilerKey) { | ||
| this.mapTilerKey = response.mapTilerKey; | ||
| this.webBaseUrl = response.webBaseUrl; | ||
| } else { | ||
| console.log("Error: Api Key not found."); | ||
| } | ||
| } catch (error) { | ||
| console.error("Error fetching environment variable:", error); | ||
| console.warn("Could not fetch MapTiler API key:", error); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -86,6 +86,34 @@ export class FieldGisEditMap extends Component { | |
| } | ||
| } | ||
|
|
||
| _getMapStyle() { | ||
| if (this.mapTilerKey) { | ||
| return maptilersdk.MapStyle.STREETS; | ||
| } | ||
| // Fallback: OSM raster tiles (no API key required) | ||
| return { | ||
| version: 8, | ||
| sources: { | ||
| osm: { | ||
| type: "raster", | ||
| tiles: ["https://tile.openstreetmap.org/{z}/{x}/{y}.png"], | ||
| tileSize: 256, | ||
| attribution: | ||
| '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors', | ||
| }, | ||
| }, | ||
| layers: [ | ||
| { | ||
| id: "osm-tiles", | ||
| type: "raster", | ||
| source: "osm", | ||
| minzoom: 0, | ||
| maxzoom: 19, | ||
| }, | ||
| ], | ||
| }; | ||
| } | ||
|
|
||
| renderMap() { | ||
| if (this.props.record.data[this.props.name]) { | ||
| const obj = JSON.parse(this.props.record.data[this.props.name]); | ||
|
|
@@ -104,9 +132,14 @@ export class FieldGisEditMap extends Component { | |
| this.defaultZoom = 10; | ||
| } | ||
|
|
||
| if (this.map) { | ||
| this.draw = null; | ||
| this.map.remove(); | ||
| } | ||
|
|
||
| this.map = new maptilersdk.Map({ | ||
| container: this.id, | ||
| style: maptilersdk.MapStyle.STREETS, | ||
| style: this._getMapStyle(), | ||
| center: this.defaultCenter, | ||
| zoom: this.defaultZoom, | ||
| }); | ||
|
|
@@ -199,7 +232,9 @@ export class FieldGisEditMap extends Component { | |
| } | ||
|
|
||
| removeSourceAndLayer(source) { | ||
| this.map.removeLayer(source); | ||
| this.map.removeLayer(`${source}-polygon-layerid`); | ||
| this.map.removeLayer(`${source}-point-layerid`); | ||
| this.map.removeLayer(`${source}-linestring-layerid`); | ||
| this.map.removeSource(source); | ||
| } | ||
|
|
||
|
|
@@ -213,13 +248,16 @@ export class FieldGisEditMap extends Component { | |
| const self = this; | ||
|
|
||
| function updateArea(e) { | ||
| console.log(e); | ||
| var data = self.draw.getAll(); | ||
| self.props.record.update({ | ||
| [self.props.name]: JSON.stringify(data.features[0].geometry), | ||
| }); | ||
| } | ||
|
Comment on lines
250
to
255
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Additionally, the function updateArea(e) {
const features = e.features;
if (features && features.length > 0) {
self.props.record.update({
[self.props.name]: JSON.stringify(features[0].geometry),
});
}
} |
||
|
|
||
| if (this.draw) { | ||
| this.map.removeControl(this.draw); | ||
| } | ||
|
|
||
| this.draw = new MapboxDraw({ | ||
| displayControlsDefault: false, | ||
| controls: { | ||
|
|
@@ -246,17 +284,6 @@ export class FieldGisEditMap extends Component { | |
|
|
||
| this.map.on("draw.create", updateArea); | ||
| this.map.on("draw.update", updateArea); | ||
|
|
||
| const url = `/spp_gis/static/src/images/laos_farm.png`; | ||
|
|
||
| this.map.on("click", `${this.sourceId}-polygon-layerid`, (e) => { | ||
| new maptilersdk.Popup() | ||
| .setLngLat(e.lngLat) | ||
| .setHTML( | ||
| `<img src="${url}" height="200" width="300" alt="Placeholder Image">` | ||
| ) | ||
| .addTo(this.map); | ||
| }); | ||
| } | ||
|
|
||
| addDrawInteractionStyle() { | ||
|
|
@@ -370,7 +397,6 @@ export class FieldGisEditMap extends Component { | |
| const customMode = {}; | ||
| const self = this; | ||
| customMode.onTrash = function (state) { | ||
| console.log(state); | ||
| self.props.record.update({[self.props.name]: null}); | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code to generate the fallback OpenStreetMap map style object is duplicated from
spp_gis/static/src/js/views/gis/gis_renderer/gis_renderer.esm.js. To improve maintainability and avoid inconsistencies, this object could be defined as a constant or returned by a utility function in a shared file, and then imported in bothfield_gis_edit_map.esm.jsandgis_renderer.esm.js.