Merge PR 1649 from deltaidea
This commit is contained in:
@@ -418,18 +418,36 @@ def create_marker_from_filter_result(poi, result):
|
|||||||
else: # ...otherwise default to display text.
|
else: # ...otherwise default to display text.
|
||||||
d['hovertext'] = result['text']
|
d['hovertext'] = result['text']
|
||||||
|
|
||||||
if 'polyline' in result and hasattr(result['polyline'], '__iter__'):
|
if "icon" in result:
|
||||||
d['polyline'] = []
|
d["icon"] = result['icon']
|
||||||
for point in result['polyline']:
|
if "createInfoWindow" in result:
|
||||||
# point.copy() would work, but this validates better
|
d["createInfoWindow"] = result['createInfoWindow']
|
||||||
d['polyline'].append(dict(x=point['x'], y=point['y'], z=point['z']))
|
|
||||||
if isinstance(result['color'], str):
|
|
||||||
d['strokeColor'] = result['color']
|
|
||||||
|
|
||||||
if "icon" in result:
|
# Polylines and polygons
|
||||||
d["icon"] = result['icon']
|
if ('polyline' in result and hasattr(result['polyline'], '__iter__')) or \
|
||||||
if "createInfoWindow" in result:
|
'polygon' in result and hasattr(result['polygon'], '__iter__'):
|
||||||
d["createInfoWindow"] = result['createInfoWindow']
|
# If the points form a line or closed shape
|
||||||
|
d['isLine'] = 'polyline' in result
|
||||||
|
# Collect points
|
||||||
|
d['points'] = []
|
||||||
|
for point in (result['polyline'] if d['isLine'] else result['polygon']):
|
||||||
|
d['points'].append(dict(x=point['x'], y=point['y'], z=point['z']))
|
||||||
|
|
||||||
|
# Options and default values
|
||||||
|
if 'color' in result:
|
||||||
|
d['strokeColor'] = result['color']
|
||||||
|
else:
|
||||||
|
d['strokeColor'] = 'red'
|
||||||
|
|
||||||
|
if 'fill' in result:
|
||||||
|
d['fill'] = result['fill']
|
||||||
|
else:
|
||||||
|
d['fill'] = not d['isLine'] # fill polygons by default
|
||||||
|
|
||||||
|
if 'weight' in result:
|
||||||
|
d['strokeWeight'] = result['weight']
|
||||||
|
else:
|
||||||
|
d['strokeWeight'] = 2
|
||||||
else:
|
else:
|
||||||
raise ValueError("Got an %s as result for POI with id %s"
|
raise ValueError("Got an %s as result for POI with id %s"
|
||||||
% (type(result).__name__, poi['id']))
|
% (type(result).__name__, poi['id']))
|
||||||
|
|||||||
@@ -379,27 +379,48 @@ overviewer.util = {
|
|||||||
console.log("this tileset has markers:", obj);
|
console.log("this tileset has markers:", obj);
|
||||||
obj.marker_groups = {};
|
obj.marker_groups = {};
|
||||||
|
|
||||||
|
// For every group of markers
|
||||||
for (var mkidx = 0; mkidx < markers[obj.path].length; mkidx++) {
|
for (var mkidx = 0; mkidx < markers[obj.path].length; mkidx++) {
|
||||||
|
// Create a Leaflet layer group
|
||||||
var marker_group = new L.layerGroup();
|
var marker_group = new L.layerGroup();
|
||||||
var marker_entry = markers[obj.path][mkidx];
|
var marker_entry = markers[obj.path][mkidx];
|
||||||
L.Util.setOptions(marker_group, {default_checked: marker_entry.checked});
|
L.Util.setOptions(marker_group, {default_checked: marker_entry.checked});
|
||||||
var icon = L.divIcon({html: `<img class="ov-marker" src="${marker_entry.icon}">`});
|
var icon = L.divIcon({html: `<img class="ov-marker" src="${marker_entry.icon}">`});
|
||||||
|
|
||||||
|
// For every marker in group
|
||||||
for (var dbidx = 0; dbidx < markersDB[marker_entry.groupName].raw.length; dbidx++) {
|
for (var dbidx = 0; dbidx < markersDB[marker_entry.groupName].raw.length; dbidx++) {
|
||||||
var db = markersDB[marker_entry.groupName].raw[dbidx];
|
let db = markersDB[marker_entry.groupName].raw[dbidx];
|
||||||
var latlng = overviewer.util.fromWorldToLatLng(db.x, db.y, db.z, obj);
|
var layerObj = undefined;
|
||||||
var m_icon;
|
|
||||||
if (db.icon != undefined) {
|
// Shape or marker?
|
||||||
m_icon = L.divIcon({html: `<img class="ov-marker" src="${db.icon}">`});
|
if ('points' in db) {
|
||||||
|
// Convert all coords
|
||||||
|
plLatLng = db['points'].map(function(p) {
|
||||||
|
return overviewer.util.fromWorldToLatLng(p.x, p.y, p.z, obj);
|
||||||
|
});
|
||||||
|
options = {
|
||||||
|
color: db['strokeColor'],
|
||||||
|
weight: db['strokeWeight'],
|
||||||
|
fill: db['fill']
|
||||||
|
};
|
||||||
|
layerObj = db['isLine'] ? L.polyline(plLatLng, options) : L.polygon(plLatLng, options);
|
||||||
|
// TODO: add other config options (fill color, fill opacity)
|
||||||
} else {
|
} else {
|
||||||
m_icon = icon;
|
// Convert coords
|
||||||
|
let latlng = overviewer.util.fromWorldToLatLng(db.x, db.y, db.z, obj);
|
||||||
|
// Set icon and use default icon if not specified
|
||||||
|
let m_icon = L.divIcon({html: `<img class="ov-marker" src="${db.icon == undefined ? marker_entry.icon : db.icon}">`});
|
||||||
|
// Create marker
|
||||||
|
layerObj = new L.marker(latlng, {icon: m_icon, title: db.hovertext});
|
||||||
}
|
}
|
||||||
let new_marker = new L.marker(latlng, {icon: m_icon, title: db.hovertext});
|
// Add popup to marker
|
||||||
if (marker_entry.createInfoWindow) {
|
if (marker_entry.createInfoWindow) {
|
||||||
new_marker.bindPopup(db.text);
|
layerObj.bindPopup(db.text);
|
||||||
}
|
}
|
||||||
marker_group.addLayer(new_marker);
|
// Add the polyline or marker to the layer
|
||||||
|
marker_group.addLayer(layerObj);
|
||||||
}
|
}
|
||||||
|
// Save marker group
|
||||||
obj.marker_groups[marker_entry.displayName] = marker_group;
|
obj.marker_groups[marker_entry.displayName] = marker_group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,11 +7,10 @@ var world = "top";
|
|||||||
markersDB[groupName] = {
|
markersDB[groupName] = {
|
||||||
"raw": [
|
"raw": [
|
||||||
{
|
{
|
||||||
"fillColor": "#00FF00",
|
|
||||||
"fillOpacity": 0.2,
|
|
||||||
"strokeColor": "#FF0000",
|
"strokeColor": "#FF0000",
|
||||||
"strokeOpacity": 1,
|
"strokeWeight": 2,
|
||||||
"polygon" : [
|
"fill": true,
|
||||||
|
"polyline" : [
|
||||||
{"x": 347, "y": 67, "z": 95},
|
{"x": 347, "y": 67, "z": 95},
|
||||||
{"x": 347, "y": 77, "z": 95},
|
{"x": 347, "y": 77, "z": 95},
|
||||||
{"x": 347, "y": 77, "z": 105},
|
{"x": 347, "y": 77, "z": 105},
|
||||||
@@ -19,7 +18,7 @@ markersDB[groupName] = {
|
|||||||
{"x": 347, "y": 67, "z": 105}
|
{"x": 347, "y": 67, "z": 105}
|
||||||
]}
|
]}
|
||||||
],
|
],
|
||||||
"name": "Regions",
|
"name": groupName,
|
||||||
"created": false
|
"created": false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user