api.reverseGeocode(lnglat[0], lnglat[1], function (error, location) { if (error) { console.error(error); } if (location) { selectedObject.humanReadableName = 'Near ' + location.shortName; } // Let the app know that we've selected something. mapView.objectSelected(selectedObject, scroll); // Let the app know that the selection is ready. $.publish('selectionReady', [selectedObject]); });
function selectParcel(event) { // Clear the selection styling of the previous feature. if (!page.multi && selection) { selection.feature.properties.selected = false; } // Select the current layer var selectedFeature = event.target.feature; // If we've already selected this object, then remove it from the selection. if (page.multi) { var partitions = _.partition(selection, function (item) { return item.feature.id === selectedFeature.id; }); var removal = partitions[0]; selection = partitions[1]; if (removal.length > 0) { deselectParcels(removal); return; } } selectedFeature.properties.selected = true; var selectedObject = { feature: selectedFeature, id: selectedFeature.id, // Store the human-readable name (often the address). humanReadableName: (selectedFeature.properties.address || // parcels endpoint selectedFeature.properties.shortName) // features endpoint }; if (!selectedObject.humanReadableName) { selectedObject.humanReadableName = 'Unknown Location'; } // Store the centroid. if (selectedFeature.properties.centroid !== undefined) { selectedObject.centroid = selectedFeature.properties.centroid; } else { selectedObject.centroid = { type: 'Point', coordinates: computeCentroid(selectedFeature.geometry) }; } // If the base feature has other info properties, store those. if (selectedFeature.properties.info !== undefined) { selectedObject.info = selectedFeature.properties.info; } selectedObject.geometry = selectedFeature.geometry; // If there is an address associated with the selected object, save that. // TODO: For now, if the survey type is "address", we assume the object // name indicates the address. // TODO: This is Houston-specific for beta testing. if (settings.survey.type === 'address') { var address = selectedFeature.properties.address; var city = 'houston'; if (address.length > city.length && address.substr(address.length - city.length).toLocaleLowerCase() === city) { selectedObject.address = address.substr(0, address.length - city.length - 1).titleCase(); } } // Now that we definitely know the centroid coordinates, let the mapView // react visually. mapView.objectSelected(selectedObject, true); if (page.multi) { selection.push(selectedObject); } else { selection = selectedObject; } updateComponents(); }