Subversion Repositories eFlore/Applications.cel

Compare Revisions

Ignore whitespace Rev 3868 → Rev 3869

/branches/v3.01-serpe/widget/modules/saisie/squelettes/js/tb-geoloc/js/Geoloc.js
202,7 → 202,6
this.onCoordinates();
};
 
 
Geoloc.prototype.reSetDrawControl = function() {
this.map.removeLayer(this.layer);
this.map.removeControl(this.drawControl);
360,7 → 359,7
Geoloc.prototype.formatPolyline = function (latLngs) {
const polyline = [];
 
latLngs.forEach(coordinates => polyline.push(Object.values(coordinates)));
latLngs.forEach(coordinates => polyline.push(Object.values(coordinates).reverse()));
 
return polyline;
};
409,7 → 408,9
url: url,
data: params,
success: function(locationData) {
lthis.loadGeolocation(coordinates,locationData,polyline);
locationData.centroid = lthis.formatPointTypeCoordinates(coordinates);
locationData.geojson = 'rue' === lthis.geometryFilter ? {type: 'LineString', coordinates: polyline} : locationData.centroid;
lthis.loadGeolocation(coordinates,locationData);
},
error: (err) => {
console.warn(err);
418,7 → 419,11
});
};
 
Geoloc.prototype.loadGeolocation = function(coordinates,locationData,polyline) {
Geoloc.prototype.formatPointTypeCoordinates = function(coordinates) {
return {type : 'Point', coordinates: Object.values(coordinates).reverse()};
};
 
Geoloc.prototype.loadGeolocation = function(coordinates,locationData) {
const lthis = this,
query = {
'lat': coordinates.lat,
431,7 → 436,7
data: query,
success: function (geoLocationData) {
lthis.triggerLocationEvent(
lthis.formatLocationEventObject(coordinates,geoLocationData,locationData,polyline)
lthis.formatLocationEventObject(locationData,geoLocationData)
);
lthis.geolocLabel.classList.remove('loading');
},
442,18 → 447,16
});
};
 
Geoloc.prototype.triggerLocationEvent = function (locationDataObject) {
const location = new CustomEvent('location', {detail: locationDataObject});
Geoloc.prototype.triggerLocationEvent = function(locationDataObject) {
const locationEvent = new CustomEvent('location', {detail: locationDataObject});
 
this.mapEl.dispatchEvent(location);
this.mapEl.dispatchEvent(locationEvent);
};
 
Geoloc.prototype.formatLocationEventObject = function(coordinates,geoLocationData,locationData,polyline) {
Geoloc.prototype.formatLocationEventObject = function(locationData,geoLocationData) {
const detail = {
centroid: {
type: 'Point',
coordinates: Object.values(coordinates)
},
centroid: locationData.centroid,
geometry: locationData.geojson,
elevation: geoLocationData.altitude,
inseeData: {
code: geoLocationData.code_zone,
462,7 → 465,7
osmCountry: locationData.address.country,
osmCountryCode: geoLocationData.code_pays,
osmCounty: locationData.address.county,
osmPostcode:locationData.address.postcode,
osmPostcode: locationData.address.postcode,
locality: this.getLocalityFromData(locationData),
locality: geoLocationData.nom,
osmRoad: locationData.address.road,
471,17 → 474,8
osmPlaceId: locationData.place_id
};
 
if (0 < polyline.length) {
detail.geometry = {
type: 'LineString',
coordinates: polyline
};
} else {
detail.geometry = detail.centroid;
}
 
return detail;
}
};
 
Geoloc.prototype.handleCoordinates = function() {
if (!!this.latitudeEl.value && !!this.longitudeEl.value) {
514,16 → 508,27
const locality = this.getLocalityFromData(localityData);
 
if(!!locality) {
const coordinates = {
const coordinates = this.formatCoordinates({
'lat' : localityData.lat,
'lng' : localityData.lon
};
});
 
if ('point' === this.geometryFilter) {
this.map.removeControl(this.drawControl);
if(!!coordinates && !!coordinates.lat && !!coordinates.lng) {
this.zoom = 20;
this.setMapCoordinates(coordinates);
 
if('point' === this.geometryFilter) {
this.map.removeControl(this.drawControl);
this.createDraggableMarker();
this.handleMarkerEvents();
}
 
localityData.centroid = this.formatPointTypeCoordinates(coordinates);
if('rue' !== this.geometryFilter && 'Polygon' === localityData.geojson.type ) {
localityData.geojson = localityData.centroid;
}
this.loadGeolocation(coordinates,localityData);
}
this.zoom = 18;
this.handleNewLocation(coordinates);
}
};
 
544,4 → 549,4
if (this.map != null) {
this.map._leaflet_id = null;
}
};
};