forked from 0x2620/oxjs
more fixes
This commit is contained in:
parent
bcade5f2d7
commit
f3e0632f0e
4 changed files with 39 additions and 16 deletions
|
|
@ -595,10 +595,17 @@ Ox.Map = function(options, self) {
|
||||||
self.boundsChanged = true;
|
self.boundsChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toSpan(bounds) {
|
||||||
|
return {
|
||||||
|
lat: bounds._ne.lat - bounds._sw.lat,
|
||||||
|
lng: bounds._ne.lng - bounds._sw.lng,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function canContain(outerBounds, innerBounds) {
|
function canContain(outerBounds, innerBounds) {
|
||||||
// checks if outerBounds _can_ contain innerBounds
|
// checks if outerBounds _can_ contain innerBounds
|
||||||
var outerSpan = outerBounds.toSpan(),
|
var outerSpan = toSpan(outerBounds),
|
||||||
innerSpan = innerBounds.toSpan();
|
innerSpan = toSpan(innerBounds);
|
||||||
return outerSpan.lat > innerSpan.lat &&
|
return outerSpan.lat > innerSpan.lat &&
|
||||||
outerSpan.lng > innerSpan.lng;
|
outerSpan.lng > innerSpan.lng;
|
||||||
}
|
}
|
||||||
|
|
@ -614,6 +621,8 @@ Ox.Map = function(options, self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function clickMap(event) {
|
function clickMap(event) {
|
||||||
|
console.log("not this one", event)
|
||||||
|
return
|
||||||
var place = getSelectedPlace();
|
var place = getSelectedPlace();
|
||||||
if (self.options.clickable/* && !editing()*/) {
|
if (self.options.clickable/* && !editing()*/) {
|
||||||
getPlaceByLatLng(event.lngLat, self.map.getBounds(), function(place) {
|
getPlaceByLatLng(event.lngLat, self.map.getBounds(), function(place) {
|
||||||
|
|
@ -753,19 +762,19 @@ Ox.Map = function(options, self) {
|
||||||
self.$loadingIcon && self.$loadingIcon.start();
|
self.$loadingIcon && self.$loadingIcon.start();
|
||||||
var results = await reverseGeocode(latlng);
|
var results = await reverseGeocode(latlng);
|
||||||
self.$loadingIcon && self.$loadingIcon.stop();
|
self.$loadingIcon && self.$loadingIcon.stop();
|
||||||
if (true) {
|
if (results.features.length) {
|
||||||
if (bounds) {
|
if (bounds) {
|
||||||
Ox.forEach(results, function(result, i) {
|
Ox.forEach(results.features, function(result, i) {
|
||||||
if (
|
if (
|
||||||
i == results.length - 1 ||
|
i == results.length - 1 ||
|
||||||
canContain(bounds, result.geometry.bounds || result.geometry.viewport)
|
canContain(bounds, result.bounds)
|
||||||
) {
|
) {
|
||||||
callback(new Ox.MapPlace(parseGeodata(results[i])));
|
callback(new Ox.MapPlace(parseGeodata(result)));
|
||||||
return false; // break
|
return false; // break
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
callback(new Ox.MapPlace(parseGeodata(results[0])));
|
callback(new Ox.MapPlace(parseGeodata(results.features[0])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!results.length) {
|
if (!results.length) {
|
||||||
|
|
@ -1151,7 +1160,7 @@ Ox.Map = function(options, self) {
|
||||||
function parseGeodata(data) {
|
function parseGeodata(data) {
|
||||||
console.log("parseGeodata", data)
|
console.log("parseGeodata", data)
|
||||||
// FIXME: data is geojson Feature with Polygon geometry now
|
// FIXME: data is geojson Feature with Polygon geometry now
|
||||||
var bounds = data.bounds || data.geometry.bounds || data.geometry.viewport,
|
var bounds = data.bounds,
|
||||||
northEast = bounds._ne,
|
northEast = bounds._ne,
|
||||||
southWest = bounds._sw,
|
southWest = bounds._sw,
|
||||||
place = {
|
place = {
|
||||||
|
|
@ -1472,6 +1481,8 @@ Ox.Map = function(options, self) {
|
||||||
// someone may want to cache google geocode data, so we fire an event.
|
// someone may want to cache google geocode data, so we fire an event.
|
||||||
// google puts functions like lat or lng on the objects' prototypes,
|
// google puts functions like lat or lng on the objects' prototypes,
|
||||||
// so we create properly named properties, for json encoding
|
// so we create properly named properties, for json encoding
|
||||||
|
console.log(data)
|
||||||
|
/*
|
||||||
if (data.latLng) {
|
if (data.latLng) {
|
||||||
data.latLng = {
|
data.latLng = {
|
||||||
lat: data.latLng.lat,
|
lat: data.latLng.lat,
|
||||||
|
|
@ -1500,6 +1511,7 @@ Ox.Map = function(options, self) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
that.triggerEvent('geocode', data);
|
that.triggerEvent('geocode', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,8 +51,8 @@ Ox.MapMarker = function(options) {
|
||||||
element.style.width = element.style.height = that.size + 'px'
|
element.style.width = element.style.height = that.size + 'px'
|
||||||
that.marker = new maplibregl.Marker({
|
that.marker = new maplibregl.Marker({
|
||||||
raiseOnDrag: false,
|
raiseOnDrag: false,
|
||||||
shape: {coords: [8, 8, 8], type: 'circle'},
|
|
||||||
element: element,
|
element: element,
|
||||||
|
//shape: {coords: [8, 8, 8], type: 'circle'},
|
||||||
//title: that.place.name,
|
//title: that.place.name,
|
||||||
//zIndex: 1000
|
//zIndex: 1000
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -140,8 +140,11 @@ class MapLibreRectangle {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_enableClicking() {
|
_enableClicking() {
|
||||||
this.map.on('click', `${this.id}-fill`, e => {
|
this.map.on('click', `rectangles-fill`, e => {
|
||||||
|
console.log('click', e)
|
||||||
if (this.onclick) {
|
if (this.onclick) {
|
||||||
|
e.preventDefault()
|
||||||
|
//e.stopPropagation()
|
||||||
this.onclick(e)
|
this.onclick(e)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -219,7 +222,6 @@ Ox.MapRectangle = function(options) {
|
||||||
|
|
||||||
function click(e) {
|
function click(e) {
|
||||||
console.log('rectangle click', e)
|
console.log('rectangle click', e)
|
||||||
return
|
|
||||||
if (
|
if (
|
||||||
that.map.options('editable')
|
that.map.options('editable')
|
||||||
&& that.place.editable
|
&& that.place.editable
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ Ox.MapRectangleMarker = function(options) {
|
||||||
type: that.place.id[0] == '_' ? 'result' : 'place'
|
type: that.place.id[0] == '_' ? 'result' : 'place'
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
that.marker.setLngLat(that.place.points[that.position])
|
||||||
|
|
||||||
function dragstart(e) {
|
function dragstart(e) {
|
||||||
Ox.$body.addClass('OxDragging');
|
Ox.$body.addClass('OxDragging');
|
||||||
|
|
@ -101,10 +102,13 @@ Ox.MapRectangleMarker = function(options) {
|
||||||
add <f> add
|
add <f> add
|
||||||
@*/
|
@*/
|
||||||
that.add = function() {
|
that.add = function() {
|
||||||
that.marker.setMap(that.map.map);
|
that.marker.addTo(that.map.map);
|
||||||
|
console.log("add marker, fix events")
|
||||||
|
/*
|
||||||
google.maps.event.addListener(that.marker, 'dragstart', dragstart);
|
google.maps.event.addListener(that.marker, 'dragstart', dragstart);
|
||||||
google.maps.event.addListener(that.marker, 'drag', drag);
|
google.maps.event.addListener(that.marker, 'drag', drag);
|
||||||
google.maps.event.addListener(that.marker, 'dragend', dragend);
|
google.maps.event.addListener(that.marker, 'dragend', dragend);
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
|
|
@ -112,21 +116,26 @@ Ox.MapRectangleMarker = function(options) {
|
||||||
@*/
|
@*/
|
||||||
that.remove = function() {
|
that.remove = function() {
|
||||||
that.marker.remove();
|
that.marker.remove();
|
||||||
google.maps.event.clearListeners(that.marker);
|
console.log("remove marker, fix events")
|
||||||
|
//google.maps.event.clearListeners(that.marker);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*@
|
/*@
|
||||||
update <f> update
|
update <f> update
|
||||||
@*/
|
@*/
|
||||||
that.update = function() {
|
that.update = function() {
|
||||||
that.marker.setOptions({
|
marker = new maplibregl.Marker({
|
||||||
icon: Ox.MapMarkerImage({
|
cursor: that.position + '-resize',
|
||||||
|
draggable: true,
|
||||||
|
element: Ox.MapMarkerImage({
|
||||||
mode: 'editing',
|
mode: 'editing',
|
||||||
rectangle: true,
|
rectangle: true,
|
||||||
type: that.place.id[0] == '_' ? 'result' : 'place'
|
type: that.place.id[0] == '_' ? 'result' : 'place'
|
||||||
}),
|
}),
|
||||||
position: that.place.points[that.position]
|
|
||||||
});
|
});
|
||||||
|
marker.setLngLat(that.place.points[that.position])
|
||||||
|
that.marker.remove()
|
||||||
|
that.marker = marker
|
||||||
};
|
};
|
||||||
|
|
||||||
return that;
|
return that;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue