Skip to content

Commit

Permalink
Geomaps: clear markers when switching maps (#53).
Browse files Browse the repository at this point in the history
There is still a bug: new markers are added to *every* geomap.

See ticket 53.
  • Loading branch information
jri committed Nov 13, 2011
1 parent ac09e82 commit 309c0ae
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 14 deletions.
Expand Up @@ -70,6 +70,7 @@ public Geomap getGeomap(@PathParam("id") long geomapId) {
@Path("/{id}/topic/{topic_id}")
@Override
public void addTopicToGeomap(@PathParam("id") long geomapId, @PathParam("topic_id") long topicId) {
logger.info("### Adding topic " + topicId + " to geomap " + geomapId);
AssociationModel model = new AssociationModel("dm4.geomaps.geotopic_mapcontext",
new TopicRoleModel(geomapId, "dm4.core.default"),
new TopicRoleModel(topicId, "dm4.topicmaps.topicmap_topic"));
Expand Down
Expand Up @@ -48,6 +48,10 @@ function GeoMapRenderer() {
}
}

this.clear = function() {
marker_layers["markers"].remove_all_markers()
}

this.select_topic = function(topic_id) {
// ### set_highlight_object(topic_id)
return {
Expand Down Expand Up @@ -150,6 +154,20 @@ function GeoMapRenderer() {
this.remove_marker = function(topic_id) {
markers_layer.removeMarker(markers[topic_id])
}

this.remove_all_markers = function() {
iterate_markers(function(marker) {
markers_layer.removeMarker(marker)
})
}

// ---

function iterate_markers(visitor_func) {
for (var topic_id in markers) {
visitor_func(markers[topic_id])
}
}
}

/**
Expand Down Expand Up @@ -179,6 +197,7 @@ function GeoMapRenderer() {
}

this.put_on_canvas = function(no_history_update) {
dm4c.canvas.clear()
display_topics()
restore_selection()

Expand All @@ -195,15 +214,16 @@ function GeoMapRenderer() {

this.add_topic = function(id, type_uri, value, x, y) {
if (x != undefined && y != undefined) {
if (LOG_GEOMAPS) dm4c.log("Geomap.add_topic(): adding topic to model\n..... id=" + id +
", type_uri=\"" + type_uri + "\", x=" + x + ", y=" + y)
if (LOG_GEOMAPS) dm4c.log("Geomap.add_topic(): adding topic to model of geomap " + topicmap_id +
"\n..... id=" + id + ", type_uri=\"" + type_uri + "\", x=" + x + ", y=" + y)
// update DB
dm4c.restc.add_topic_to_geomap(topicmap_id, id) // ### FIXME: add only once
// update memory
topics[id] = new GeomapTopic(id, type_uri, value, x, y)
} else {
if (LOG_GEOMAPS) dm4c.log("Geomap.add_topic(): adding topic to model ABORTED -- topic has " +
"no coordinates\n..... id=" + id + ", type_uri=\"" + type_uri + "\", value=\"" + value + "\"")
if (LOG_GEOMAPS) dm4c.log("Geomap.add_topic(): adding topic to model of geomap " + topicmap_id +
" ABORTED -- topic has no coordinates\n..... id=" + id + ", type_uri=\"" + type_uri +
"\", value=\"" + value + "\"")
}
}

Expand Down
@@ -1,5 +1,10 @@
/**
* This interface is implemented by classes who render the left part of the DeepaMehta window (the "canvas").
* An abstraction of the view component that occupies the left part of the DeepaMehta window (the "canvas").
* The abstraction comprises:
* - A model of the topics and association that are currently displayed.
* - A model for the current selection.
* - A model for the current translation.
* - The view element (the "dom" property).
*
* The Webclient is coded to this interface.
*
Expand Down Expand Up @@ -46,6 +51,11 @@ function TopicmapRenderer() {
*/
this.remove_association = function(assoc_id, refresh_canvas) {}

/**
* Clears the model: removes all topics and associations. Resets the selection and translation.
*/
this.clear = function() {}

// ---

/**
Expand All @@ -67,8 +77,6 @@ function TopicmapRenderer() {

this.refresh = function() {}

this.clear = function() {}

/**
* @param size an object with "width" and "height" properties.
*/
Expand Down
Expand Up @@ -193,6 +193,15 @@ function Canvas(width, height) {

// ---

this.clear = function() {
// refresh GUI
translate(-trans_x, -trans_y) // reset translation
// update model
init_model()
}

// ---

this.select_topic = function(topic_id) {
var topic = dm4c.fetch_topic(topic_id)
set_highlight_object(topic_id)
Expand Down Expand Up @@ -245,13 +254,6 @@ function Canvas(width, height) {
draw()
}

this.clear = function() {
// refresh GUI
translate(-trans_x, -trans_y) // reset translation
// update model
init_model()
}

this.resize = function(size) {
resize_canvas(size)
}
Expand Down

0 comments on commit 309c0ae

Please sign in to comment.