|
|
|
@ -6,24 +6,21 @@ const util = require('util');
|
|
|
|
|
|
|
|
|
|
var $ = require('jquery');
|
|
|
|
|
L.ParkingSpot = L.Circle.extend({
|
|
|
|
|
options: {
|
|
|
|
|
id: 'Custom data!',
|
|
|
|
|
attributes: {}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
createDirection: function () {
|
|
|
|
|
if (this.direction === undefined ) {
|
|
|
|
|
var start = this._latlng;
|
|
|
|
|
var options = { units: 'kilometers' };
|
|
|
|
|
var end = turf.destination([start.lat, start.lng], this.options.attributes.radius / 1000, this.options.attributes.heading - 180, options);
|
|
|
|
|
// Resize, since leaflet is wrong
|
|
|
|
|
var rad2 = start.distanceTo(end.geometry.coordinates);
|
|
|
|
|
|
|
|
|
|
var end = turf.destination([start.lng, start.lat], this.options.attributes.radius / 1000, this.options.attributes.heading - 180, options);
|
|
|
|
|
// Resize, since leaflet is wrong
|
|
|
|
|
var rad2 = start.distanceTo(this.turfToLatLng(end), options);
|
|
|
|
|
console.debug('Dist ', start, [start.lng, start.lat], end.geometry.coordinates, this.options.attributes.radius, rad2);
|
|
|
|
|
this.setRadius(rad2);
|
|
|
|
|
// console.log(util.inspect(this.editor));
|
|
|
|
|
if(this.editor._resizeLatLng.__vertex !== undefined){
|
|
|
|
|
this.editor._resizeLatLng.__vertex.setLatLng(end.geometry.coordinates);
|
|
|
|
|
this.editor._resizeLatLng.__vertex.setLatLng(this.turfToLatLng(end));
|
|
|
|
|
}
|
|
|
|
|
this.direction = L.polyline([start, end.geometry.coordinates]);
|
|
|
|
|
this.direction = L.polyline([start, this.turfToLatLng(end)]);
|
|
|
|
|
this.direction.addTo(this.editor.editLayer);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -37,26 +34,28 @@ L.ParkingSpot = L.Circle.extend({
|
|
|
|
|
if (this.editEnabled()) {
|
|
|
|
|
var start = this._latlng;
|
|
|
|
|
var options = { units: 'kilometers' };
|
|
|
|
|
var end = turf.destination([start.lat, start.lng], this.options.attributes.radius / 1000, this.options.attributes.heading - 180, options);
|
|
|
|
|
var end = turf.destination([start.lng, start.lat], this.options.attributes.radius / 1000, this.options.attributes.heading - 180, options);
|
|
|
|
|
// Resize, since leaflet is wrong
|
|
|
|
|
var rad2 = start.distanceTo(end.geometry.coordinates);
|
|
|
|
|
var rad2 = start.distanceTo(this.turfToLatLng(end), options);
|
|
|
|
|
this.setRadius(rad2);
|
|
|
|
|
if(this.editor._resizeLatLng.__vertex!== undefined){
|
|
|
|
|
this.editor._resizeLatLng.__vertex.setLatLng(end.geometry.coordinates);
|
|
|
|
|
this.editor._resizeLatLng.__vertex.setLatLng(this.turfToLatLng(end));
|
|
|
|
|
}
|
|
|
|
|
this.direction.setLatLngs([start, end.geometry.coordinates]);
|
|
|
|
|
this.direction.setLatLngs([start, this.turfToLatLng(end)]);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
updateDirectionFromVertex: function () {
|
|
|
|
|
if (this.editEnabled()) {
|
|
|
|
|
var start = this._latlng;
|
|
|
|
|
var end = this.editor._resizeLatLng.__vertex.getLatLng();
|
|
|
|
|
var heading = turf.bearing([start.lat, start.lng], [end.lat, end.lng]);
|
|
|
|
|
var heading = turf.bearing([start.lng, start.lat], [end.lng, end.lat]);
|
|
|
|
|
this.options.attributes.heading = heading + 180;
|
|
|
|
|
this.direction.setLatLngs([start, end]);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
turfToLatLng: function (turfPoint) {
|
|
|
|
|
return {lat: turfPoint.geometry.coordinates[1], lng: turfPoint.geometry.coordinates[0]};
|
|
|
|
|
},
|
|
|
|
|
extensions: function () {
|
|
|
|
|
this.createDirection();
|
|
|
|
|
},
|
|
|
|
@ -77,10 +76,7 @@ var parkingSpot = function (n, layerGroup) {
|
|
|
|
|
var latlon = convert(n.attr('lat') + " " + n.attr('lon'));
|
|
|
|
|
//console.log(latlon.decimalLatitude);
|
|
|
|
|
//console.log(convert(n.attr('lat') + " " + n.attr('lon')).decimalLongitude);
|
|
|
|
|
const circle = new L.ParkingSpot([latlon.decimalLatitude, latlon.decimalLongitude], { radius: n.attr('radius') });
|
|
|
|
|
circle.on('add', function (event) {
|
|
|
|
|
console.log(event);
|
|
|
|
|
});
|
|
|
|
|
const circle = new L.ParkingSpot([latlon.decimalLatitude, latlon.decimalLongitude], { radius_m: n.attr('radius'), attributes: {} });
|
|
|
|
|
circle.on('editable:enable', function (event) {
|
|
|
|
|
// event.target.createDirection();
|
|
|
|
|
});
|
|
|
|
@ -100,7 +96,7 @@ airlineCodes="VIR,KAL,DAL,KLM" />
|
|
|
|
|
//circle.attributes = { type: n.attr('type'), name: n.attr('name'), radius: Number(n.attr('radius')), airlineCodes: n.attr('airlineCodes'), heading: Number(n.attr('heading')) };
|
|
|
|
|
|
|
|
|
|
$.each( n.attrs, function( key, value ) {
|
|
|
|
|
console.log( key + "\t" + value);
|
|
|
|
|
console.log( '$', circle.id, key , value);
|
|
|
|
|
|
|
|
|
|
if(isNaN(value))
|
|
|
|
|
circle.options.attributes[ key ] = value;
|
|
|
|
|