Commit 22b5ffd6 authored by Gloria's avatar Gloria
Browse files

posDelete, dmx domainTopics

parent 137c1923
......@@ -11,7 +11,7 @@ import java.util.Iterator;
import java.util.Map;
import java.util.logging.Logger;
import java.util.List; // gevlish
import java.util.List;
import org.codehaus.jettison.json.JSONArray;
......
......@@ -21,6 +21,7 @@ import systems.dmx.core.service.Transactional;
import systems.dmx.core.service.event.PostCreateTopic;
import systems.dmx.core.service.event.PostUpdateTopic;
import systems.dmx.core.service.event.PreSendTopic;
import systems.dmx.core.service.event.PostDeleteTopic;
import systems.dmx.core.service.CoreService;
......@@ -58,7 +59,8 @@ import java.util.logging.Logger;
@Produces("application/json")
public class GeomapsPlugin extends PluginActivator implements GeomapsService, GeomapsConstants, PostCreateTopic,
PostUpdateTopic,
PreSendTopic {
PreSendTopic,
PostDeleteTopic {
private static final String GEOCODER_URL = "https://nominatim.openstreetmap.org/search?" +
"street=%s&postalcode=%s&city=%s&country=%s&format=json&limit=1";
......@@ -294,7 +296,13 @@ public class GeomapsPlugin extends PluginActivator implements GeomapsService, Ge
}
}
}
@Override
public void postDeleteTopic(TopicModel topic) {
logger.info("###PostDeleteTopic " + topic);
// send remove-domain-topic message
me.removeDomainTopic(null, topic.getId());
}
// ---
......@@ -563,7 +571,7 @@ public class GeomapsPlugin extends PluginActivator implements GeomapsService, Ge
sendToAll(new JSONObject()
.put("type", "removeDomainTopic")
.put("args", new JSONObject()
.put("fromGeoCoord", fromGeoCoord.toJSON())
.put("fromGeoCoord", fromGeoCoord != null ? fromGeoCoord.toJSON() : JSONObject.NULL)
.put("domainTopicId", domainTopicId)
)
);
......
......@@ -2,7 +2,7 @@
<l-map class="dmx-geomap-renderer" :center.sync="center" :zoom.sync="zoom" :options="options" ref="geomapRef"
@ready="ready">
<l-tile-layer :url="url"></l-tile-layer>
<l-marker v-for="marker in markers" :key="marker.domainTopics[0].id" :lat-lng="marker.coords"
<l-marker v-for="marker in markers" :key="marker.id" :lat-lng="marker.coords"
:icon="marker.iconMarker"
@popupopen="popupOpen(marker.domainTopics, marker.id, $event)">
......@@ -22,7 +22,7 @@ import {LMap, LTileLayer, LMarker, LPopup} from 'vue2-leaflet'
import 'leaflet/dist/leaflet.css'
let popup
const ICON_SCALING = 0.013 // max value = 0.014 (without height cut)
const ICON_SCALING = 0.0125 // max value = 0.014 (without height cut)
export default {
......@@ -126,35 +126,21 @@ export default {
initMarkers () {
this.dmx.icons.ready.then(() => {
for (let i = 0; i < this.geoMarkers.length; i++) {
if (this.geoMarkers[i].domainTopics.length > 0) {
if (this.geoMarkers[i].domainTopics[0].assoc) {
this.selectSpot(this.geoMarkers[i])
} else {
this.$store.dispatch('_getDomainTopics', this.geoMarkers[i].geoCoordTopic.id).then(topics => {
console.log('_getDomainTopics')
this.geoMarkers[i].domainTopics = topics
this.selectSpot(this.geoMarkers[i], i)
})
}
// NOSPOT (remove marker)
if (this.geoMarkers[i].domainTopics.length === 0) {
this.markers.splice(i, 1)
// SINGLESPOT
} else if (this.geoMarkers[i].domainTopics.length > 1) {
this.pushMarker(this.geoMarkers[i], '\uf041', '#4B87C3')
// MULTISPOT
} else if (this.geoMarkers[i].domainTopics.length === 1) {
this.pushMarker(this.geoMarkers[i],
this.geoMarkers[i].domainTopics[0].icon,
this.geoMarkers[i].domainTopics[0].iconColor)
}
}
})
console.log('geoMarkers', this.geoMarkers.length)
console.log('markers', [this.markers])
},
selectSpot (geoMarker, index) {
// NOSPOT
if (geoMarker.domainTopics.length === 0) {
this.markers.splice(index, 1)
// SINGLESPOT
} else if (geoMarker.domainTopics.length > 1) {
this.pushMarker(geoMarker, '\uf041', '#4B87C3')
// MULTISPOT
} else if (geoMarker.domainTopics.length === 1) {
this.pushMarker(geoMarker, geoMarker.domainTopics[0].icon, geoMarker.domainTopics[0].iconColor)
}
// console.log('markers', this.markers)
},
createLeafletIcon (icon, color) {
......
......@@ -33,10 +33,10 @@ export default function GeomapsService (dmx, http) {
// super(geomap.topic)
this.id = geomap.topic.id
this.viewProps = geomap.viewProps
this.geoMarkers = this.instDomains(geomap.geoMarkers)
this.geoMarkers = this.instDomainTopics(geomap.geoMarkers)
}
instDomains (array) {
instDomainTopics (array) {
for (let i = 0; i < array.length; i++) {
array[i].domainTopics = dmx.utils.instantiateMany(array[i].domainTopics, dmx.Topic)
}
......
const state = {
geomap: undefined, // the rendered geomap (Geomap, see geomaps-service.js)
// {
// id:
// viewProps:
// geoMarkers: [
// {
// geoCoordTopic: {}
// domainTopics: []
// }
// ]
// }
writable: false // if the rendered geomap is writable by the current user (Boolean)
}
export default ({dmx}) => {
const actions = {
const state = {
geomap: undefined, // the rendered geomap (Geomap, see geomaps-service.js)
// {
// id:
// viewProps:
// geoMarkers: [
// {
// geoCoordTopic: {}
// domainTopics: []
// }
// ]
// }
writable: false // if the rendered geomap is writable by the current user (Boolean)
}
// Test action from webclient to delete topic
_processDirectives ({dispatch}, directives) {
if (state.geomap) {
directives.forEach(dir => {
if (dir.type === 'DELETE_TOPIC') {
console.log('domainTopicId', dir.arg.id)
deleteTopic(dir.arg.id)
}
})
} else {
console.log('No geomap loaded')
}
},
const actions = {
// WebSocket messages
// WebSocket messages
_addDomainTopic (_, {toGeoCoord, domainTopic}) {
const dt = new dmx.Topic(domainTopic)
console.log('ADD DOMAIN TOPIC')
if (state.geomap) {
addTopic(state, toGeoCoord, dt)
} else {
console.log('No geomap loaded')
}
},
_addDomainTopic (_, {toGeoCoord, domainTopic}) {
console.log('ADD DOMAIN TOPIC')
if (state.geomap) {
addTopic(toGeoCoord, domainTopic)
} else {
console.log('No geomap loaded')
}
},
_removeDomainTopic (_, {fromGeoCoord, domainTopicId}) {
if (state.geomap) {
if (!fromGeoCoord) {
console.log('DELETE DOMAIN TOPIC')
deleteTopic(state, domainTopicId)
} else {
console.log('REMOVE DOMAIN TOPIC')
removeTopic(state, fromGeoCoord, domainTopicId)
}
} else {
console.log('No geomap loaded')
}
},
_removeDomainTopic (_, {fromGeoCoord, domainTopicId}) {
console.log('REMOVE DOMAIN TOPIC')
if (state.geomap) {
removeTopic(fromGeoCoord, domainTopicId)
} else {
console.log('No geomap loaded')
_moveDomainTopic (_, {fromGeoCoord, toGeoCoord, domainTopic}) {
const dt = new dmx.Topic(domainTopic)
console.log('MOVE DOMAIN TOPIC')
if (state.geomap) {
addTopic(state, toGeoCoord, dt)
removeTopic(state, fromGeoCoord, dt.id)
} else {
console.log('No geomap loaded')
}
}
},
}
_moveDomainTopic (_, {fromGeoCoord, toGeoCoord, domainTopic}) {
console.log('MOVE DOMAIN TOPIC')
if (state.geomap) {
addTopic(toGeoCoord, domainTopic)
removeTopic(fromGeoCoord, domainTopic.id)
} else {
console.log('No geomap loaded')
}
return {
state,
actions
}
}
function addTopic (geoCoord, domainTopic) {
function addTopic (state, geoCoord, domainTopic) {
let geoMarkerExist = false
let geoMarkerIndex = -1
for (let i = 0; i < state.geomap.geoMarkers.length; i++) {
......@@ -85,20 +85,11 @@ function addTopic (geoCoord, domainTopic) {
}
function removeTopic (geoCoord, domainTopicId) {
for (let i = 0; i < state.geomap.geoMarkers.length; i++) {
if (state.geomap.geoMarkers[i].geoCoordTopic.id === geoCoord.id) {
state.geomap.geoMarkers[i].domainTopics = state.geomap.geoMarkers[i].domainTopics.filter(
data => data.id !== domainTopicId)
}
}
}
function deleteTopic (domainTopicId) {
function deleteTopic (state, domainTopicId) {
for (let i = 0; i < state.geomap.geoMarkers.length; i++) {
if (state.geomap.geoMarkers[i].domainTopics.find(elem => elem.id === domainTopicId)) {
if (state.geomap.geoMarkers[i].domainTopics.length === 1) {
console.log('index', i)
// console.log('index', i)
state.geomap.geoMarkers.splice(i, 1)
} else {
removeTopic(state.geomap.geoMarkers[i].geoCoordTopic, domainTopicId)
......@@ -107,7 +98,11 @@ function deleteTopic (domainTopicId) {
}
}
export default {
state,
actions
function removeTopic (state, geoCoord, domainTopicId) {
for (let i = 0; i < state.geomap.geoMarkers.length; i++) {
if (state.geomap.geoMarkers[i].geoCoordTopic.id === geoCoord.id) {
state.geomap.geoMarkers[i].domainTopics = state.geomap.geoMarkers[i].domainTopics.filter(
elem => elem.id !== domainTopicId)
}
}
}
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