Compare commits
2 commits
8dbfcc0ece
...
f3e0632f0e
| Author | SHA1 | Date | |
|---|---|---|---|
| f3e0632f0e | |||
| bcade5f2d7 |
6 changed files with 89 additions and 16 deletions
13
examples/maps/map_editor/index.html
Normal file
13
examples/maps/map_editor/index.html
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>World Map with Countries</title>
|
||||
<meta http-equiv="Keywords" content="Lists"/>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
|
||||
<link rel="shortcut icon" type="image/png" href="../../../source/UI/themes/oxlight/png/icon16.png"/>
|
||||
<script type="text/javascript" src="../../../dev/Ox.js"></script>
|
||||
<script type="text/javascript" src="js/example.js"></script>
|
||||
<script>window.addEventListener('message', function(e) { e.origin == window.location.origin && eval('(' + e.data + ')'); });</script>
|
||||
</head>
|
||||
<body></body>
|
||||
</html>
|
||||
37
examples/maps/map_editor/js/example.js
Normal file
37
examples/maps/map_editor/js/example.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
In this example, we use Ox.MapEditor
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
Ox.load(['UI', 'Geo'], function() {
|
||||
var $map = Ox.MapEditor({
|
||||
addPlace: function(place, callback) {
|
||||
console.log("addPlace", place)
|
||||
},
|
||||
editPlace: function(place, callback) {
|
||||
console.log("editPlace", place)
|
||||
},
|
||||
getMatches: function(names, callback) {
|
||||
console.log("getMatches", names)
|
||||
callback(23);
|
||||
},
|
||||
hasMatches: true, // FIXME: getMatches is enough
|
||||
height: 800,
|
||||
mode: 'add', // 'define',
|
||||
names: null,
|
||||
places: [],
|
||||
removePlace: function(place, callback) {
|
||||
console.log("removePlace", place)
|
||||
},
|
||||
selected: '',
|
||||
showControls: false,
|
||||
showLabels: false,
|
||||
showTypes: true,
|
||||
width: 600
|
||||
})
|
||||
.appendTo(Ox.$body);
|
||||
|
||||
Ox.$window.bind({resize: $map.resizeMap});
|
||||
|
||||
});
|
||||
|
|
@ -595,10 +595,17 @@ Ox.Map = function(options, self) {
|
|||
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) {
|
||||
// checks if outerBounds _can_ contain innerBounds
|
||||
var outerSpan = outerBounds.toSpan(),
|
||||
innerSpan = innerBounds.toSpan();
|
||||
var outerSpan = toSpan(outerBounds),
|
||||
innerSpan = toSpan(innerBounds);
|
||||
return outerSpan.lat > innerSpan.lat &&
|
||||
outerSpan.lng > innerSpan.lng;
|
||||
}
|
||||
|
|
@ -614,6 +621,8 @@ Ox.Map = function(options, self) {
|
|||
}
|
||||
|
||||
function clickMap(event) {
|
||||
console.log("not this one", event)
|
||||
return
|
||||
var place = getSelectedPlace();
|
||||
if (self.options.clickable/* && !editing()*/) {
|
||||
getPlaceByLatLng(event.lngLat, self.map.getBounds(), function(place) {
|
||||
|
|
@ -753,19 +762,19 @@ Ox.Map = function(options, self) {
|
|||
self.$loadingIcon && self.$loadingIcon.start();
|
||||
var results = await reverseGeocode(latlng);
|
||||
self.$loadingIcon && self.$loadingIcon.stop();
|
||||
if (true) {
|
||||
if (results.features.length) {
|
||||
if (bounds) {
|
||||
Ox.forEach(results, function(result, i) {
|
||||
Ox.forEach(results.features, function(result, i) {
|
||||
if (
|
||||
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
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback(new Ox.MapPlace(parseGeodata(results[0])));
|
||||
callback(new Ox.MapPlace(parseGeodata(results.features[0])));
|
||||
}
|
||||
}
|
||||
if (!results.length) {
|
||||
|
|
@ -1151,7 +1160,7 @@ Ox.Map = function(options, self) {
|
|||
function parseGeodata(data) {
|
||||
console.log("parseGeodata", data)
|
||||
// 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,
|
||||
southWest = bounds._sw,
|
||||
place = {
|
||||
|
|
@ -1472,6 +1481,8 @@ Ox.Map = function(options, self) {
|
|||
// someone may want to cache google geocode data, so we fire an event.
|
||||
// google puts functions like lat or lng on the objects' prototypes,
|
||||
// so we create properly named properties, for json encoding
|
||||
console.log(data)
|
||||
/*
|
||||
if (data.latLng) {
|
||||
data.latLng = {
|
||||
lat: data.latLng.lat,
|
||||
|
|
@ -1500,6 +1511,7 @@ Ox.Map = function(options, self) {
|
|||
}
|
||||
}
|
||||
});
|
||||
*/
|
||||
that.triggerEvent('geocode', data);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,8 +51,8 @@ Ox.MapMarker = function(options) {
|
|||
element.style.width = element.style.height = that.size + 'px'
|
||||
that.marker = new maplibregl.Marker({
|
||||
raiseOnDrag: false,
|
||||
shape: {coords: [8, 8, 8], type: 'circle'},
|
||||
element: element,
|
||||
//shape: {coords: [8, 8, 8], type: 'circle'},
|
||||
//title: that.place.name,
|
||||
//zIndex: 1000
|
||||
});
|
||||
|
|
|
|||
|
|
@ -140,8 +140,11 @@ class MapLibreRectangle {
|
|||
});
|
||||
}
|
||||
_enableClicking() {
|
||||
this.map.on('click', `${this.id}-fill`, e => {
|
||||
this.map.on('click', `rectangles-fill`, e => {
|
||||
console.log('click', e)
|
||||
if (this.onclick) {
|
||||
e.preventDefault()
|
||||
//e.stopPropagation()
|
||||
this.onclick(e)
|
||||
}
|
||||
})
|
||||
|
|
@ -219,7 +222,6 @@ Ox.MapRectangle = function(options) {
|
|||
|
||||
function click(e) {
|
||||
console.log('rectangle click', e)
|
||||
return
|
||||
if (
|
||||
that.map.options('editable')
|
||||
&& that.place.editable
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ Ox.MapRectangleMarker = function(options) {
|
|||
type: that.place.id[0] == '_' ? 'result' : 'place'
|
||||
}),
|
||||
});
|
||||
that.marker.setLngLat(that.place.points[that.position])
|
||||
|
||||
function dragstart(e) {
|
||||
Ox.$body.addClass('OxDragging');
|
||||
|
|
@ -101,10 +102,13 @@ Ox.MapRectangleMarker = function(options) {
|
|||
add <f> add
|
||||
@*/
|
||||
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, 'drag', drag);
|
||||
google.maps.event.addListener(that.marker, 'dragend', dragend);
|
||||
*/
|
||||
};
|
||||
|
||||
/*@
|
||||
|
|
@ -112,21 +116,26 @@ Ox.MapRectangleMarker = function(options) {
|
|||
@*/
|
||||
that.remove = function() {
|
||||
that.marker.remove();
|
||||
google.maps.event.clearListeners(that.marker);
|
||||
console.log("remove marker, fix events")
|
||||
//google.maps.event.clearListeners(that.marker);
|
||||
};
|
||||
|
||||
/*@
|
||||
update <f> update
|
||||
@*/
|
||||
that.update = function() {
|
||||
that.marker.setOptions({
|
||||
icon: Ox.MapMarkerImage({
|
||||
marker = new maplibregl.Marker({
|
||||
cursor: that.position + '-resize',
|
||||
draggable: true,
|
||||
element: Ox.MapMarkerImage({
|
||||
mode: 'editing',
|
||||
rectangle: true,
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue