Commit dcec33e0 authored by Adrien Pavie's avatar Adrien Pavie
Browse files

Updated tests, polylabel used for label placement (closes #55)

parent 15439f57
......@@ -69,6 +69,10 @@ Flickr.prototype.get = function(bbox, success, fail) {
Flickr._simpleResult = function(data) {
var result = {};
if(data.stat != "ok" || data.photos == undefined || data.photos.photo == undefined) {
throw new Error("ctrl.provider.picture.Flickr.invalidData");
}
var photos = data.photos.photo;
var photo, machineTags, machineTag, mtKey, mtValue, osmType, osmId;
......
......@@ -16,6 +16,7 @@
*/
var L = require("leaflet");
var Polylabel = require("polylabel");
var util = require('../utils');
/**
......@@ -72,74 +73,9 @@ FeatureGeometry.prototype.getLabelPosition = function() {
}
}
else if(this.type == "Polygon" || this.type == "MultiPolygon") {
var coords = (this.type == "MultiPolygon") ? this.coordinates[0][0] : this.coordinates[0];
var minlon = coords[0][0];
var minlat = coords[0][1];
var maxlon = minlon;
var maxlat = minlat;
var length = coords.length;
var coord;
for(var i=1; i < length-1; i++) {
coord = coords[i];
if(minlon > coord[0]) { minlon = coord[0]; }
else if(maxlon < coord[0]) { maxlon = coord[0]; }
if(minlat > coord[1]) { minlat = coord[1]; }
else if(maxlat < coord[1]) { maxlat = coord[1]; }
}
var point = [ minlon + (maxlon-minlon)/2, minlat + (maxlat-minlat)/2 ];
if(length <= 4 || util.pointInPolygon(point, coords)) {
result = L.latLng(point[1], point[0]);
}
else {
//Try to find another point in polygon
//Doing circles around BBox center
var circles = 5;
var stepLat = (maxlat - minlat) / (2*circles);
var stepLon = (maxlon - minlon) / (2*circles);
var midLat = (maxlat-minlat)/2 + minlat;
var midLon = (maxlon-minlon)/2 + minlon;
var c = 1;
var altPoint, pos;
while(result == null && c <= circles) {
pos = 0;
while(result == null && pos < 4) {
switch(pos) {
//North
case 0:
altPoint = [ midLon, midLat + c*stepLat ];
break;
//East
case 1:
altPoint = [ midLon + c*stepLon, midLat ];
break;
//South
case 2:
altPoint = [ midLon, midLat - c*stepLat ];
break;
//West
case 3:
altPoint = [ midLon - c*stepLon, midLat ];
break;
}
if(util.pointInPolygon(altPoint, coords)) {
result = L.latLng(altPoint[1], altPoint[0]);
}
pos++;
}
c++;
}
if(result == null) {
result = L.latLng(point[1], point[0]);
console.log("[FeatureGeometry] No optimal label placement found");
}
}
var coords = (this.type == "MultiPolygon") ? this.coordinates[0] : this.coordinates;
result = Polylabel(coords, 0.00001);
result = L.latLng(result[1], result[0]);
}
else {
console.log("Unknown type: "+this.type);
......
../src/conf
\ No newline at end of file
{
"map": {
"iconSize": 24,
"iconFolder": "img",
"clusterMinZoom": 11,
"dataMinZoom": 18,
"maxZoom": 24,
"tilesMinOpacity": 0.2,
"center": {
"lat": 46.973,
"lon": 1.934,
"zoom": 6
},
"defaultStyle": "basic.mapcss"
},
"styles": [
"styles/basic.mapcss",
"styles/default.mapcss",
"styles/details.mapcss"
],
"api": {
"overpass": "http://api.openstreetmap.fr/oapi/interpreter/?data=",
"overpass_alt": "http://www.overpass-api.de/api/interpreter?data=",
"osm": "http://api.openstreetmap.org/api/0.6/",
"osm_dev": "http://api06.dev.openstreetmap.org/api/0.6/",
"nominatim": "http://nominatim.openstreetmap.org/",
"flickr": {
"url": "https://api.flickr.com/services/rest/?",
"key": "d06fb1ebb3ede5813b89c79320e11ab8"
},
"mapillary": {
"clientId": "eDhQTTdnRmZJNXdYZWUwRDQxc1NwdzpmYjE3YWE3MWM5ZjcyMTdm"
}
},
"tiles": [
{
"name": "OpenStreetMap",
"URL": "http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",
"attribution": "Tiles <a href=\"http://openstreetmap.org/\">OSM</a>",
"minZoom": 1,
"maxZoom": 19
},
{
"name": "OpenStreetMap FR",
"URL": "http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png",
"attribution": "Tiles <a href=\"http://tile.openstreetmap.fr/\">OSMFR</a>",
"minZoom": 1,
"maxZoom": 20
},
{
"name": "Stamen Toner",
"URL": "http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png",
"attribution": "Tiles <a href=\"http://maps.stamen.com/\">Stamen Toner</a>",
"minZoom": 1,
"maxZoom": 20
},
{
"name": "Cadastre FR",
"URL": "http://tms.cadastre.openstreetmap.fr/*/tout/{z}/{x}/{y}.png",
"attribution": "Cadastre (DGFiP)",
"minZoom": 1,
"maxZoom": 20
},
{
"name": "ÖPNV",
"URL": "http://tileserver.memomaps.de/tilegen/{z}/{x}/{y}.png",
"attribution": "Tiles <a href=\"http://www.öpnvkarte.de/\">ÖPNV</a>",
"minZoom": 1,
"maxZoom": 18
},
{
"name": "OpenStreetMap DE",
"URL": "http://b.tile.openstreetmap.de/tiles/osmde/{z}/{x}/{y}.png",
"attribution": "Tiles <a href=\"http://openstreetmap.de/karte.html\">OSMDE</a>",
"minZoom": 1,
"maxZoom": 18,
"subdomains": "abcd"
}
],
"feature": {
"details": {
"major": {
"opening_hours": {
"type": "hours",
"img": "clock",
"name": "Opening hours"
},
"contact:website": {
"type": "link",
"img": "web",
"name": "Website"
},
"website": {
"type": "link",
"img": "web",
"name": "Website"
},
"contact:email": {
"type": "email",
"img": "email",
"name": "E-mail"
},
"email": {
"type": "email",
"img": "email",
"name": "E-mail"
},
"contact:phone": {
"type": "text",
"img": "phone",
"name": "Phone"
},
"phone": {
"type": "text",
"img": "phone",
"name": "Phone"
},
"wheelchair": {
"type": "text_bind",
"img": "wheelchair",
"text_bind": { "yes": "Fully accessible", "limited": "Limited access", "no": "Not accessible" }
}
},
"minor": {
"cuisine": {
"type": "text",
"img": "cuisine",
"name": "Cuisine"
},
"description": {
"type": "text",
"img": "info",
"name": "More details"
}
}
}
},
"routing": {
"foot": {
"name": "By foot",
"speed": 1.39
},
"wheelchair": {
"name": "In wheelchair",
"speed": 0.7,
"avoid": [ "stairs", "escalator" ]
},
"sport": {
"name": "By foot (sportive)",
"speed": 1.39,
"avoid": [ "elevator", "escalator" ]
}
},
"polygonFeatures": {
"building": true,
"highway": {
"included_values": {
"services": true,
"rest_area": true,
"escape": true,
"elevator": true
}
},
"natural": {
"excluded_values": {
"coastline": true,
"cliff": true,
"ridge": true,
"arete": true,
"tree_row": true
}
},
"landuse": true,
"waterway": {
"included_values": {
"riverbank": true,
"dock": true,
"boatyard": true,
"dam": true
}
},
"amenity": true,
"leisure": true,
"barrier": {
"included_values": {
"city_wall": true,
"ditch": true,
"retaining_wall": true,
"spikes": true,
"self_checkout": true,
"checkout": true,
"shelf": true
}
},
"railway": {
"included_values": {
"station": true,
"turntable": true,
"roundhouse": true,
"platform": true
}
},
"area": true,
"boundary": true,
"man_made": {
"excluded_values": {
"cutline": true,
"embankment": true,
"pipeline": true
}
},
"power": {
"included_values": {
"plant": true,
"substation": true,
"generator": true,
"transformer": true
}
},
"place": true,
"shop": true,
"aeroway": {
"excluded_values": {
"taxiway": true
}
},
"tourism": true,
"historic": true,
"public_transport": true,
"office": true,
"building:part": true,
"military": true,
"ruins": true,
"area:highway": true,
"craft": true,
"golf": true,
"indoor": {
"excluded_values": {
"yes": true,
"wall": true
}
},
"buildingpart": {
"excluded_values": {
"yes": true,
"wall": true
}
},
"room": true,
"department": true
}
}
......@@ -12,7 +12,7 @@ QUnit.module("Ctrl > Provider > Data > Notes");
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -12,7 +12,7 @@ QUnit.module("Ctrl > Provider > Data > OSM");
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -11,7 +11,7 @@ QUnit.module("Ctrl > Provider > Picture > Flickr");
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -12,7 +12,7 @@ QUnit.module("Ctrl > Service > NewNote");
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -12,7 +12,7 @@ QUnit.module("Ctrl > Service > Routing");
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -12,7 +12,7 @@ QUnit.module("Ctrl > Service > Search");
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -11,7 +11,7 @@ var style = [];
//Load config file
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -11,7 +11,7 @@ var style = [];
//Load config file
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -9,7 +9,7 @@ var OLU = require("../src/OLU");
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -12,7 +12,7 @@ var style = null;
//Load config file
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -9,7 +9,7 @@ var OLU = require("../src/OLU");
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -9,7 +9,7 @@ var OLU = require("../src/OLU");
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -11,7 +11,7 @@ L.Icon.Default.imagePath = "./img/";
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -9,7 +9,7 @@ var OLU = require("../src/OLU");
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
......@@ -9,7 +9,7 @@ var OLU = require("../src/OLU");
//Load config file
var config = null;
$.ajax({
url: 'conf/config.json',
url: 'config.json',
async: false,
dataType: 'json',
success: function(data) { config = data; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment