408,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); |
417,7 → 419,11 |
}); |
}; |
|
Geoloc.prototype.loadGeolocation = function(coordinates,locationData,polyline) { |
Geoloc.prototype.formatPointTypeCoordinates = function(coordinates) { |
return {type : 'Point', coordinates: Object.values(coordinates)}; |
}; |
|
Geoloc.prototype.loadGeolocation = function(coordinates,locationData) { |
const lthis = this, |
query = { |
'lat': coordinates.lat, |
430,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'); |
}, |
441,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, |
461,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, |
470,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) { |
513,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); |
} |
}; |
|