Skip to content
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

[DO NOT MERGE] ocha debugging #2371

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions static/css/browser.scss
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,5 @@
padding-top: 5px;
padding-bottom: 0px;
margin-bottom: -0.5rem;
height: 80vh;
}
64 changes: 43 additions & 21 deletions static/js/components/google_map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import axios from "axios";
import _ from "lodash";
import React from "react";
import { fetchGeoJsonData } from "../utils/subject_page_utils";

const DEFAULT_MAP_ZOOM = 4;
const MAP_BOUNDS_PADDING = 0;
Expand Down Expand Up @@ -77,6 +78,19 @@ interface GoogleMapStateType {
geoJson: object;
}

const MALFORMED_GEOJSON = {
"type": "FeatureCollection",
"features": []
};
const GENERATED_GEOJSON = {
"type": "FeatureCollection",
"features": []
};

const SELF_INTERSECTION_POINT = null;
const PLACE_DCID = "";
const PLACE_TYPE = "";

/**
* Initialize a google map widget.
* @param container the element to render the map in
Expand All @@ -91,6 +105,7 @@ function initMap(container: HTMLDivElement): google.maps.Map {
streetViewControl: false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: DEFAULT_MAP_ZOOM,
center: new google.maps.LatLng(0, 0)
};
return new google.maps.Map(container, mapOptions);
}
Expand Down Expand Up @@ -199,31 +214,38 @@ export class GoogleMap extends React.Component<
}

render(): JSX.Element {
if (!this.state.shouldShowMap) {
return null;
}
return <div className="map-container" ref={this.div}></div>;
}

componentDidMount(): void {
if (this.props.geoJsonGeometry) {
const geoJson = geoJsonFromGeometry(this.props.geoJsonGeometry);
this.setState({
shouldShowMap: true,
geoJson: geoJson,
});
} else if (this.props.latLong) {
const coordinates = {
lat: this.props.latLong[0],
lng: this.props.latLong[1],
};
this.setState({
markerLocation: coordinates,
shouldShowMap: true,
});
} else {
this.fetchData();
}
const map = initMap(this.div.current);
const geojsonPromise = PLACE_DCID && PLACE_TYPE ? fetchGeoJsonData({ dcid: PLACE_DCID, name: PLACE_DCID, types: [] }, PLACE_TYPE) : Promise.resolve({});
geojsonPromise.then(((geojson) => {
if (geojson) {
const dcLayer = new google.maps.Data();
dcLayer.addGeoJson(geojson)
dcLayer.setStyle({ fillColor: "green", strokeWeight: 0, fillOpacity: 1 });
dcLayer.setMap(map);
}
const generatedLayer = new google.maps.Data()
generatedLayer.addGeoJson(GENERATED_GEOJSON);
generatedLayer.addListener('click', function(event) {
console.log(event.feature.getProperty("wikiId"));
})
generatedLayer.setStyle({ fillColor: "blue" })
generatedLayer.setMap(map);
const malformedLayer = new google.maps.Data()
malformedLayer.addGeoJson(MALFORMED_GEOJSON);
malformedLayer.setStyle({fillColor: "red"});
malformedLayer.setMap(map);
malformedLayer.addListener('click', function(event) {
console.log(event.feature.getProperty("id"));
})

if (!_.isEmpty(SELF_INTERSECTION_POINT)) {
drawMarker(SELF_INTERSECTION_POINT, map)
}
}))
}

componentDidUpdate(): void {
Expand Down