From e262ccc4b5a840d301f6fc583599dd54bbe3bac4 Mon Sep 17 00:00:00 2001 From: Andrea Date: Wed, 21 Mar 2018 14:01:29 +0100 Subject: [PATCH] C125 annotations (#2757) * Fix issue on editing style in vector import * Fixed style of loaded vector layers * fixes on Matteo's comments * Fixed lint error * Fixes #16 * Fixed test * Fixed typo * Removed unused var --- web/client/test-resources/Annotation.json | 2327 +++++++++++++++++ web/client/test-resources/markerIcon.png | Bin 0 -> 1829 bytes web/client/utils/AnnotationsUtils.js | 127 +- web/client/utils/MarkerUtils.js | 36 +- web/client/utils/PrintUtils.js | 35 +- .../utils/__tests__/AnnotationsUtils-test.js | 46 +- .../utils/__tests__/MarkerUtils-test.js | 9 + 7 files changed, 2560 insertions(+), 20 deletions(-) create mode 100644 web/client/test-resources/Annotation.json create mode 100644 web/client/test-resources/markerIcon.png diff --git a/web/client/test-resources/Annotation.json b/web/client/test-resources/Annotation.json new file mode 100644 index 0000000000..4909d41e21 --- /dev/null +++ b/web/client/test-resources/Annotation.json @@ -0,0 +1,2327 @@ +{ + "geometry": { + "geometries": [ + { + "coordinates": [ + [ + [ + [ + -2.1302270796149987, + 41.012866939758716 + ], + [ + 0.7314477860927568, + 40.955144011732784 + ], + [ + 0.8768409490585312, + 42.79464290558846 + ], + [ + -2.1302270796149987, + 41.012866939758716 + ] + ] + ], + [ + [ + [ + -0.653510838747026, + 41.60537157021042 + ], + [ + 0.26290275156497783, + 42.2001684138601 + ], + [ + 0.4970435053110107, + 41.13431740566309 + ], + [ + -1.3155249506235136, + 41.249100655546755 + ], + [ + -0.653510838747026, + 41.60537157021042 + ] + ] + ], + [ + [ + [ + -2.4873705860227364, + 41.066414081271496 + ], + [ + 1.1326244473457323, + 43.09194999351491 + ], + [ + 0.888772085309027, + 40.72982594526523 + ], + [ + -2.510375976562502, + 40.77293738777871 + ], + [ + -2.4873705860227364, + 41.066414081271496 + ] + ] + ], + [ + [ + [ + -2.510375976562502, + 40.77293738777871 + ], + [ + -2.7714770380407585, + 42.46233959929457 + ], + [ + -3.3174316305667175, + 42.30758935314285 + ], + [ + -2.510375976562502, + 40.77293738777871 + ] + ] + ] + ], + "type": "MultiPolygon" + }, + { + "coordinates": [ + [ + [ + -1.0703978687524813, + 40.22725536555695 + ], + [ + 1.6443456709384907, + 40.09278101249406 + ] + ], + [ + [ + -0.1218822598457349, + 39.36768506734152 + ], + [ + 2.1009595692157736, + 41.48935575656172 + ] + ] + ], + "type": "MultiLineString" + }, + { + "coordinates": [ + [ + [ + -1.4526615005506758, + 44.24033519864751 + ], + [ + -1.4545111865413698, + 44.28248708834574 + ], + [ + -1.4600529446478878, + 44.32444258058433 + ], + [ + -1.4692649040827712, + 44.36603662834894 + ], + [ + -1.4821107094506756, + 44.40710595732416 + ], + [ + -1.498539664226503, + 44.4474896964214 + ], + [ + -1.518486930831429, + 44.48702999357495 + ], + [ + -1.5418737865172039, + 44.52557261467738 + ], + [ + -1.5686079340488732, + 44.56296752366954 + ], + [ + -1.5985838659597995, + 44.599069441947854 + ], + [ + -1.631683280941432, + 44.633738385397336 + ], + [ + -1.6677755507245215, + 44.666840177504895 + ], + [ + -1.7067182356092243, + 44.6982469371487 + ], + [ + -1.7483576466095205, + 44.72783753979808 + ], + [ + -1.79252945199343, + 44.75549805099 + ], + [ + -1.8390593258252799, + 44.781122131075044 + ], + [ + -1.8877636359505339, + 44.804611410343945 + ], + [ + -1.9384501687080102, + 44.82587583375724 + ], + [ + -1.9909188875093888, + 44.8448339746037 + ], + [ + -2.0449627222922384, + 44.86141331650843 + ], + [ + -2.100368386730951, + 44.875550503297724 + ], + [ + -2.1569172199804267, + 44.88719155630784 + ], + [ + -2.214386049630535, + 44.89629205879568 + ], + [ + -2.2725480724656566, + 44.90281730717493 + ], + [ + -2.3311737495533635, + 44.90674242885969 + ], + [ + -2.390031712129714, + 44.90805246655213 + ], + [ + -2.448889674706064, + 44.90674242885969 + ], + [ + -2.5075153517937703, + 44.90281730717493 + ], + [ + -2.565677374628893, + 44.89629205879568 + ], + [ + -2.6231462042790006, + 44.88719155630784 + ], + [ + -2.679695037528476, + 44.875550503297724 + ], + [ + -2.735100701967189, + 44.86141331650843 + ], + [ + -2.789144536750039, + 44.8448339746037 + ], + [ + -2.8416132555514175, + 44.82587583375724 + ], + [ + -2.8922997883088937, + 44.804611410343945 + ], + [ + -2.9410040984341475, + 44.781122131075044 + ], + [ + -2.987533972265997, + 44.75549805099 + ], + [ + -3.031705777649907, + 44.72783753979808 + ], + [ + -3.073345188650203, + 44.6982469371487 + ], + [ + -3.1122878735349055, + 44.666840177504895 + ], + [ + -3.1483801433179956, + 44.633738385397336 + ], + [ + -3.1814795582996274, + 44.599069441947854 + ], + [ + -3.2114554902105543, + 44.56296752366954 + ], + [ + -3.2381896377422232, + 44.52557261467738 + ], + [ + -3.261576493427998, + 44.48702999357495 + ], + [ + -3.2815237600329246, + 44.4474896964214 + ], + [ + -3.2979527148087513, + 44.40710595732416 + ], + [ + -3.310798520176656, + 44.36603662834894 + ], + [ + -3.3200104796115397, + 44.32444258058433 + ], + [ + -3.3255522377180573, + 44.28248708834574 + ], + [ + -3.3274019237087518, + 44.24033519864751 + ], + [ + -3.3255522377180573, + 44.198153088213566 + ], + [ + -3.3200104796115397, + 44.156107410432625 + ], + [ + -3.310798520176656, + 44.114364634791905 + ], + [ + -3.297952714808752, + 44.073090381442405 + ], + [ + -3.2815237600329246, + 44.03244875365653 + ], + [ + -3.2615764934279983, + 43.992601671033 + ], + [ + -3.238189637742224, + 43.9537082063844 + ], + [ + -3.2114554902105543, + 43.91592392930542 + ], + [ + -3.181479558299628, + 43.8794002594656 + ], + [ + -3.148380143317996, + 43.84428383269662 + ], + [ + -3.1122878735349064, + 43.81071588294976 + ], + [ + -3.0733451886502037, + 43.77883164318383 + ], + [ + -3.031705777649907, + 43.74875976820668 + ], + [ + -2.987533972265997, + 43.72062178243341 + ], + [ + -2.9410040984341475, + 43.69453155544245 + ], + [ + -2.892299788308893, + 43.67059480810564 + ], + [ + -2.8416132555514175, + 43.648908651942314 + ], + [ + -2.789144536750038, + 43.6295611641984 + ], + [ + -2.735100701967189, + 43.612631000983356 + ], + [ + -2.679695037528477, + 43.59818705060928 + ], + [ + -2.6231462042790006, + 43.5862881290699 + ], + [ + -2.565677374628893, + 43.57698271937469 + ], + [ + -2.5075153517937707, + 43.570308756215084 + ], + [ + -2.448889674706064, + 43.566293457189715 + ], + [ + -2.390031712129714, + 43.56495320155397 + ], + [ + -2.331173749553364, + 43.566293457189715 + ], + [ + -2.2725480724656566, + 43.570308756215084 + ], + [ + -2.214386049630535, + 43.57698271937469 + ], + [ + -2.1569172199804267, + 43.5862881290699 + ], + [ + -2.1003683867309513, + 43.59818705060928 + ], + [ + -2.0449627222922393, + 43.612631000983356 + ], + [ + -1.9909188875093897, + 43.6295611641984 + ], + [ + -1.9384501687080096, + 43.648908651942314 + ], + [ + -1.8877636359505339, + 43.67059480810564 + ], + [ + -1.8390593258252799, + 43.69453155544245 + ], + [ + -1.7925294519934305, + 43.72062178243341 + ], + [ + -1.7483576466095214, + 43.74875976820668 + ], + [ + -1.7067182356092245, + 43.77883164318383 + ], + [ + -1.6677755507245215, + 43.81071588294976 + ], + [ + -1.631683280941432, + 43.84428383269662 + ], + [ + -1.5985838659598002, + 43.8794002594656 + ], + [ + -1.5686079340488734, + 43.915923929305414 + ], + [ + -1.5418737865172039, + 43.9537082063844 + ], + [ + -1.518486930831429, + 43.992601671033 + ], + [ + -1.498539664226503, + 44.03244875365653 + ], + [ + -1.4821107094506758, + 44.073090381442405 + ], + [ + -1.4692649040827712, + 44.114364634791905 + ], + [ + -1.4600529446478878, + 44.156107410432625 + ], + [ + -1.4545111865413698, + 44.198153088213566 + ], + [ + -1.4526615005506758, + 44.24033519864751 + ] + ] + ], + "type": "Polygon" + }, + { + "coordinates": [ + [ + [ + 1.3693084004917728, + 42.90318704568137 + ], + [ + 1.3662180253537672, + 42.975177551909944 + ], + [ + 1.356959096238561, + 43.046800264242954 + ], + [ + 1.3415681539093698, + 43.11777399136188 + ], + [ + 1.320105939384114, + 43.187821068610354 + ], + [ + 1.2926571542183722, + 43.25666841558373 + ], + [ + 1.2593301262270364, + 43.32404856095068 + ], + [ + 1.2202563819639172, + 43.389700631294666 + ], + [ + 1.1755901276465255, + 43.4533713011254 + ], + [ + 1.1255076405745819, + 43.5148157015678 + ], + [ + 1.0702065734440471, + 43.57379828558289 + ], + [ + 1.0099051743022307, + 43.63009364790698 + ], + [ + 0.9448414252224573, + 43.683487298209876 + ], + [ + 0.875272103097545, + 43.73377638626398 + ], + [ + 0.8014717662587207, + 43.78077037818393 + ], + [ + 0.7237316709193209, + 43.824291683036456 + ], + [ + 0.6423586217195779, + 43.86417622933142 + ], + [ + 0.5576737609088744, + 43.900273991087495 + ], + [ + 0.470011300943997, + 43.932449463317504 + ], + [ + 0.37971720550525884, + 43.96058208690097 + ], + [ + 0.28714782413590767, + 43.98456662290419 + ], + [ + 0.1926684858932812, + 44.0043134764742 + ], + [ + 0.09665205756191957, + 44.01974897047265 + ], + [ + -0.0005225278812873263, + 44.03081556903216 + ], + [ + -0.0984717667424406, + 44.03747205121399 + ], + [ + -0.1968090981245056, + 44.039693634924674 + ], + [ + -0.2951464295065706, + 44.03747205121399 + ], + [ + -0.3930956683677236, + 44.03081556903216 + ], + [ + -0.4902702538109307, + 44.01974897047265 + ], + [ + -0.5862866821422927, + 44.0043134764742 + ], + [ + -0.6807660203849184, + 43.98456662290419 + ], + [ + -0.7733354017542697, + 43.96058208690097 + ], + [ + -0.8636294971930086, + 43.932449463317504 + ], + [ + -0.9512919571578863, + 43.900273991087495 + ], + [ + -1.0359768179685898, + 43.86417622933142 + ], + [ + -1.1173498671683317, + 43.824291683036456 + ], + [ + -1.1950899625077323, + 43.78077037818393 + ], + [ + -1.2688902993465563, + 43.73377638626398 + ], + [ + -1.3384596214714681, + 43.683487298209876 + ], + [ + -1.403523370551242, + 43.63009364790698 + ], + [ + -1.4638247696930582, + 43.57379828558289 + ], + [ + -1.519125836823593, + 43.5148157015678 + ], + [ + -1.569208323895537, + 43.4533713011254 + ], + [ + -1.6138745782129282, + 43.389700631294666 + ], + [ + -1.6529483224760477, + 43.32404856095068 + ], + [ + -1.6862753504673837, + 43.25666841558373 + ], + [ + -1.713724135633125, + 43.187821068610354 + ], + [ + -1.735186350158381, + 43.11777399136188 + ], + [ + -1.750577292487572, + 43.046800264242954 + ], + [ + -1.7598362216027785, + 42.975177551909944 + ], + [ + -1.7629265967407843, + 42.90318704568137 + ], + [ + -1.7598362216027785, + 42.83111237675638 + ], + [ + -1.7505772924875724, + 42.759238504175286 + ], + [ + -1.7351863501583806, + 42.687850581805066 + ], + [ + -1.7137241356331256, + 42.61723280896535 + ], + [ + -1.6862753504673837, + 42.54766726962275 + ], + [ + -1.6529483224760477, + 42.47943276536708 + ], + [ + -1.613874578212929, + 42.412803647637595 + ], + [ + -1.569208323895537, + 42.34804865488663 + ], + [ + -1.5191258368235934, + 42.28542976054622 + ], + [ + -1.463824769693059, + 42.225201037798186 + ], + [ + -1.403523370551242, + 42.167607547235846 + ], + [ + -1.338459621471469, + 42.11288425354252 + ], + [ + -1.268890299346556, + 42.0612549772979 + ], + [ + -1.1950899625077318, + 42.01293138795553 + ], + [ + -1.1173498671683322, + 41.968112043912456 + ], + [ + -1.035976817968589, + 41.92698148541671 + ], + [ + -0.9512919571578858, + 41.889709385828795 + ], + [ + -0.8636294971930079, + 41.856449766472515 + ], + [ + -0.7733354017542697, + 41.827340279979516 + ], + [ + -0.6807660203849192, + 41.80250156665425 + ], + [ + -0.5862866821422921, + 41.78203668796389 + ], + [ + -0.4902702538109308, + 41.766030640796416 + ], + [ + -0.3930956683677242, + 41.75454995563224 + ], + [ + -0.2951464295065702, + 41.74764238124673 + ], + [ + -0.19680909812450598, + 41.7453366580063 + ], + [ + -0.09847176674244168, + 41.74764238124673 + ], + [ + -0.0005225278812877185, + 41.75454995563224 + ], + [ + 0.09665205756191882, + 41.766030640796416 + ], + [ + 0.19266848589328153, + 41.782036687963895 + ], + [ + 0.2871478241359074, + 41.80250156665425 + ], + [ + 0.3797172055052578, + 41.827340279979516 + ], + [ + 0.47001130094399585, + 41.856449766472515 + ], + [ + 0.5576737609088752, + 41.889709385828795 + ], + [ + 0.6423586217195782, + 41.92698148541671 + ], + [ + 0.7237316709193202, + 41.968112043912456 + ], + [ + 0.8014717662587201, + 42.01293138795553 + ], + [ + 0.8752721030975439, + 42.0612549772979 + ], + [ + 0.9448414252224568, + 42.11288425354252 + ], + [ + 1.0099051743022311, + 42.167607547235846 + ], + [ + 1.070206573444047, + 42.225201037798186 + ], + [ + 1.1255076405745816, + 42.28542976054622 + ], + [ + 1.1755901276465248, + 42.34804865488663 + ], + [ + 1.220256381963917, + 42.412803647637595 + ], + [ + 1.2593301262270364, + 42.47943276536708 + ], + [ + 1.2926571542183722, + 42.54766726962275 + ], + [ + 1.3201059393841137, + 42.61723280896535 + ], + [ + 1.3415681539093698, + 42.687850581805066 + ], + [ + 1.3569590962385607, + 42.759238504175286 + ], + [ + 1.3662180253537672, + 42.83111237675638 + ], + [ + 1.3693084004917728, + 42.90318704568137 + ] + ] + ], + "type": "Polygon" + }, + { + "coordinates": [ + [ + [ + 3.1779668514472643, + 44.46294003612415 + ], + [ + 3.175709685177877, + 44.51417872181113 + ], + [ + 3.1689470943737796, + 44.56517044613116 + ], + [ + 3.157705767891342, + 44.61571476091935 + ], + [ + 3.142030070110517, + 44.66561349944311 + ], + [ + 3.1219818658488996, + 44.71467153784484 + ], + [ + 3.097640276209558, + 44.762697536758886 + ], + [ + 3.069101366326184, + 44.809504660625514 + ], + [ + 3.0364777662378986, + 44.85491127242935 + ], + [ + 2.9998982263899467, + 44.89874160179368 + ], + [ + 2.959507109514505, + 44.94082638456483 + ], + [ + 2.9154638208969352, + 44.98100347221729 + ], + [ + 2.8679421792759463, + 45.01911840960054 + ], + [ + 2.8171297308604433, + 45.055024979729794 + ], + [ + 2.7632270091703224, + 45.08858571449352 + ], + [ + 2.706446743622284, + 45.119672370309466 + ], + [ + 2.6470130199840094, + 45.14816636790742 + ], + [ + 2.5851603960100147, + 45.17395919554938 + ], + [ + 2.521132975749348, + 45.19695277511717 + ], + [ + 2.455183446178433, + 45.21705979060253 + ], + [ + 2.3875720799610116, + 45.2342039786263 + ], + [ + 2.3185657082708495, + 45.24832038069216 + ], + [ + 2.248436667730995, + 45.259355556946645 + ], + [ + 2.177461725625548, + 45.26726776127254 + ], + [ + 2.1059209876256317, + 45.2720270775882 + ], + [ + 2.0340967923402773, + 45.27361551726286 + ], + [ + 1.9622725970549233, + 45.2720270775882 + ], + [ + 1.8907318590550068, + 45.26726776127254 + ], + [ + 1.8197569169495595, + 45.259355556946645 + ], + [ + 1.7496278764097049, + 45.24832038069216 + ], + [ + 1.680621504719543, + 45.2342039786263 + ], + [ + 1.6130101385021216, + 45.21705979060253 + ], + [ + 1.5470606089312062, + 45.19695277511717 + ], + [ + 1.48303318867054, + 45.17395919554938 + ], + [ + 1.4211805646965445, + 45.14816636790742 + ], + [ + 1.3617468410582707, + 45.119672370309466 + ], + [ + 1.304966575510232, + 45.08858571449352 + ], + [ + 1.251063853820111, + 45.055024979729794 + ], + [ + 1.2002514054046083, + 45.01911840960054 + ], + [ + 1.152729763783619, + 44.98100347221729 + ], + [ + 1.1086864751660492, + 44.94082638456483 + ], + [ + 1.0682953582906076, + 44.89874160179368 + ], + [ + 1.0317158184426554, + 44.85491127242935 + ], + [ + 0.9990922183543707, + 44.809504660625514 + ], + [ + 0.9705533084709964, + 44.762697536758886 + ], + [ + 0.9462117188316547, + 44.71467153784484 + ], + [ + 0.9261635145700376, + 44.66561349944311 + ], + [ + 0.9104878167892122, + 44.61571476091935 + ], + [ + 0.8992464903067745, + 44.56517044613116 + ], + [ + 0.8924838995026771, + 44.51417872181113 + ], + [ + 0.89022673323329, + 44.46294003612415 + ], + [ + 0.8924838995026771, + 44.41165634007863 + ], + [ + 0.8992464903067745, + 44.360530294667306 + ], + [ + 0.9104878167892122, + 44.309764466802214 + ], + [ + 0.9261635145700374, + 44.25956051728528 + ], + [ + 0.9462117188316544, + 44.2101183842197 + ], + [ + 0.9705533084709963, + 44.16163546541379 + ], + [ + 0.9990922183543703, + 44.114305803456276 + ], + [ + 1.0317158184426554, + 44.06831927724793 + ], + [ + 1.0682953582906072, + 44.02386080385549 + ], + [ + 1.1086864751660486, + 43.98110955460997 + ], + [ + 1.1527297637836187, + 43.94023818939836 + ], + [ + 1.2002514054046076, + 43.901412113096924 + ], + [ + 1.251063853820111, + 43.86478875806191 + ], + [ + 1.304966575510232, + 43.83051689653101 + ], + [ + 1.3617468410582705, + 43.79873598669443 + ], + [ + 1.421180564696545, + 43.769575556069135 + ], + [ + 1.48303318867054, + 43.743154625653005 + ], + [ + 1.5470606089312071, + 43.71958117814939 + ], + [ + 1.6130101385021216, + 43.698951673336836 + ], + [ + 1.6806215047195425, + 43.68135061341583 + ], + [ + 1.749627876409705, + 43.66685016089605 + ], + [ + 1.8197569169495595, + 43.65550981129572 + ], + [ + 1.8907318590550064, + 43.64737612261215 + ], + [ + 1.9622725970549233, + 43.64248250319181 + ], + [ + 2.034096792340277, + 43.6408490592824 + ], + [ + 2.105920987625631, + 43.64248250319181 + ], + [ + 2.1774617256255477, + 43.64737612261215 + ], + [ + 2.2484366677309944, + 43.65550981129572 + ], + [ + 2.31856570827085, + 43.66685016089605 + ], + [ + 2.3875720799610116, + 43.68135061341583 + ], + [ + 2.4551834461784323, + 43.698951673336836 + ], + [ + 2.5211329757493472, + 43.71958117814939 + ], + [ + 2.585160396010015, + 43.743154625653005 + ], + [ + 2.64701301998401, + 43.769575556069135 + ], + [ + 2.7064467436222834, + 43.79873598669443 + ], + [ + 2.7632270091703215, + 43.83051689653101 + ], + [ + 2.817129730860443, + 43.86478875806191 + ], + [ + 2.867942179275946, + 43.901412113096924 + ], + [ + 2.9154638208969357, + 43.94023818939836 + ], + [ + 2.959507109514505, + 43.98110955460997 + ], + [ + 2.9998982263899463, + 44.02386080385549 + ], + [ + 3.0364777662378986, + 44.06831927724793 + ], + [ + 3.069101366326184, + 44.114305803456276 + ], + [ + 3.097640276209558, + 44.16163546541379 + ], + [ + 3.1219818658488996, + 44.2101183842197 + ], + [ + 3.1420300701105166, + 44.25956051728527 + ], + [ + 3.157705767891342, + 44.309764466802214 + ], + [ + 3.1689470943737796, + 44.360530294667306 + ], + [ + 3.175709685177877, + 44.41165634007863 + ], + [ + 3.1779668514472643, + 44.46294003612415 + ] + ] + ], + "type": "Polygon" + }, + { + "coordinates": [ + [ + [ + 1.0429974353241511, + 45.10479454777919 + ], + [ + 1.0415800192543725, + 45.136619860497404 + ], + [ + 1.0373333649387084, + 45.16830192602386 + ], + [ + 1.030274231981631, + 45.199716023021175 + ], + [ + 1.0204304795559103, + 45.23073869102389 + ], + [ + 1.0078409564551887, + 45.26124820952878 + ], + [ + 0.9925553477755382, + 45.29112506713965 + ], + [ + 0.9746339788310872, + 45.32025241909233 + ], + [ + 0.9541475770775646, + 45.34851653157763 + ], + [ + 0.9311769929833452, + 45.37580721137409 + ], + [ + 0.905812880949587, + 45.402018219398364 + ], + [ + 0.8781553415387268, + 45.42704766687796 + ], + [ + 0.8483135264232913, + 45.45079839294743 + ], + [ + 0.816405207614113, + 45.4731783225646 + ], + [ + 0.7825563126680067, + 45.494100803737126 + ], + [ + 0.7469004277092366, + 45.513484923140844 + ], + [ + 0.7095782702261098, + 45.53125579930016 + ], + [ + 0.6707371337233407, + 45.54734485258557 + ], + [ + 0.6305303064218782, + 45.561690051364934 + ], + [ + 0.5891164663003294, + 45.574236133723545 + ], + [ + 0.5466590548654698, + 45.58493480424149 + ], + [ + 0.5033256321232867, + 45.593744905387666 + ], + [ + 0.4592872152961861, + 45.60063256315654 + ], + [ + 0.41471760389614526, + 45.6055713066374 + ], + [ + 0.3697926938174417, + 45.60854216126648 + ], + [ + 0.3246897831559169, + 45.60953371557048 + ], + [ + 0.279586872494392, + 45.60854216126648 + ], + [ + 0.23466196241568854, + 45.6055713066374 + ], + [ + 0.19009235101564764, + 45.60063256315654 + ], + [ + 0.1460539341885468, + 45.593744905387666 + ], + [ + 0.10272051144636404, + 45.58493480424149 + ], + [ + 0.06026310001150442, + 45.574236133723545 + ], + [ + 0.018849259889955304, + 45.561690051364934 + ], + [ + -0.021357567411507124, + 45.54734485258557 + ], + [ + -0.06019870391427631, + 45.53125579930016 + ], + [ + -0.0975208613974028, + 45.513484923140844 + ], + [ + -0.1331767463561732, + 45.494100803737126 + ], + [ + -0.16702564130227923, + 45.4731783225646 + ], + [ + -0.1989339601114576, + 45.45079839294743 + ], + [ + -0.22877577522689305, + 45.42704766687796 + ], + [ + -0.25643331463775326, + 45.402018219398364 + ], + [ + -0.28179742667151136, + 45.37580721137409 + ], + [ + -0.304768010765731, + 45.34851653157763 + ], + [ + -0.3252544125192534, + 45.32025241909233 + ], + [ + -0.34317578146370453, + 45.29112506713965 + ], + [ + -0.35846139014335504, + 45.26124820952878 + ], + [ + -0.3710509132440768, + 45.23073869102389 + ], + [ + -0.3808946656697974, + 45.199716023021175 + ], + [ + -0.3879537986268749, + 45.16830192602386 + ], + [ + -0.3922004529425389, + 45.136619860497404 + ], + [ + -0.39361786901231754, + 45.10479454777919 + ], + [ + -0.3922004529425389, + 45.07295148280463 + ], + [ + -0.3879537986268749, + 45.04121644049451 + ], + [ + -0.38089466566979724, + 45.0097149777254 + ], + [ + -0.3710509132440769, + 44.97857193287487 + ], + [ + -0.3584613901433552, + 44.9479109249942 + ], + [ + -0.34317578146370453, + 44.917853854714046 + ], + [ + -0.3252544125192535, + 44.88852040902997 + ], + [ + -0.304768010765731, + 44.86002757214503 + ], + [ + -0.2817974266715116, + 44.83248914456561 + ], + [ + -0.25643331463775365, + 44.80601527265165 + ], + [ + -0.2287757752268931, + 44.78071199081462 + ], + [ + -0.19893396011145792, + 44.756680778534694 + ], + [ + -0.16702564130227915, + 44.734018134332146 + ], + [ + -0.13317674635617308, + 44.712815168777254 + ], + [ + -0.09752086139740294, + 44.69315721855737 + ], + [ + -0.060198703914275925, + 44.67512348354034 + ], + [ + -0.021357567411506993, + 44.658786688678475 + ], + [ + 0.018849259889955696, + 44.644212772490505 + ], + [ + 0.06026310001150438, + 44.6314606037368 + ], + [ + 0.10272051144636372, + 44.62058172777018 + ], + [ + 0.1460539341885471, + 44.61162014389943 + ], + [ + 0.19009235101564764, + 44.604612114946626 + ], + [ + 0.23466196241568824, + 44.59958601001467 + ], + [ + 0.2795868724943922, + 44.59656218130794 + ], + [ + 0.3246897831559167, + 44.59555287566889 + ], + [ + 0.36979269381744123, + 44.59656218130794 + ], + [ + 0.41471760389614515, + 44.59958601001467 + ], + [ + 0.4592872152961857, + 44.604612114946626 + ], + [ + 0.5033256321232868, + 44.61162014389943 + ], + [ + 0.5466590548654696, + 44.62058172777018 + ], + [ + 0.589116466300329, + 44.6314606037368 + ], + [ + 0.6305303064218778, + 44.644212772490505 + ], + [ + 0.6707371337233409, + 44.658786688678475 + ], + [ + 0.7095782702261098, + 44.67512348354034 + ], + [ + 0.7469004277092363, + 44.69315721855737 + ], + [ + 0.7825563126680066, + 44.712815168777254 + ], + [ + 0.8164052076141124, + 44.734018134332146 + ], + [ + 0.848313526423291, + 44.756680778534694 + ], + [ + 0.8781553415387269, + 44.78071199081462 + ], + [ + 0.905812880949587, + 44.80601527265165 + ], + [ + 0.931176992983345, + 44.83248914456561 + ], + [ + 0.9541475770775644, + 44.86002757214503 + ], + [ + 0.9746339788310869, + 44.88852040902997 + ], + [ + 0.9925553477755382, + 44.917853854714046 + ], + [ + 1.0078409564551887, + 44.9479109249942 + ], + [ + 1.0204304795559103, + 44.97857193287487 + ], + [ + 1.030274231981631, + 45.0097149777254 + ], + [ + 1.0373333649387084, + 45.04121644049451 + ], + [ + 1.0415800192543725, + 45.07295148280463 + ], + [ + 1.0429974353241511, + 45.10479454777919 + ] + ] + ], + "type": "Polygon" + }, + { + "coordinates": [ + [ + [ + 0.264841992486353, + 46.45643335185111 + ], + [ + 0.2625195092261366, + 46.50732150338776 + ], + [ + 0.25556122522587427, + 46.55796150856663 + ], + [ + 0.2439946016535771, + 46.60815435855227 + ], + [ + 0.22786528668819725, + 46.65770335419288 + ], + [ + 0.20723693536712018, + 46.70641486029958 + ], + [ + 0.18219095836881302, + 46.75409903958872 + ], + [ + 0.15282620072206937, + 46.80057056387149 + ], + [ + 0.11925855170983928, + 46.845649300287654 + ], + [ + 0.081620487507174, + 46.889160970591064 + ], + [ + 0.04006054835828574, + 46.93093778170223 + ], + [ + -0.00525724764393534, + 46.970819025944635 + ], + [ + -0.054154051862399764, + 47.00865164957498 + ], + [ + -0.10643689094968238, + 47.04429078840043 + ], + [ + -0.1618994284256629, + 47.077600269448055 + ], + [ + -0.22032277899334635, + 47.1084530778098 + ], + [ + -0.2814763723791329, + 47.13673178793153 + ], + [ + -0.3451188632883473, + 47.162328958744304 + ], + [ + -0.4109990838848594, + 47.18514749215231 + ], + [ + -0.47885703503578475, + 47.2051009544911 + ], + [ + -0.5484249124092799, + 47.22211386065707 + ], + [ + -0.6194281633758915, + 47.23612192068009 + ], + [ + -0.6915865705423535, + 47.247072248571335 + ], + [ + -0.7646153576416209, + 47.2549235333246 + ], + [ + -0.8382263134146924, + 47.25964617198746 + ], + [ + -0.9121289290487782, + 47.26122236474588 + ], + [ + -0.9860315446828639, + 47.25964617198746 + ], + [ + -1.059642500455935, + 47.2549235333246 + ], + [ + -1.132671287555203, + 47.247072248571335 + ], + [ + -1.2048296947216652, + 47.23612192068009 + ], + [ + -1.2758329456882762, + 47.22211386065707 + ], + [ + -1.3454008230617713, + 47.2051009544911 + ], + [ + -1.4132587742126972, + 47.18514749215231 + ], + [ + -1.4791389948092095, + 47.162328958744304 + ], + [ + -1.542781485718424, + 47.13673178793153 + ], + [ + -1.6039350791042097, + 47.1084530778098 + ], + [ + -1.6623584296718936, + 47.077600269448055 + ], + [ + -1.7178209671478744, + 47.04429078840043 + ], + [ + -1.7701038062351566, + 47.00865164957498 + ], + [ + -1.8190006104536212, + 46.970819025944635 + ], + [ + -1.864318406455842, + 46.93093778170223 + ], + [ + -1.9058783456047304, + 46.889160970591064 + ], + [ + -1.9435164098073958, + 46.845649300287654 + ], + [ + -1.9770840588196255, + 46.80057056387149 + ], + [ + -2.00644881646637, + 46.75409903958872 + ], + [ + -2.0314947934646765, + 46.70641486029958 + ], + [ + -2.0521231447857535, + 46.65770335419288 + ], + [ + -2.0682524597511334, + 46.60815435855227 + ], + [ + -2.0798190833234305, + 46.55796150856663 + ], + [ + -2.086777367323693, + 46.50732150338776 + ], + [ + -2.0890998505839096, + 46.45643335185111 + ], + [ + -2.086777367323693, + 46.40549760048509 + ], + [ + -2.0798190833234305, + 46.35471554664084 + ], + [ + -2.0682524597511334, + 46.30428843977188 + ], + [ + -2.052123144785754, + 46.25441667408089 + ], + [ + -2.031494793464677, + 46.20529897592447 + ], + [ + -2.00644881646637, + 46.15713158952413 + ], + [ + -1.9770840588196263, + 46.11010746466963 + ], + [ + -1.9435164098073958, + 46.064415450216714 + ], + [ + -1.9058783456047308, + 46.020239497272584 + ], + [ + -1.8643184064558425, + 45.97775787602741 + ], + [ + -1.8190006104536212, + 45.93714241022631 + ], + [ + -1.770103806235157, + 45.898557733282416 + ], + [ + -1.7178209671478741, + 45.862160570006246 + ], + [ + -1.6623584296718934, + 45.828099047869124 + ], + [ + -1.6039350791042104, + 45.79651204162868 + ], + [ + -1.5427814857184234, + 45.76752855502099 + ], + [ + -1.4791389948092095, + 45.74126714306936 + ], + [ + -1.4132587742126965, + 45.717835378372605 + ], + [ + -1.3454008230617713, + 45.69732936451883 + ], + [ + -1.2758329456882769, + 45.67983329952475 + ], + [ + -1.2048296947216648, + 45.66541909192764 + ], + [ + -1.132671287555203, + 45.65414603185962 + ], + [ + -1.0596425004559358, + 45.6460605191149 + ], + [ + -0.9860315446828637, + 45.641195849881335 + ], + [ + -0.9121289290487785, + 45.63957206345415 + ], + [ + -0.8382263134146932, + 45.641195849881335 + ], + [ + -0.7646153576416213, + 45.6460605191149 + ], + [ + -0.6915865705423541, + 45.65414603185962 + ], + [ + -0.6194281633758912, + 45.66541909192764 + ], + [ + -0.5484249124092802, + 45.67983329952475 + ], + [ + -0.4788570350357855, + 45.69732936451883 + ], + [ + -0.4109990838848604, + 45.717835378372605 + ], + [ + -0.3451188632883466, + 45.74126714306936 + ], + [ + -0.28147637237913264, + 45.76752855502099 + ], + [ + -0.22032277899334674, + 45.79651204162868 + ], + [ + -0.1618994284256634, + 45.828099047869124 + ], + [ + -0.10643689094968317, + 45.862160570006246 + ], + [ + -0.05415405186240015, + 45.898557733282416 + ], + [ + -0.0052572476439352095, + 45.93714241022631 + ], + [ + 0.04006054835828561, + 45.977757876027404 + ], + [ + 0.08162048750717361, + 46.020239497272584 + ], + [ + 0.11925855170983876, + 46.064415450216714 + ], + [ + 0.1528262007220691, + 46.11010746466963 + ], + [ + 0.18219095836881302, + 46.15713158952413 + ], + [ + 0.20723693536712018, + 46.205298975924464 + ], + [ + 0.22786528668819708, + 46.25441667408089 + ], + [ + 0.2439946016535771, + 46.30428843977188 + ], + [ + 0.25556122522587416, + 46.35471554664084 + ], + [ + 0.2625195092261366, + 46.40549760048509 + ], + [ + 0.264841992486353, + 46.45643335185111 + ] + ] + ], + "type": "Polygon" + }, + { + "coordinates": [ + [ + -7.554638665169478, + 46.18809087243807 + ] + ], + "type": "MultiPoint" + }, + { + "coordinates": [ + [ + -7.330187978222967, + 45.56760189825186 + ] + ], + "type": "MultiPoint" + }, + { + "coordinates": [ + [ + -6.705263704061509, + 46.64012898007186 + ] + ], + "type": "MultiPoint" + }, + { + "coordinates": [ + [ + -7.880712887272239, + 44.937709366865704 + ] + ], + "type": "MultiPoint" + }, + { + "coordinates": [ + [ + -7.1956933848559865, + 44.7047702702588 + ] + ], + "type": "MultiPoint" + }, + { + "coordinates": [ + [ + -7.010639654472471, + 45.29209346290613 + ] + ], + "type": "MultiPoint" + } + ], + "type": "GeometryCollection" + }, + "properties": { + "circles": [ + 2, + 3, + 4, + 5, + 6 + ], + "id": "bf93b0d0-29ef-11e8-b13f-295f3b40bd20", + "textGeometriesIndexes": [ + 10, + 11 + ], + "textValues": [ + "pino", + "palo" + ], + "title": "multi" + }, + "style": { + "Circle": { + "color": "#ffcc33", + "fillColor": "#ffffff", + "fillOpacity": 0.2, + "opacity": 1, + "radius": 10, + "weight": 3 + }, + "LineString": { + "color": "#ffcc33", + "editing": { + "fill": 1 + }, + "fillColor": "#ffffff", + "fillOpacity": 0.2, + "opacity": 1, + "weight": 3 + }, + "MultiLineString": { + "color": "#ffcc33", + "editing": { + "fill": 1 + }, + "fillColor": "#ffffff", + "fillOpacity": 0.2, + "opacity": 1, + "weight": 3 + }, + "MultiPoint": { + "iconColor": "blue", + "iconGlyph": "comment", + "iconShape": "square" + }, + "MultiPolygon": { + "color": "#ffcc33", + "editing": { + "fill": 1 + }, + "fillColor": "#ffffff", + "fillOpacity": 0.2, + "opacity": 1, + "weight": 3 + }, + "Point": { + "iconColor": "blue", + "iconGlyph": "comment", + "iconShape": "square" + }, + "Polygon": { + "color": "#ffcc33", + "editing": { + "fill": 1 + }, + "fillColor": "#ffffff", + "fillOpacity": 0.2, + "opacity": 1, + "weight": 3 + }, + "Text": { + "color": "#000000", + "font": "14px FontAwesome", + "fontFamily": "FontAwesome", + "fontSize": "14", + "fontSizeUom": "px", + "fontStyle": "normal", + "fontWeight": "normal", + "opacity": 1, + "textAlign": "center" + }, + "highlight": false, + "type": "GeometryCollection" + }, + "type": "Feature" +} \ No newline at end of file diff --git a/web/client/test-resources/markerIcon.png b/web/client/test-resources/markerIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..55914ed190b5d8ccfd7d31ca6e6f533b1bf9cafb GIT binary patch literal 1829 zcmV+=2io|FP)?8fhcZ${a zHvOsTBITq(fvVTvvg~Nbk#(qW0DanE()Ts!0Iweoi|6yes@<232+)KVmzZ08-*=~q zjYbsPfTYHVky|eTi6qb##CesqmmFNYKd#k!gPcG!Hs4vc|JW~H*=Yf67VYX}kE)Y0VLsu zhhHlxIzQHM~&{cujKOYuay3{0<@I{Ev%-#C=-w*4b|o|*r6Tj<1UjByRmH@QX< z2KNOp+T?kqb;XW*RDsNo&i2Ku$x;;AfW$D2oNpwWJDGswkI5I6Pjv6U_f3D!Jm8O2 zYp=hjC46E7+;$*2ge79A;iSP&2H-N5?!026{lPMA((!!R9cf75dWjvwyk=Z+gv9@`raGlu-pD*PZs$dU{VPofl z8E3n5nOR(VihHL$x3ILa^;@4@VgPJrWtAVM!FBYc477Hls$yzg%ZgnMnkuz8sciL} zXMDlt$6mHZf9ci>#LN^$!1Wk|;RCv_#PQ9FtYhgT%iJI55@ z?Z(+>T`;}rp&bW@4g_HIV^`eX+J1NoJdVuuXR1|K zUUO6mRKr~|^fJH+(8%E^;E$np-1)9wSH72XsmNIvbCFMYV&3%T6F+ArN{lcTGcN`cwAONMyFJE-h|Jz2C7HO;A zRHripo8;OZe)-#ZLxE9Oh-cK->!f2_Q?gwGtd_w;C)5eXP*pv-yk*rc-^c?2C|Npd zO=rjNE8r=~uad|tdPis97k#bqO0Hmo0Et~-cHgHZZ+KIk{1Ko><= z+S__dsJAy|7& z8+t!$-j_up!oi+O5Q06M03nQMstQpZ3xFclNjBTODNDn#?(0xGDzh6%7r}0r^cHV? z*Dp^io)9Wf3AR(hq5wnzgtOEkR9sCV0aOB@0zet``ZC?sRWJ1!B~#kq(F72Tzrr3vv z`MO2;g0m+GeZj`>e8S){Vc7T^!{gBm!r#~nRR|(r`fHI|$fy=gO%D;ITnszG# zaxg-$Q2_zepG67;L9(;1KM&Ljqe%NvT-Fq0(@Rc<(sE60UGkv!gJfHfZ(6AUn}A?A z7#jXYKM|0jA&7X-!()!o|Lm>?L~`LHs>DVZdaA%Q)iW-B$k&8aN`y%$l+Ku39#N#o z`|>~wkO&*SRG`!(8vwI1Gco(YAT+ literal 0 HcmV?d00001 diff --git a/web/client/utils/AnnotationsUtils.js b/web/client/utils/AnnotationsUtils.js index fcb1f69391..f74043d512 100644 --- a/web/client/utils/AnnotationsUtils.js +++ b/web/client/utils/AnnotationsUtils.js @@ -5,10 +5,13 @@ * This source code is licensed under the BSD-style license found in the * LICENSE file in the root directory of this source tree. */ + const uuidv1 = require('uuid/v1'); const LocaleUtils = require('./LocaleUtils'); +const {extraMarkers} = require('./MarkerUtils'); const {values} = require('lodash'); + const STYLE_CIRCLE = { color: '#ffcc33', opacity: 1, @@ -64,14 +67,84 @@ const DEFAULT_ANNOTATIONS_STYLES = { "MultiPolygon": STYLE_POLYGON }; +const rgbaTorgb = (rgba = "") => { + return rgba.indexOf("rgba") !== -1 ? `rgb${rgba.slice(rgba.indexOf("("), rgba.lastIndexOf(","))})` : rgba; +}; + +const textAlignTolabelAlign = (a) => (a === "start" && "lm") || (a === "end" && "rm") || "cm"; + const getStylesObject = ({type = "Point", geometries = []} = {}) => { return type === "GeometryCollection" ? geometries.reduce((p, {type: t}) => { p[t] = DEFAULT_ANNOTATIONS_STYLES[t]; return p; }, {type: "GeometryCollection"}) : {...DEFAULT_ANNOTATIONS_STYLES[type]}; }; + const getPropreties = (props = {}, messages = {}) => ({title: LocaleUtils.getMessageById(messages, "annotations.defaulttitle") || "Default title", id: uuidv1(), ...props}); +const annStyleToOlStyle = (type, style, label = "") => { + const s = style[type] || style; + switch (type) { + case "MultiPolygon": + case "Polygon": + case "Circle": + return { + "strokeColor": rgbaTorgb(s.color), + "strokeOpacity": s.opacity, + "strokeWidth": s.weight, + "fillColor": rgbaTorgb(s.fillColor), + "fillOpacity": s.fillOpacity + }; + case "LineString": + case "MultiLineString": + return { + "strokeColor": rgbaTorgb(s.color), + "strokeOpacity": s.opacity, + "strokeWidth": s.weight + }; + case "Text": + return { + "fontStyle": s.fontStyle, + "fontSize": s.fontSize, // in mapfish is in px + "fontFamily": s.fontFamily, + "fontWeight": s.fontWeight, + "labelAlign": textAlignTolabelAlign(s.textAlign), + "fontColor": rgbaTorgb(s.color), + "fontOpacity": s.opacity, + "label": label, + "fill": false, + "stroke": false + }; + case "Point": + case "MultiPoint": { + const externalGraphic = extraMarkers.markerToDataUrl(s); + return externalGraphic ? { + externalGraphic: externalGraphic, + "graphicWidth": 36, + "graphicHeight": 46, + "graphicXOffset": -18, + "graphicYOffset": -46 + } : { + "fillColor": "#0000AE", + "fillOpacity": 0.5, + "strokeColor": "#0000FF", + "pointRadius": 10, + "strokeOpacity": 1, + "strokeWidth": 1 + }; + } + default: + return { + "fillColor": "#FF0000", + "fillOpacity": 0, + "strokeColor": "#FF0000", + "pointRadius": 5, + "strokeOpacity": 1, + "strokeWidth": 1 + }; + } +}; + const AnnotationsUtils = { /** * function used to convert a geojson into a internal model. @@ -203,7 +276,59 @@ const AnnotationsUtils = { const properties = getPropreties(annotation.properties, messages); return {style, properties, ...annotation}; }, - removeDuplicate: (annotations) => values(annotations.reduce((p, c) => ({...p, [c.properties.id]: c}), {})) + removeDuplicate: (annotations) => values(annotations.reduce((p, c) => ({...p, [c.properties.id]: c}), {})), + /** + * Compress circle in a single MultyPolygon feature with style + * @param (Object) geometry + * @param (Object) properties + * @param (Object) style + * @return (OBject) feature + */ + circlesToMultiPolygon: ({geometries}, {circles}, style = STYLE_CIRCLE) => { + const coordinates = circles.reduce((coords, cIdx) => coords.concat([geometries[cIdx].coordinates]), []); + return {type: "Feature", geometry: {type: "MultiPolygon", coordinates}, properties: {id: uuidv1(), ms_style: annStyleToOlStyle("Circle", style)}}; + }, + /** + * Flatten text point to single point with style + * @param (Object) geometry + * @param (Object) properties + * @param (Object) style + * @return (array) features + */ + textToPoint: ({geometries}, {textGeometriesIndexes, textValues}, style = STYLE_TEXT) => { + return textGeometriesIndexes.map((tIdx, cIdx) => { + return {type: "Feature", geometry: geometries[tIdx], properties: {id: uuidv1(), ms_style: annStyleToOlStyle("Text", style, textValues[cIdx])}}; + }); + + }, + /** + * Flatten geometry collection + * @param (Object) GeometryCollection An annotation of type geometrycollection + * @return (array) an array of features + */ + flattenGeometryCollection: ({geometry, properties, style}) => { + const circles = properties.circles && AnnotationsUtils.circlesToMultiPolygon(geometry, properties, style.Circle) || []; + const texts = properties.textGeometriesIndexes && AnnotationsUtils.textToPoint(geometry, properties, style.Text) || []; + const skeep = (properties.circles || []).concat(properties.textGeometriesIndexes || []); + const features = geometry.geometries.filter((el, idx) => skeep.indexOf(idx) === -1) + .map((geom) => ({ + type: "Feature", + geometry: geom, + properties: {id: uuidv1(), ms_style: annStyleToOlStyle(geom.type, style[geom.type])} + })); + return features.concat(circles, texts); + }, + /** + * Adapt annotation features to print pdf + * @param (Array) features + * @param (Object) style + * @return (Array) features + */ + annotationsToPrint: (features = []) => { + return features.reduce((coll, f) => { + return f.geometry.type === "GeometryCollection" && coll.concat(AnnotationsUtils.flattenGeometryCollection(f)) || coll.concat({type: "Feature", geometry: f.geometry, properties: {...f.properties, ms_style: annStyleToOlStyle(f.geometry.type, f.style)}}); + }, []); + } }; module.exports = AnnotationsUtils; diff --git a/web/client/utils/MarkerUtils.js b/web/client/utils/MarkerUtils.js index 8e447ee84c..328805f9d6 100644 --- a/web/client/utils/MarkerUtils.js +++ b/web/client/utils/MarkerUtils.js @@ -12,6 +12,14 @@ const assign = require('object-assign'); const css = { fontawesome: require('raw-loader!./font-awesome.txt') }; +const baseImageUrl = require('../components/mapcontrols/annotations/img/markers_default.png'); +const shadowImageUrl = require('../components/mapcontrols/annotations/img/markers_shadow.png'); + +const baseImage = new Image(); +const shadowImage = new Image(); + +baseImage.src = baseImageUrl; +shadowImage.src = shadowImageUrl; const getNodeOfType = (node, condition) => { if (condition(node)) { @@ -52,16 +60,40 @@ const extraMarkers = { colors: ['red', 'orange-dark', 'orange', 'yellow', 'blue-dark', 'blue', 'cyan', 'purple', 'violet', 'pink', 'green-dark', 'green', 'green-light', 'black'], shapes: ['circle', 'square', 'star', 'penta'], - icons: [require('../components/mapcontrols/annotations/img/markers_default.png'), require('../components/mapcontrols/annotations/img/markers_shadow.png')] + icons: [baseImageUrl, shadowImageUrl], + images: [shadowImage, baseImage] }; const getOffsets = (color, shape) => { return [-extraMarkers.colors.indexOf(color) * extraMarkers.size[0] - 2, -extraMarkers.shapes.indexOf(shape) * extraMarkers.size[1]]; }; - const MarkerUtils = { extraMarkers: assign({}, extraMarkers, { getOffsets, + markerToDataUrl: ({iconColor, iconShape, iconGlyph}) => { + if (MarkerUtils.extraMarkers.images) { + let canvas = document.createElement('canvas'); + const size = extraMarkers.size; + canvas.width = size[0]; + canvas.height = size[1]; + // const c = document.getElementById("container"); + // c.insertBefore(canvas, c.children[0]) + const ctx = canvas.getContext("2d"); + + const offSet = getOffsets(iconColor, iconShape); + ctx.drawImage(extraMarkers.images[0], 4, 31, 35, 16); // shadowImage + ctx.drawImage(extraMarkers.images[1], Math.abs(offSet[0]), Math.abs(offSet[1]), size[0], size[1], 0, 0, size[0], size[1]); // iconImage + // glyph + ctx.font = "14px FontAwesome"; + ctx.fillStyle = "rgb(255,255,255)"; + ctx.textBaseline = "middle"; + ctx.textAlign = "center"; + ctx.fillText((MarkerUtils.getGlyphs("fontawesome"))[iconGlyph] || '', (size[0] / 2) - 2, (size[1] / 2) - 7); + const data = canvas.toDataURL("image/png"); + canvas = null; + return data; + } + }, matches: (style, marker) => { return style.iconColor === marker.color && style.iconShape === marker.shape; }, diff --git a/web/client/utils/PrintUtils.js b/web/client/utils/PrintUtils.js index 527faca410..1baaa5aed2 100644 --- a/web/client/utils/PrintUtils.js +++ b/web/client/utils/PrintUtils.js @@ -8,7 +8,7 @@ const CoordinatesUtils = require('./CoordinatesUtils'); const MapUtils = require('./MapUtils'); - +const AnnotationsUtils = require("./AnnotationsUtils"); const {isArray} = require('lodash'); @@ -18,6 +18,7 @@ const defaultScales = MapUtils.getGoogleMercatorScales(0, 21); const assign = require('object-assign'); +// Non รจ detto che sia uniforme!! const getGeomType = function(layer) { return layer.features && layer.features[0] ? layer.features[0].geometry.type : undefined; }; @@ -230,20 +231,21 @@ const PrintUtils = { }, vector: { map: (layer, spec) => ({ - type: 'Vector', - name: layer.name, - "opacity": layer.opacity || 1.0, - styleProperty: "ms_style", - styles: { - 1: PrintUtils.toOpenLayers2Style(layer, layer.style) - }, - geoJson: CoordinatesUtils.reprojectGeoJson({ - type: "FeatureCollection", - features: layer.features.map( f => ({...f, properties: {...f.properties, ms_style: 1}})) - }, - "EPSG:4326", - spec.projection) - }) + type: 'Vector', + name: layer.name, + "opacity": layer.opacity || 1.0, + styleProperty: "ms_style", + styles: { + 1: PrintUtils.toOpenLayers2Style(layer, layer.style) + }, + geoJson: CoordinatesUtils.reprojectGeoJson({ + type: "FeatureCollection", + features: layer.id === "annotations" && AnnotationsUtils.annotationsToPrint(layer.features) || layer.features.map( f => ({...f, properties: {...f.properties, ms_style: 1}})) + }, + "EPSG:4326", + spec.projection) + } + ) }, osm: { map: () => ({ @@ -329,6 +331,7 @@ const PrintUtils = { rgbaTorgb: (rgba = "") => { return rgba.indexOf("rgba") !== -1 ? `rgb${rgba.slice(rgba.indexOf("("), rgba.lastIndexOf(","))})` : rgba; }, + /** * Useful for print (Or generic Openlayers 2 conversion style) * http://dev.openlayers.org/docs/files/OpenLayers/Feature/Vector-js.html#OpenLayers.Feature.Vector.OpenLayers.Feature.Vector.style @@ -346,7 +349,7 @@ const PrintUtils = { // "graphicName": "circle", // "graphicOpacity": 0.4, "pointRadius": style.radius, - "strokeColor": PrintUtils.rgbaTorgb(style.fillColor), + "strokeColor": PrintUtils.rgbaTorgb(style.color), "strokeOpacity": style.opacity, "strokeWidth": style.weight // "strokeLinecap": "round", diff --git a/web/client/utils/__tests__/AnnotationsUtils-test.js b/web/client/utils/__tests__/AnnotationsUtils-test.js index cd3c1c98ef..5c500f18e4 100644 --- a/web/client/utils/__tests__/AnnotationsUtils-test.js +++ b/web/client/utils/__tests__/AnnotationsUtils-test.js @@ -7,7 +7,10 @@ */ const expect = require('expect'); -const {getAvailableStyler, getRelativeStyler, convertGeoJSONToInternalModel, DEFAULT_ANNOTATIONS_STYLES, createFont} = require('../AnnotationsUtils'); +const {getAvailableStyler, getRelativeStyler, convertGeoJSONToInternalModel, DEFAULT_ANNOTATIONS_STYLES, createFont, +circlesToMultiPolygon, textToPoint, flattenGeometryCollection} = require('../AnnotationsUtils'); + +const feature = require("json-loader!../../test-resources/Annotation.json"); describe('Test the AnnotationsUtils', () => { it('getAvailableStyler for point or MultiPoint', () => { @@ -189,4 +192,45 @@ describe('Test the AnnotationsUtils', () => { expect(createFont({fontStyle: "italic"})).toBe("italic normal 14px FontAwesome"); expect(createFont({fontWeight: "bold"})).toBe("normal bold 14px FontAwesome"); }); + + it('circlesToMultiPolygon', () => { + const {geometry, properties, style} = feature; + const f = circlesToMultiPolygon(geometry, properties, style.Circle); + expect(f).toExist(); + expect(f.type).toBe("Feature"); + expect(f.geometry.type).toBe("MultiPolygon"); + expect(f.properties.ms_style).toExist(); + expect(f.properties.ms_style.strokeColor).toBe(style.Circle.color); + expect(f.properties).toExist(); + + }); + it('textToPoint', () => { + const {geometry, properties, style} = feature; + const fts = textToPoint(geometry, properties, style.Text); + expect(fts).toExist(); + expect(fts.length).toBe(2); + expect(fts[0].type).toBe("Feature"); + expect(fts[0].geometry.type).toBe("MultiPoint"); + expect(fts[0].properties.ms_style).toExist(); + expect(fts[0].properties.ms_style.label).toBe("pino"); + expect(fts[0].properties).toExist(); + + }); + + it('flattenGeometryCollection', () => { + const fts = flattenGeometryCollection(feature); + expect(fts).toExist(); + expect(fts.length).toBe(9); + expect(fts[6].type).toBe("Feature"); + expect(fts[6].geometry.type).toBe("MultiPolygon"); + expect(fts[6].properties.ms_style).toExist(); + expect(fts[6].properties.ms_style.strokeColor).toBe(feature.style.Circle.color); + expect(fts[6].properties).toExist(); + expect(fts[7].type).toBe("Feature"); + expect(fts[7].geometry.type).toBe("MultiPoint"); + expect(fts[7].properties.ms_style).toExist(); + expect(fts[7].properties.ms_style.label).toBe("pino"); + expect(fts[7].properties).toExist(); + }); + }); diff --git a/web/client/utils/__tests__/MarkerUtils-test.js b/web/client/utils/__tests__/MarkerUtils-test.js index 4fddc58aa8..b2c4be0417 100644 --- a/web/client/utils/__tests__/MarkerUtils-test.js +++ b/web/client/utils/__tests__/MarkerUtils-test.js @@ -7,6 +7,7 @@ */ const expect = require('expect'); + const { extraMarkers, getGlyphs @@ -59,4 +60,12 @@ describe('Test the MarkerUtils', () => { expect(Object.keys(getGlyphs('fontawesome')).length > 0).toBe(true); expect(getGlyphs('fontawesome').comment).toExist(); }); + + it('markerToDataUrl', () => { + const style = { + iconShape: 'penta', + iconColor: 'green'}; + const dataUrl = extraMarkers.markerToDataUrl(style); + expect(dataUrl).toExist(); + }); });