Wiki source code of Map Editor
Last modified by Simon Urli on 2020/03/20 18:00
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{include reference="Maps.Code.CommonMacros" /}} | ||
2 | |||
3 | {{velocity}} | ||
4 | #if ("$!request.action" == "createItems") | ||
5 | #set ($itemsSpace = $request.mapItemsSpace) | ||
6 | #set ($allMapItems = $request.mapItemsGeoJSON) | ||
7 | #set ($allMapItems = $allMapItems.replaceAll("'", "'")) | ||
8 | #set ($allMapItems = $jsontool.fromString($allMapItems)) | ||
9 | ## Start processing each map item separately | ||
10 | #set ($pointCount = 0) | ||
11 | #set ($shapeCount = 0) | ||
12 | #if ($allMapItems.features.size() > 0) | ||
13 | == Pages created == | ||
14 | #end | ||
15 | #foreach ($mapItem in $allMapItems.features) | ||
16 | ## Checking shape because circle's type is also "Point" | ||
17 | #set ($isShape = true) | ||
18 | #set ($title = "$!mapItem.properties.title") | ||
19 | #if ("$!mapItem.geometry.type" == 'Point') | ||
20 | #if ("$!mapItem.properties.radius" == '') | ||
21 | #set ($isShape = false) | ||
22 | ## Its a point | ||
23 | #if ($title == '') | ||
24 | #set ($title = 'Point-' + $pointCount) | ||
25 | #set ($pointCount = $pointCount + 1) | ||
26 | #end | ||
27 | #set ($pointDoc = $xwiki.getDocument("${itemsSpace}.${title}")) | ||
28 | #set ($discard = $pointDoc.setTitle($title)) | ||
29 | #set ($discard = $pointDoc.setContent($mapItem.properties.content)) | ||
30 | #set ($pointObj = $pointDoc.newObject('Maps.Code.PointClass')) | ||
31 | #set ($discard = $pointObj.set('latitude', $mapItem.geometry.coordinates[1])) | ||
32 | #set ($discard = $pointObj.set('longitude', $mapItem.geometry.coordinates[0])) | ||
33 | #set ($includePopup = $mapItem.properties.addPopup) | ||
34 | #if ($includePopup) | ||
35 | #set ($discard = $pointObj.set('includePopup', 1)) | ||
36 | #else | ||
37 | #set ($discard = $pointObj.set('includePopup', 0)) | ||
38 | #end | ||
39 | #set ($discard = $pointObj.set('options', $jsontool.serialize($mapItem.properties.style))) | ||
40 | #set ($discard = $pointDoc.save()) | ||
41 | * [[$pointDoc.fullName]] | ||
42 | #end | ||
43 | #end | ||
44 | ## Check if its a shape | ||
45 | #if ($isShape) | ||
46 | #if ($title == '') | ||
47 | #set ($title = 'Shape-' + $shapeCount) | ||
48 | #set ($shapeCount = $shapeCount + 1) | ||
49 | #end | ||
50 | #set ($shapeDoc = $xwiki.getDocument("${itemsSpace}.${title}")) | ||
51 | #set ($discard = $shapeDoc.setTitle($title)) | ||
52 | #set ($discard = $shapeDoc.setContent($mapItem.properties.content)) | ||
53 | #set ($shapeObj = $shapeDoc.newObject('Maps.Code.ShapeClass')) | ||
54 | #set ($includePopup = $mapItem.properties.addPopup) | ||
55 | #if ($includePopup) | ||
56 | #set ($discard = $shapeObj.set('includePopup', 1)) | ||
57 | #else | ||
58 | #set ($discard = $shapeObj.set('includePopup', 0)) | ||
59 | #end | ||
60 | #set ($shapeGeoJSON = {"type": "FeatureCollection", "features": [$mapItem]}) | ||
61 | #set ($discard = $shapeObj.set('shapeGeoJSON', $jsontool.serialize($shapeGeoJSON))) | ||
62 | #set ($discard = $shapeObj.set('style', $jsontool.serialize($mapItem.properties.style))) | ||
63 | #set ($discard = $shapeDoc.save()) | ||
64 | * [[$shapeDoc.fullName]] | ||
65 | #end | ||
66 | #end | ||
67 | #if ($allMapItems.features.size() > 0) | ||
68 | ---- | ||
69 | #end | ||
70 | #end | ||
71 | #set ($discard = $xwiki.ssx.use('Maps.Code.LeafletUtils')) | ||
72 | #set ($discard = $xwiki.jsx.use('Maps.Code.LeafletUtils')) | ||
73 | #set ($discard = $xwiki.jsx.use('Maps.MapEditor')) | ||
74 | {{html wiki="true" clean="false"}} | ||
75 | (% class="row" %)((( | ||
76 | (% class="col-sm-12" %)((( | ||
77 | ## Preview of the map | ||
78 | <p class="xform"><span class="xHint">$services.localization.render('intmap.mapEditor.hint')</span></p> | ||
79 | (% class="map-wrapper" %)((( | ||
80 | <div class="map-preview map-editor-preview" id="map-${util.generateRandomString(5)}" style="width: 100%; height: 450px;"></div> | ||
81 | (% class="map-search-filter" %)((( | ||
82 | #displayLocationSearch() | ||
83 | ))) | ||
84 | (% id="map-search-close" %)((( | ||
85 | <i class="fa fa-arrow-left"></i> | ||
86 | ))) | ||
87 | (% id="map-item-properties" class="xform" %)((( | ||
88 | <dl> | ||
89 | <dt> | ||
90 | <label for="item-p-title">$services.localization.render('intmap.mapEditor.itemPropTitle')</label> | ||
91 | <span class="xHint">$services.localization.render('intmap.mapEditor.itemPropTitleHint')</span> | ||
92 | </dt> | ||
93 | <dd><input type="text" id="item-p-title" /></dd> | ||
94 | <dt> | ||
95 | <label for="item-p-content">$services.localization.render('intmap.mapEditor.itemPropContent')</label> | ||
96 | <span class="xHint">$services.localization.render('intmap.mapEditor.itemPropContentHint')</span> | ||
97 | </dt> | ||
98 | <dd><textarea id="item-p-content"></textarea></dd> | ||
99 | <dt> | ||
100 | <input type="checkbox" id="item-p-addPopup" /> | ||
101 | <label for="item-p-addPopup">Add Popup</label> | ||
102 | </dt> | ||
103 | <dt> | ||
104 | <label for="item-p-style">$services.localization.render('intmap.mapEditor.itemPropStyle')</label> | ||
105 | <span class="xHint">$services.localization.render('intmap.mapEditor.itemPropStyleHint')</span> | ||
106 | </dt> | ||
107 | <dd><textarea id="item-p-style"></textarea></dd> | ||
108 | <button id="item-p-update" class="btn btn-primary" type="button">$services.localization.render('intmap.mapEditor.itemPropUpdate')</button> | ||
109 | <button id="item-p-delete" class="btn btn-danger" type="button">$services.localization.render('intmap.mapEditor.itemPropDelete')</button> | ||
110 | <button id="item-p-close" class="btn btn-secondary" type="button">$services.localization.render('intmap.mapEditor.itemPropClose')</button> | ||
111 | </dl> | ||
112 | ))) | ||
113 | ))) | ||
114 | ---- | ||
115 | ))) | ||
116 | (% class="col-sm-12" %)((( | ||
117 | <form class="xform" action="" method="POST"> | ||
118 | <input type="hidden" id="mapItemsGeoJSON" name="mapItemsGeoJSON" /> | ||
119 | <dl> | ||
120 | <dt> | ||
121 | <label for="mapItemsSpace">$services.localization.render('intmap.mapEditor.mapItemsSpace')</label> | ||
122 | <span class="xHint">$services.localization.render('intmap.mapEditor.mapItemsSpaceHint')</span> | ||
123 | </dt> | ||
124 | <dd> | ||
125 | <input type="text" id="mapItemsSpace" name="mapItemsSpace" /> | ||
126 | </dd> | ||
127 | </dl> | ||
128 | <button class="btn btn-primary" name="action" value="createItems">$services.localization.render('intmap.mapEditor.createItems')</button> | ||
129 | </form> | ||
130 | ))) | ||
131 | ))) | ||
132 | {{/html}} | ||
133 | {{/velocity}} |