Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 3864 Rev 3869
Line 200... Line 200...
200
        });
200
        });
201
    }
201
    }
202
    this.onCoordinates();
202
    this.onCoordinates();
203
};
203
};
Line 204... Line -...
204
 
-
 
205
 
204
 
206
Geoloc.prototype.reSetDrawControl = function() {
205
Geoloc.prototype.reSetDrawControl = function() {
207
    this.map.removeLayer(this.layer);
206
    this.map.removeLayer(this.layer);
208
    this.map.removeControl(this.drawControl);
207
    this.map.removeControl(this.drawControl);
209
    this.setDrawControl(this.map);
208
    this.setDrawControl(this.map);
Line 358... Line 357...
358
};
357
};
Line 359... Line 358...
359
 
358
 
360
Geoloc.prototype.formatPolyline = function (latLngs) {
359
Geoloc.prototype.formatPolyline = function (latLngs) {
Line 361... Line 360...
361
    const polyline = [];
360
    const polyline = [];
Line 362... Line 361...
362
 
361
 
363
    latLngs.forEach(coordinates => polyline.push(Object.values(coordinates)));
362
    latLngs.forEach(coordinates => polyline.push(Object.values(coordinates).reverse()));
Line 364... Line 363...
364
 
363
 
Line 407... Line 406...
407
    $.ajax({
406
    $.ajax({
408
        method: "GET",
407
        method: "GET",
409
        url: url,
408
        url: url,
410
        data: params,
409
        data: params,
411
        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;
412
            lthis.loadGeolocation(coordinates,locationData,polyline);
413
            lthis.loadGeolocation(coordinates,locationData);
413
        },
414
        },
414
        error: (err) => {
415
        error: (err) => {
415
            console.warn(err);
416
            console.warn(err);
416
            lthis.geolocLabel.classList.remove('loading');
417
            lthis.geolocLabel.classList.remove('loading');
417
        }
418
        }
418
    });
419
    });
419
};
420
};
Line -... Line 421...
-
 
421
 
-
 
422
Geoloc.prototype.formatPointTypeCoordinates = function(coordinates) {
-
 
423
    return {type : 'Point', coordinates: Object.values(coordinates).reverse()};
-
 
424
};
420
 
425
 
421
Geoloc.prototype.loadGeolocation = function(coordinates,locationData,polyline) {
426
Geoloc.prototype.loadGeolocation = function(coordinates,locationData) {
422
    const lthis = this,
427
    const lthis = this,
423
        query = {
428
        query = {
424
            'lat': coordinates.lat,
429
            'lat': coordinates.lat,
425
            'lon': coordinates.lng
430
            'lon': coordinates.lng
Line 429... Line 434...
429
        method: "GET",
434
        method: "GET",
430
        url: URL_GEOLOC_SERVICE,
435
        url: URL_GEOLOC_SERVICE,
431
        data: query,
436
        data: query,
432
        success: function (geoLocationData) {
437
        success: function (geoLocationData) {
433
            lthis.triggerLocationEvent(
438
            lthis.triggerLocationEvent(
434
                lthis.formatLocationEventObject(coordinates,geoLocationData,locationData,polyline)
439
                lthis.formatLocationEventObject(locationData,geoLocationData)
435
            );
440
            );
436
            lthis.geolocLabel.classList.remove('loading');
441
            lthis.geolocLabel.classList.remove('loading');
437
        },
442
        },
438
        error:  (err) => {
443
        error:  (err) => {
439
            console.warn(err);
444
            console.warn(err);
440
            lthis.geolocLabel.classList.remove('loading');
445
            lthis.geolocLabel.classList.remove('loading');
441
        }
446
        }
442
    });
447
    });
443
};
448
};
Line 444... Line 449...
444
 
449
 
445
Geoloc.prototype.triggerLocationEvent = function (locationDataObject) {
450
Geoloc.prototype.triggerLocationEvent = function(locationDataObject) {
Line 446... Line 451...
446
    const location = new CustomEvent('location', {detail: locationDataObject});
451
    const locationEvent = new CustomEvent('location', {detail: locationDataObject});
447
 
452
 
Line 448... Line 453...
448
    this.mapEl.dispatchEvent(location);
453
    this.mapEl.dispatchEvent(locationEvent);
449
};
454
};
450
 
