chairemobilite / evolution

Online survey platform for travel survey
MIT License
4 stars 9 forks source link

inputMap: Put imprecise location and zooms too large directly in the widget #673

Open tahini opened 2 months ago

tahini commented 2 months ago

I'm not sure if we can integrate any widget-specific validations in the global process of validating an interview, but there is some code that should be used in most inputMapFindPlace widgets:

 invalidGeocodingResultTypes: [
        'political',
        'country',
        'administrative_area_level_1',
        'administrative_area_level_2',
        'administrative_area_level_3',
        'administrative_area_level_4',
        'administrative_area_level_5',
        'administrative_area_level_6',
        'administrative_area_level_7',
        'colloquial_area',
        'locality',
        'sublocality',
        'sublocality_level_1',
        'sublocality_level_2',
        'sublocality_level_3',
        'sublocality_level_4',
        'sublocality_level_5',
        'neighborhood',
        'route'
  ],
  validations: (value, _customValue, interview, path) => {
      const homeGeography: any = surveyHelperNew.getResponse(interview, path as string, null);
     ...
      const geocodingTextInput = homeGeography ? homeGeography.properties?.geocodingQueryString : undefined;

      return [
         ... other validations,
          {
              validation:
                  homeGeography &&
                  homeGeography.properties.lastAction &&
                  (homeGeography.properties.lastAction === 'mapClicked' ||
                      homeGeography.properties.lastAction === 'markerDragged') &&
                  homeGeography.properties.zoom < 14,
              errorMessage: {
                  fr: "Le positionnement du lieu n'est pas assez précis. Utilisez le zoom + pour vous rapprocher davantage, puis précisez la localisation en déplaçant l'icône.",
                  en: 'The positioning of the place is not precise enough. Please use the + zoom and drag the icon marker to confirm the precise location.'
              }
          },
          {
              validation:
              homeGeography &&
              homeGeography.properties.isGeocodingImprecise,
              errorMessage: {
                  fr: `<strong>Le nom du lieu utilisé pour effectuer la recherche ${
                      !_isBlank(geocodingTextInput) ? `("${geocodingTextInput}")` : ''
                  } n'est pas assez précis.</strong> Ajoutez de l'information ou précisez l'emplacement à l'aide de la carte.`,
                  en: `<strong>The location name used for searching ${
                      !_isBlank(geocodingTextInput) ? `("${geocodingTextInput}")` : ''
                  } is not specific enough.</strong> Please add more information or specify the location more precisely using the map.`
              }
          }
      ];
  },
samuel-duhaime commented 2 months ago

In what case do we need something like administrative_area_level_5 ?

tahini commented 2 months ago

In what case do we need something like administrative_area_level_5 ?

These are part of the Google API and represent place types. The invalidGeocodingResultTypes means that if results that come back from Google are of this type, then they should not be taken to represent the place because they are too imprecise, I'm not sure what administrative_area_level_5 represents, but for instance, the city of Sherbrooke is of type locality, so if the query returned this result, even if it returns a single point, this point is not located is a precise enough place to be considered valid geolocation.