Skip to content

Commit b4c783e

Browse files
committed
New simple message
Better LeafletPlugin
1 parent 432c7cf commit b4c783e

File tree

2 files changed

+138
-21
lines changed

2 files changed

+138
-21
lines changed

[email protected]

+72-15
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@ interface LocationData extends ComponentData {
2020
coordinates: {
2121
latitude: number,
2222
longitude: number
23-
}
24-
sensitivity: number
23+
},
24+
sensitivity: number,
25+
showMarker: boolean,
26+
markerPictureUrl: string;
27+
markerPopupText: string;
28+
showUsers: boolean,
29+
containerClass: string,
2530
}
2631

2732
interface LocationState {
@@ -70,7 +75,10 @@ export class LeafletLocation extends Component<LocationData, LocationState> {
7075
"additionalProperties": false,
7176
"required": [
7277
"coordinates",
73-
"sensitivity"
78+
"sensitivity",
79+
"showMarker",
80+
"markerPictureUrl",
81+
"showUsers"
7482
],
7583
"definitions": {
7684
"location": {
@@ -103,6 +111,36 @@ export class LeafletLocation extends Component<LocationData, LocationState> {
103111
"title": "Proximity to location (km)",
104112
"default": 0.1,
105113
"minimum": 0.0
114+
},
115+
"showMarker": {
116+
"$id": "#/properties/showMarker",
117+
"type": "boolean",
118+
"title": "Show marker",
119+
"default": true
120+
},
121+
"markerPictureUrl": {
122+
"$id": "#/properties/markerPictureUrl",
123+
"type": "string",
124+
"title": "Marker picture url",
125+
"default": "http://assets.stickpng.com/images/58568b014f6ae202fedf2717.png"
126+
},
127+
"markerPopupText": {
128+
"$id": "#/properties/markerPopupText",
129+
"type": "string",
130+
"title": "Marker popup text",
131+
"default": "This is your goal!"
132+
},
133+
"showUsers": {
134+
"$id": "#/properties/showUsers",
135+
"type": "boolean",
136+
"title": "Show users",
137+
"default": true
138+
},
139+
"containerClass": {
140+
"$id": "#/properties/containerClass",
141+
"type": "string",
142+
"title": "Map container class name",
143+
"default": "leaflet-map-container"
106144
}
107145
}
108146
};
@@ -112,7 +150,12 @@ export class LeafletLocation extends Component<LocationData, LocationState> {
112150
example: {
113151
longitude: 47.541246,
114152
latitude: 19.243312,
153+
showMarker: true,
154+
markerPictureUrl: "http://assets.stickpng.com/images/58568b014f6ae202fedf2717.png",
155+
showUsers: true,
156+
markerPopupText: "Your goal is here!",
115157
players: ["test"],
158+
containerClass: "leaflet-map-container",
116159
playerLocations: {
117160
"test": {
118161
longitude: 47.541497,
@@ -121,8 +164,8 @@ export class LeafletLocation extends Component<LocationData, LocationState> {
121164
}
122165
}
123166
},
124-
template: `<div id="leaflet-plugin-container-{{id}}" style="width: 90%; margin: 0 auto; height: 50vh">
125-
<div id="leaflet-map-{{id}}"></div>
167+
template: `<div id="leaflet-plugin-container-{{id}}" class="{{containerClass}}" style="width: 90%; margin: 0 auto; height: 50vh">
168+
126169
</div>
127170
<script>
128171
var leafletPluginMapId = "{{id}}";
@@ -144,10 +187,8 @@ function createMapSetup(mapId) {
144187
145188
var map;
146189
if (container != null && leafletPluginMaps[mapId] != null && leafletPluginMaps != undefined) {
147-
console.log("Loading map from cache");
148190
map = leafletPluginMaps[mapId];
149191
} else {
150-
console.log("Creating new map");
151192
document.getElementById('leaflet-plugin-container-' + mapId).innerHTML = "<div id=" + mapName + "></div>";
152193
map = L.map(mapName);
153194
@@ -159,21 +200,27 @@ function createMapSetup(mapId) {
159200
attribution: '&copy; <a href=&quot;http://osm.org/copyright&quot;>OpenStreetMap</a> contributors'
160201
}).addTo(map);
161202
162-
var mainIcon = L.icon({
163-
iconUrl: "https://tcbmag.com/wp-content/uploads/2020/03/7fe12969-5641-4ce0-9395-e325cee0e830.jpg",
164-
iconSize: [50, 50],
165-
});
166-
var mainMarker = L.marker([mapLatitude, mapLongitude], { icon: mainIcon }).addTo(map);
167-
mainMarker.bindPopup("Célpont: {{latitude}}, {{longitude}}")
203+
if ("{{showMarker}}" === "true") {
204+
var mainIcon = L.icon({
205+
iconUrl: "{{markerPictureUrl}}",
206+
iconSize: [50, 50],
207+
});
208+
var mainMarker = L.marker([mapLatitude, mapLongitude], { icon: mainIcon }).addTo(map);
209+
var popupText = "{{markerPopupText}}";
210+
if (popupText.length !== 0)
211+
mainMarker.bindPopup(popupText)
212+
}
213+
168214
}
169215
170216
if (leafletPluginMarkers[mapId] !== undefined) {
171217
leafletPluginMarkers[mapId].forEach(marker => map.removeLayer(marker));
172218
leafletPluginMarkers[mapId] = [];
173219
}
174220
175-
updateMarkers(mapId, map);
176-
221+
if ("{{showUsers}}" === "true") {
222+
updateMarkers(mapId, map);
223+
}
177224
return map;
178225
}
179226
}
@@ -218,6 +265,11 @@ function updateMarkers(mapId, map) {
218265
feedId: createFeed("leafletHint", {
219266
latitude: information.data.coordinates.latitude,
220267
longitude: information.data.coordinates.longitude,
268+
showMarker: information.data.showMarker,
269+
markerPictureUrl: information.data.markerPictureUrl,
270+
markerPopupText: information.data.markerPopupText,
271+
showUsers: information.data.showUsers,
272+
containerClass: information.data.containerClass,
221273
id: information.id,
222274
}),
223275
players: [],
@@ -251,6 +303,11 @@ function updateMarkers(mapId, map) {
251303
updateFeed(ctx.feedId, {
252304
latitude: information.data.coordinates.latitude,
253305
longitude: information.data.coordinates.longitude,
306+
showMarker: information.data.showMarker,
307+
markerPictureUrl: information.data.markerPictureUrl,
308+
markerPopupText: information.data.markerPopupText,
309+
showUsers: information.data.showUsers,
310+
containerClass: information.data.containerClass,
254311
players: ctx.players,
255312
playerLocations: ctx.playerLocations,
256313
id: information.id

[email protected]

+66-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,68 @@ interface MessageState {
2323
messageId: string
2424
}
2525

26+
export class SimpleMessage extends Component<HtmlMessageData, MessageState> {
27+
28+
description = "SimpleMessage component allows you to show basic text message to the user.\n" +
29+
"Will signal the next components and stays active.";
30+
31+
schema: JSONSchema7 = {
32+
"$schema": "http://json-schema.org/draft-07/schema",
33+
"type": "object",
34+
"additionalProperties": false,
35+
"required": [
36+
"message"
37+
],
38+
"properties": {
39+
"message": {
40+
"$id": "#/properties/message",
41+
"type": "string",
42+
"title": "Message",
43+
"default": "Default message"
44+
}
45+
}
46+
};
47+
48+
doCleanUpOnCompletion = false;
49+
defaultCleanUpEnabled = false;
50+
51+
outputTemplates: OutputTemplates = {
52+
simpleMessage: {
53+
example: {
54+
message: "Example message!"
55+
},
56+
template: `<p>{{message}}</p>`
57+
}
58+
};
59+
60+
componentStartEvent = () => {
61+
const component = getComponentInformation<HtmlMessageData>();
62+
const [, setCtx] = this.useState();
63+
64+
const feedId = createFeed("simpleMessage", {
65+
message: component.data.message
66+
});
67+
setCtx({ messageId: feedId });
68+
69+
dispatchNextComponentEvent(component.nextComponents);
70+
}
71+
72+
componentCleanUp = () => {
73+
const [ctx,] = this.useState();
74+
removeFeed(ctx.messageId);
75+
updateStatus("idle");
76+
subscribeToEvent(BuiltInEvents.ComponentStart)
77+
unsubscribeFromEvent(BuiltInEvents.ComponentReset);
78+
unsubscribeFromEvent(BuiltInEvents.ComponentEnd);
79+
}
80+
81+
componentCompleted = () => {
82+
83+
}
84+
}
85+
86+
registerComponent(new SimpleMessage());
87+
2688
export class HtmlMessage extends Component<HtmlMessageData, MessageState> {
2789

2890
description = "HtmlMessage component allows you to show custom html content to the user.\n" +
@@ -49,21 +111,19 @@ export class HtmlMessage extends Component<HtmlMessageData, MessageState> {
49111
defaultCleanUpEnabled = false;
50112

51113
outputTemplates: OutputTemplates = {
52-
message: {
114+
htmlMessage: {
53115
example: {
54-
message: "Example message!"
116+
message: "<p>Example message!</p>"
55117
},
56-
template: `<div>
57-
<p>{{message}}</p>
58-
</div>`
118+
template: `{{message}}`
59119
}
60120
};
61121

62122
componentStartEvent = () => {
63123
const component = getComponentInformation<HtmlMessageData>();
64124
const [, setCtx] = this.useState();
65125

66-
const feedId = createFeed("message", {
126+
const feedId = createFeed("htmlMessage", {
67127
message: component.data.message
68128
});
69129
setCtx({ messageId: feedId });

0 commit comments

Comments
 (0)