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'); |
}, |
443,17 → 448,15 |
}; |
|
Geoloc.prototype.triggerLocationEvent = function (locationDataObject) { |
const location = new CustomEvent('location', {detail: 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, |
471,18 → 474,9 |
osmPlaceId: locationData.place_id |
}; |
|
if (0 < polyline.length) { |
detail.geometry = { |
type: 'LineString', |
coordinates: polyline |
return detail; |
}; |
} else { |
detail.geometry = detail.centroid; |
} |
|
return detail; |
} |
|
Geoloc.prototype.handleCoordinates = function() { |
if (!!this.latitudeEl.value && !!this.longitudeEl.value) { |
this.handleNewLocation({ |
514,17 → 508,28 |
const locality = this.getLocalityFromData(localityData); |
|
if(!!locality) { |
const coordinates = { |
const coordinates = this.formatCoordinates({ |
'lat' : localityData.lat, |
'lng' : localityData.lon |
}; |
}); |
|
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(); |
} |
this.zoom = 18; |
this.handleNewLocation(coordinates); |
|
localityData.centroid = this.formatPointTypeCoordinates(coordinates); |
if('rue' !== this.geometryFilter && 'Polygon' === localityData.geojson.type ) { |
localityData.geojson = localityData.centroid; |
} |
this.loadGeolocation(coordinates,localityData); |
} |
} |
}; |
|
Geoloc.prototype.getLocalityFromData = function(localityData) { |