455
 
451
Geoloc.prototype.formatLocationEventObject = function(coordinates,geoLocationData,locationData,polyline) {
456
Geoloc.prototype.formatLocationEventObject = function(locationData,geoLocationData) {
452
    const detail = {
-
 
453
        centroid: {
-
 
454
            type: 'Point',
457
    const detail = {
455
            coordinates: Object.values(coordinates)
458
        centroid: locationData.centroid,
456
        },
459
        geometry: locationData.geojson,
457
        elevation: geoLocationData.altitude,
460
        elevation: geoLocationData.altitude,
458
        inseeData: {
461
        inseeData: {
459
            code: geoLocationData.code_zone,
462
            code: geoLocationData.code_zone,
460
            nom: geoLocationData.nom
463
            nom: geoLocationData.nom
461
        },
464
        },
462
        osmCountry: locationData.address.country,
465
        osmCountry: locationData.address.country,
463
        osmCountryCode: geoLocationData.code_pays,
466
        osmCountryCode: geoLocationData.code_pays,
464
        osmCounty: locationData.address.county,
467
        osmCounty: locationData.address.county,
465
        osmPostcode:locationData.address.postcode,
468
        osmPostcode: locationData.address.postcode,
466
        locality: this.getLocalityFromData(locationData),
469
        locality: this.getLocalityFromData(locationData),
467
        locality: geoLocationData.nom,
470
        locality: geoLocationData.nom,
468
        osmRoad: locationData.address.road,
471
        osmRoad: locationData.address.road,
469
        osmState: locationData.address.state,
472
        osmState: locationData.address.state,
Line 470... Line -...
470
        osmId: locationData.osm_id,
-
 
471
        osmPlaceId: locationData.place_id
-
 
472
    };
-
 
473
 
-
 
474
    if (0 < polyline.length) {
-
 
475
        detail.geometry = {
-
 
476
            type: 'LineString',
-
 
477
            coordinates: polyline
-
 
478
        };
-
 
479
    } else {
473
        osmId: locationData.osm_id,
480
        detail.geometry = detail.centroid;
474
        osmPlaceId: locationData.place_id
Line 481... Line 475...
481
    }
475
    };
482
 
476
 
483
    return detail;
477
    return detail;
484
}
478
};
Line 512... Line 506...
512
 
506
 
513
Geoloc.prototype.tbPlacesCallback = function(localityData) {
507
Geoloc.prototype.tbPlacesCallback = function(localityData) {
Line 514... Line 508...
514
    const locality = this.getLocalityFromData(localityData);
508
    const locality = this.getLocalityFromData(localityData);
515
 
509
 
516
    if(!!locality) {
510
    if(!!locality) {
517
        const coordinates = {
511
        const coordinates = this.formatCoordinates({
518
            'lat' : localityData.lat,
512
            'lat' : localityData.lat,
Line -... Line 513...
-
 
513
            'lng' : localityData.lon
-
 
514
        });
-
 
515
 
-
 
516
        if(!!coordinates && !!coordinates.lat && !!coordinates.lng) {
519
            'lng' : localityData.lon
517
            this.zoom = 20;
520
        };
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 ) {
521
 
528
                localityData.geojson = localityData.centroid;
522
        if ('point' === this.geometryFilter) {
-
 
523
            this.map.removeControl(this.drawControl);
-
 
524
        }
529
            }
525
        this.zoom = 18;
530
            this.loadGeolocation(coordinates,localityData);
Line 526... Line 531...
526
        this.handleNewLocation(coordinates);
531
        }
527
    }
532
    }
Line 542... Line 547...
542
    // reset map
547
    // reset map
543
    this.map = L.DomUtil.get(this.mapIdAttr);
548
    this.map = L.DomUtil.get(this.mapIdAttr);
544
    if (this.map != null) {
549
    if (this.map != null) {
545
        this.map._leaflet_id = null;
550
        this.map._leaflet_id = null;
546
    }
551
    }
547
};
-
 
548
552
};
-
 
553