Subversion Repositories eFlore/Applications.cel

Rev

Rev 3862 | Rev 3867 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3862 Rev 3866
Line 406... Line 406...
406
    $.ajax({
406
    $.ajax({
407
        method: "GET",
407
        method: "GET",
408
        url: url,
408
        url: url,
409
        data: params,
409
        data: params,
410
        success: function(locationData) {
410
        success: function(locationData) {
-
 
411
            locationData.centroid = lthis.formatPointTypeCoordinates(coordinates);
-
 
412
            locationData.geojson = 'rue' === lthis.geometryFilter ? {type: 'LineString', coordinates: polyline} : locationData.centroid;
411
            lthis.loadGeolocation(coordinates,locationData,polyline);
413
            lthis.loadGeolocation(coordinates,locationData);
412
        },
414
        },
413
        error: (err) => {
415
        error: (err) => {
414
            console.warn(err);
416
            console.warn(err);
415
            lthis.geolocLabel.classList.remove('loading');
417
            lthis.geolocLabel.classList.remove('loading');
416
        }
418
        }
417
    });
419
    });
418
};
420
};
Line -... Line 421...
-
 
421
 
-
 
422
Geoloc.prototype.formatPointTypeCoordinates = function(coordinates) {
-
 
423
    return {type : 'Point', coordinates: Object.values(coordinates)};
-
 
424
};
419
 
425
 
420
Geoloc.prototype.loadGeolocation = function(coordinates,locationData,polyline) {
426
Geoloc.prototype.loadGeolocation = function(coordinates,locationData) {
421
    const lthis = this,
427
    const lthis = this,
422
        query = {
428
        query = {
423
            'lat': coordinates.lat,
429
            'lat': coordinates.lat,
424
            'lon': coordinates.lng
430
            'lon': coordinates.lng
Line 428... Line 434...
428
        method: "GET",
434
        method: "GET",
429
        url: URL_GEOLOC_SERVICE,
435
        url: URL_GEOLOC_SERVICE,
430
        data: query,
436
        data: query,
431
        success: function (geoLocationData) {
437
        success: function (geoLocationData) {
432
            lthis.triggerLocationEvent(
438
            lthis.triggerLocationEvent(
433
                lthis.formatLocationEventObject(coordinates,geoLocationData,locationData,polyline)
439
                lthis.formatLocationEventObject(locationData,geoLocationData)
434
            );
440
            );
435
            lthis.geolocLabel.classList.remove('loading');
441
            lthis.geolocLabel.classList.remove('loading');
436
        },
442
        },
437
        error:  (err) => {
443
        error:  (err) => {
438
            console.warn(err);
444
            console.warn(err);
439
            lthis.geolocLabel.classList.remove('loading');
445
            lthis.geolocLabel.classList.remove('loading');
440
        }
446
        }
441
    });
447
    });
442
};
448
};
Line 443... Line 449...
443
 
449
 
444
Geoloc.prototype.triggerLocationEvent = function (locationDataObject) {
450
Geoloc.prototype.triggerLocationEvent = function(locationDataObject) {
Line 445... Line 451...
445
    const location = new CustomEvent('location', {detail: locationDataObject});
451
    const locationEvent = new CustomEvent('location', {detail: locationDataObject});
446
 
452
 
Line 447... Line 453...
447
    this.mapEl.dispatchEvent(location);
453
    this.mapEl.dispatchEvent(locationEvent);
448
};
454
};
449
 
455
 
450
Geoloc.prototype.formatLocationEventObject = function(coordinates,geoLocationData,locationData,polyline) {
456
Geoloc.prototype.formatLocationEventObject = function(locationData,geoLocationData) {
451
    const detail = {
-
 
452
        centroid: {
-
 
453
            type: 'Point',
457
    const detail = {
454
            coordinates: Object.values(coordinates)
458
        centroid: locationData.centroid,
455
        },
459
        geometry: locationData.geojson,
456
        elevation: geoLocationData.altitude,
460
        elevation: geoLocationData.altitude,
457
        inseeData: {
461
        inseeData: {
458
            code: geoLocationData.code_zone,
462
            code: geoLocationData.code_zone,
459
            nom: geoLocationData.nom
463
            nom: geoLocationData.nom
460
        },
464
        },
461
        osmCountry: locationData.address.country,
465
        osmCountry: locationData.address.country,
462
        osmCountryCode: geoLocationData.code_pays,
466
        osmCountryCode: geoLocationData.code_pays,
463
        osmCounty: locationData.address.county,
467
        osmCounty: locationData.address.county,
464
        osmPostcode:locationData.address.postcode,
468
        osmPostcode: locationData.address.postcode,
465
        locality: this.getLocalityFromData(locationData),
469
        locality: this.getLocalityFromData(locationData),
466
        locality: geoLocationData.nom,
470
        locality: geoLocationData.nom,
467
        osmRoad: locationData.address.road,
471
        osmRoad: locationData.address.road,
468
        osmState: locationData.address.state,
472
        osmState: locationData.address.state,
Line 469... Line -...
469
        osmId: locationData.osm_id,
-
 
470
        osmPlaceId: locationData.place_id
-
 
471
    };
-
 
472
 
-
 
473
    if (0 < polyline.length) {
-
 
474
        detail.geometry = {
-
 
475
            type: 'LineString',
-
 
476
            coordinates: polyline
-
 
477
        };
-
 
478
    } else {
473
        osmId: locationData.osm_id,
479
        detail.geometry = detail.centroid;
474
        osmPlaceId: locationData.place_id
Line 480... Line 475...
480
    }
475
    };
481
 
476
 
482
    return detail;
477
    return detail;
483
}
478
};
Line 511... Line 506...
511
 
506
 
512
Geoloc.prototype.tbPlacesCallback = function(localityData) {
507
Geoloc.prototype.tbPlacesCallback = function(localityData) {
Line 513... Line 508...
513
    const locality = this.getLocalityFromData(localityData);
508
    const locality = this.getLocalityFromData(localityData);
514
 
509
 
515
    if(!!locality) {
510
    if(!!locality) {
516
        const coordinates = {
511
        const coordinates = this.formatCoordinates({
517
            'lat' : localityData.lat,
512
            'lat' : localityData.lat,
Line -... Line 513...
-
 
513
            'lng' : localityData.lon
-
 
514
        });
-
 
515
 
-
 
516
        if(!!coordinates && !!coordinates.lat && !!coordinates.lng) {
518
            'lng' : localityData.lon
517
            this.zoom = 20;
519
        };
518
            this.setMapCoordinates(coordinates);
-
 
519
 
-
 
520
            if('point' === this.geometryFilter) {
-
 
521
                this.map.removeControl(this.drawControl);
-
 
522
                this.createDraggableMarker();
-
 
523
                this.handleMarkerEvents();
-
 
524
            }
-
 
525
 
-
 
526
            localityData.centroid = this.formatPointTypeCoordinates(coordinates);
-
 
527
            if('rue' !== this.geometryFilter && 'Polygon' === localityData.geojson.type ) {
520
 
528
                localityData.geojson = localityData.centroid;
521
        if ('point' === this.geometryFilter) {
-
 
522
            this.map.removeControl(this.drawControl);
-
 
523
        }
529
            }
524
        this.zoom = 18;
530
            this.loadGeolocation(coordinates,localityData);
Line 525... Line 531...
525
        this.handleNewLocation(coordinates);
531
        }
526
    }
532
    }