{
static dataStore = dataStore;
private map: any;
private left: () => JSX.Element;
private right: () => JSX.Element;
private header: () => JSX.Element;
private footer: () => JSX.Element;
private rightRail: () => JSX.Element;
constructor() {
super();
this.search = this.search.bind(this);
this.callback = this.callback.bind(this);
this.initMap = this.initMap.bind(this);
this.state = {
display: []
};
this.header = () => (
Scroll the map and search
);
this.left =
databind(
dataStore.talks.registerFacet(['collection_l1_ss']),
dataStore.talks,
(data: [string, number, boolean][]) => (
label + ': ' + value.toLocaleString()}
/>
)
);
const databindTalksQuery =
(fn: ((talks: Talk[], pagination: PaginationData) => JSX.Element)) =>
databind(
dataStore.talks.onQuery,
dataStore.talks,
fn);
this.right = databindTalksQuery(
(talks: Talk[], pagination: PaginationData) => {
return (
);
}
);
}
callback(results: string[], status: string) {
const self = this;
const google: PlacesApi = _.get(window, 'google');
if (status === google.maps.places.PlacesServiceStatus.OK) {
const display = _.sortedUniq(
results.map(
(result) =>
_.get(result, 'name', '')
.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/ig, ' ')
.replace(/\b(Inc|St|Av)\b/ig, ' ')
.replace(/\b(Charter School|Public School|Junior High School|Station|High School of .*)\b/ig, ' ')
.replace(/\b(Preparatory School|Library|City Hall|Academy Preschool|Transportation Center)\b/ig, ' ')
.replace(/\b(School|Institute|Post Office|College|Hospital|University|High School)\b/ig, ' ')
.replace(/\b(United States Postal Service|Mail Parcel Service|Mail Center|Historical Society)\b/ig, '')
.replace(/\b(at|and|the|of|Foundation|Services|Academy)\b/ig, ' ')
.replace(/[ ]+/ig, ' ')
.split(' ')
.filter(
(token) =>
!token.match(/^[0-9]/) && // numbered streets
token.length > 1 && // N/S/W/E
token.toUpperCase() !== token // removes train station tokens
).join(
' '
)
).concat(this.state.display)
).filter(
(name) => name.indexOf(' ') > 0
);
self.setState( {
display
});
dataStore.talks.doQuery({
query: (
'"' + (display.join('"~1 "')).replace(/ /g, '%20') + '"'
)
});
}
}
initMap() {
const self = this;
const google: PlacesApi = _.get(window, 'google');
if (!google) {
setTimeout(this.initMap, 50);
return;
}
const start = {lat: 39.9779964, lng: -75.1486154};
this.map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: start
});
google.maps.event.addListener(self.map, 'idle', function() {
// self.center = self.map.getCenter();
self.setState({display: []});
self.search();
});
/*var marker = new google.maps.Marker({
position: start,
map: map
});*/
}
componentDidMount() {
setTimeout(this.initMap, 0);
}
search() {
const self = this;
const google: PlacesApi = _.get(window, 'google');
const map = this.map;
[
'school',
// 'courthouse', these don't have special names
// 'airport',
// 'library',
'subway_station',
'local_government_office',
'train_station',
'transit_station',
// 'city_hall',
'neighborhood'
// 'post_office'
].map(
(type) => {
const bounds = map['getBounds']();
const top = bounds.getNorthEast();
const bottom = bounds.getSouthWest();
const r = Math.round(measure(top.lat(), top.lng(), bottom.lat(), bottom.lng())) + '';
const request = {
location: map['getCenter'](),
radius: r,
type: type
};
const service = new google.maps.places.PlacesService(self.map);
service.nearbySearch(request, this.callback);
}
);
}
render() {
return (
);
}
}
interface PlacesApi {
maps: {
LatLng: any;
Map: any;
event: {
addListener: any;
}
places: {
PlacesService: any;
PlacesServiceStatus: {
OK: string;
}
}
};
}
class MapApp extends React.Component<{}, {}> {
constructor() {
super();
}
render() {
return (
);
}
}
export { MapApp as MapPage };