Handle marker icons
This commit is contained in:
@@ -74,7 +74,7 @@
|
|||||||
|
|
||||||
router.get('/search', function () {
|
router.get('/search', function () {
|
||||||
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(req, res, next) {
|
var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee(req, res, next) {
|
||||||
var bounds, minPrice, maxPrice, minSize, maxSize, rooms, adType, category, sort, properties, query, _bounds$split$map, _bounds$split$map2, lat1, lng1, lat2, lng2, box, price, allRooms, or, size, allCategories, _or, all;
|
var bounds, minPrice, maxPrice, minSize, maxSize, rooms, adType, category, sort, properties, query, _bounds$split$map, _bounds$split$map2, lat1, lng1, lat2, lng2, box, price, and, allRooms, or, size, allCategories, _or, all;
|
||||||
|
|
||||||
return regeneratorRuntime.wrap(function _callee$(_context) {
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
||||||
while (1) {
|
while (1) {
|
||||||
@@ -130,6 +130,8 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
and = [];
|
||||||
|
|
||||||
if (rooms) {
|
if (rooms) {
|
||||||
allRooms = rooms.split(',');
|
allRooms = rooms.split(',');
|
||||||
or = allRooms.map(function (val) {
|
or = allRooms.map(function (val) {
|
||||||
@@ -146,9 +148,10 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
query = Object.assign(query, {
|
and.push({ "$or": or });
|
||||||
"$or": or
|
//query = Object.assign(query, {
|
||||||
});
|
//rooms:
|
||||||
|
//});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minSize || maxSize) {
|
if (minSize || maxSize) {
|
||||||
@@ -176,40 +179,47 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
and.push({ "$or": _or });
|
||||||
|
//query = Object.assign(query, {
|
||||||
|
//{"$or" : or }
|
||||||
|
//});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (and.length > 0) {
|
||||||
query = Object.assign(query, {
|
query = Object.assign(query, {
|
||||||
"$or": _or
|
"$and": and
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('QUERY: ', query);
|
console.log('QUERY: ', query);
|
||||||
_context.next = 21;
|
_context.next = 23;
|
||||||
return properties.find(query, {
|
return properties.find(query, {
|
||||||
//"sort": [['field1','asc'], ['field2','desc']]
|
//"sort": [['field1','asc'], ['field2','desc']]
|
||||||
"sort": [['price', 'asc']]
|
"sort": [['price', 'asc']]
|
||||||
}).toArray();
|
}).toArray();
|
||||||
|
|
||||||
case 21:
|
case 23:
|
||||||
all = _context.sent;
|
all = _context.sent;
|
||||||
|
|
||||||
|
|
||||||
res.json(all);
|
res.json(all);
|
||||||
res.end();
|
res.end();
|
||||||
_context.next = 30;
|
_context.next = 32;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 26:
|
case 28:
|
||||||
_context.prev = 26;
|
_context.prev = 28;
|
||||||
_context.t0 = _context['catch'](0);
|
_context.t0 = _context['catch'](0);
|
||||||
|
|
||||||
console.log('error:', _context.t0);
|
console.log('error:', _context.t0);
|
||||||
next(_context.t0);
|
next(_context.t0);
|
||||||
|
|
||||||
case 30:
|
case 32:
|
||||||
case 'end':
|
case 'end':
|
||||||
return _context.stop();
|
return _context.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, _callee, undefined, [[0, 26]]);
|
}, _callee, undefined, [[0, 28]]);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return function (_x, _x2, _x3) {
|
return function (_x, _x2, _x3) {
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ router.get('/search', async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const and = [];
|
||||||
if (rooms) {
|
if (rooms) {
|
||||||
const allRooms = rooms.split(',');
|
const allRooms = rooms.split(',');
|
||||||
const or = allRooms.map(val => {
|
const or = allRooms.map(val => {
|
||||||
@@ -75,9 +76,7 @@ router.get('/search', async (req, res, next) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
query = Object.assign(query, {
|
and.push({ "$or": or });
|
||||||
"$or": or
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (minSize || maxSize) {
|
if (minSize || maxSize) {
|
||||||
@@ -103,8 +102,12 @@ router.get('/search', async (req, res, next) => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
and.push({ "$or": or });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (and.length > 0) {
|
||||||
query = Object.assign(query, {
|
query = Object.assign(query, {
|
||||||
"$or": or
|
"$and": and
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,15 @@ export default class Listings extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMouseEnter (id) {
|
||||||
|
this.props.dispatch({
|
||||||
|
type: 'ON_LISTING_MOUSE_OVER',
|
||||||
|
action: {
|
||||||
|
id
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
renderListings () {
|
renderListings () {
|
||||||
const {listings = (new Map())} = this.props;
|
const {listings = (new Map())} = this.props;
|
||||||
|
|
||||||
@@ -22,8 +31,9 @@ export default class Listings extends React.Component {
|
|||||||
rendered.push(
|
rendered.push(
|
||||||
<div
|
<div
|
||||||
key={l._id}
|
key={l._id}
|
||||||
|
onMouseEnter={this.onMouseEnter.bind(this, l._id)}
|
||||||
className="property-list-item"
|
className="property-list-item"
|
||||||
onClick={this.onListingClick.bind(this, l.url)}>
|
onClick={this.onListingClick.bind(this, l._id)}>
|
||||||
<div className="pli-image">
|
<div className="pli-image">
|
||||||
<img src={images[0]} alt=""></img>
|
<img src={images[0]} alt=""></img>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -112,6 +112,15 @@ class Main extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findMarker (id) {
|
||||||
|
if (!this.markers) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const index = this.markers.findIndex(m => m.id === id);
|
||||||
|
return this.markers[index];
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Refreshes search
|
* Refreshes search
|
||||||
*/
|
*/
|
||||||
@@ -138,8 +147,9 @@ class Main extends React.Component {
|
|||||||
category
|
category
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const markerExists = (id) => {
|
const markerExists = (id) => {
|
||||||
return (this.markers || []).findIndex(m => m.id === id) !== -1;
|
return this.findMarker(id) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
properties.then(p => p.text()).then(p => {
|
properties.then(p => p.text()).then(p => {
|
||||||
@@ -168,18 +178,42 @@ class Main extends React.Component {
|
|||||||
for(const [index, prop] of data.entries()) {
|
for(const [index, prop] of data.entries()) {
|
||||||
const myLatLng = {lat: prop.loc[0], lng: prop.loc[1]};
|
const myLatLng = {lat: prop.loc[0], lng: prop.loc[1]};
|
||||||
|
|
||||||
if (!markerExists(p._id)) {
|
if (!markerExists(prop._id)) {
|
||||||
|
|
||||||
const marker = new google.maps.Marker({
|
const marker = new google.maps.Marker({
|
||||||
position: myLatLng,
|
position : myLatLng,
|
||||||
map: map,
|
map : map,
|
||||||
title: prop.title
|
title : prop.title,
|
||||||
|
icon : this.defaultMarkerIcon(),
|
||||||
|
id : prop._id
|
||||||
|
});
|
||||||
|
|
||||||
|
marker.addListener('mouseover', () => {
|
||||||
|
if (marker.id !== this.state.listingId) {
|
||||||
|
marker.setIcon(this.hoveredMarkerIcon());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
marker.addListener('mouseout', () => {
|
||||||
|
if (marker.id !== this.state.listingId) {
|
||||||
|
marker.setIcon(this.defaultMarkerIcon());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
marker.addListener('click', () => {
|
marker.addListener('click', () => {
|
||||||
console.log('clicking...')
|
console.log('clicking...', prop._id);
|
||||||
|
if (this.state.listingId) {
|
||||||
|
const prevSelected = this.findMarker(this.state.listingId);
|
||||||
|
if (prevSelected) {
|
||||||
|
console.log('prevselected', prevSelected);
|
||||||
|
prevSelected.marker.setIcon(this.defaultMarkerIcon());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
marker.setIcon(this.selectedMarkerIcon());
|
||||||
this.dispatch({type: 'VIEW_LISTING_DETAILS', action: {
|
this.dispatch({type: 'VIEW_LISTING_DETAILS', action: {
|
||||||
id: prop.url
|
id: prop._id
|
||||||
}})
|
}});
|
||||||
});
|
});
|
||||||
|
|
||||||
newMarkers.push({
|
newMarkers.push({
|
||||||
@@ -211,6 +245,57 @@ class Main extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get default marker icon
|
||||||
|
*/
|
||||||
|
defaultMarkerIcon () {
|
||||||
|
const sf = 0.5;
|
||||||
|
const width = 48;
|
||||||
|
const height = 64;
|
||||||
|
const icon = {
|
||||||
|
url : "static/images/pins_sprite.png",
|
||||||
|
size : new google.maps.Size(width * sf, height * sf),
|
||||||
|
scaledSize : new google.maps.Size(730 * sf, 102 * sf),
|
||||||
|
origin : new google.maps.Point(0, 36 * sf)
|
||||||
|
}
|
||||||
|
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hovered marker icon
|
||||||
|
*/
|
||||||
|
hoveredMarkerIcon () {
|
||||||
|
const sf = 0.5;
|
||||||
|
const width = 61;
|
||||||
|
const height = 82;
|
||||||
|
const icon = {
|
||||||
|
url : "static/images/pins_sprite.png",
|
||||||
|
size : new google.maps.Size(width * sf, height * sf),
|
||||||
|
scaledSize : new google.maps.Size(730 * sf, 102 * sf),
|
||||||
|
origin : new google.maps.Point(303 * sf, 18 * sf)
|
||||||
|
}
|
||||||
|
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Selected marker icon
|
||||||
|
*/
|
||||||
|
selectedMarkerIcon () {
|
||||||
|
const sf = 0.5;
|
||||||
|
const width = 73;
|
||||||
|
const height = 100;
|
||||||
|
const icon = {
|
||||||
|
url : "static/images/pins_sprite.png",
|
||||||
|
size : new google.maps.Size(width * sf, height * sf),
|
||||||
|
scaledSize : new google.maps.Size(730 * sf, 102 * sf),
|
||||||
|
origin : new google.maps.Point(655 * sf, 1 * sf)
|
||||||
|
}
|
||||||
|
|
||||||
|
return icon;
|
||||||
|
}
|
||||||
|
|
||||||
renderRightContent() {
|
renderRightContent() {
|
||||||
|
|
||||||
const children = [];
|
const children = [];
|
||||||
|
|||||||
BIN
web/dist/static/images/pins_sprite.png
vendored
Normal file
BIN
web/dist/static/images/pins_sprite.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 20 KiB |
@@ -55,7 +55,7 @@ const listingsLoaded = ({ type, action }, component) => {
|
|||||||
const currentListings = new Map();
|
const currentListings = new Map();
|
||||||
|
|
||||||
for (const listing of action.listings) {
|
for (const listing of action.listings) {
|
||||||
currentListings.set(listing.url, listing);
|
currentListings.set(listing._id, listing);
|
||||||
}
|
}
|
||||||
|
|
||||||
component.setState({
|
component.setState({
|
||||||
@@ -151,7 +151,20 @@ const setCategory = ({type, action}, component) => {
|
|||||||
component.refreshListings();
|
component.refreshListings();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
const onListingMouseOver = ({type, action}, component) => {
|
||||||
|
const marker = component.findMarker(action.id);
|
||||||
|
if (marker) {
|
||||||
|
marker.marker.setIcon(component.hoveredMarkerIcon());
|
||||||
|
marker.marker.setAnimation(google.maps.Animation.BOUNCE);
|
||||||
|
setTimeout(() => {
|
||||||
|
marker.marker.setAnimation(null);
|
||||||
|
marker.marker.setIcon(component.defaultMarkerIcon());
|
||||||
|
} , 710);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
const handlers = {
|
const handlers = {
|
||||||
SET_MIN_PRICE: setMinPrice,
|
SET_MIN_PRICE: setMinPrice,
|
||||||
@@ -167,7 +180,8 @@ const handlers = {
|
|||||||
SET_ROOMS: setRooms,
|
SET_ROOMS: setRooms,
|
||||||
VIEW_LISTING_DETAILS: viewListingDetails,
|
VIEW_LISTING_DETAILS: viewListingDetails,
|
||||||
UPDATE_SEARCH: updateSearch,
|
UPDATE_SEARCH: updateSearch,
|
||||||
SET_CATEGORY: setCategory
|
SET_CATEGORY: setCategory,
|
||||||
|
ON_LISTING_MOUSE_OVER: onListingMouseOver
|
||||||
};
|
};
|
||||||
|
|
||||||
export const handleMessage = ({ type, action }, component) => {
|
export const handleMessage = ({ type, action }, component) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user