Mercurial > hg > extraction-interface
comparison geotemco/js/Map/PlacenamePopup.js @ 0:b12c99b7c3f0
commit for previous development
| author | Zoe Hong <zhong@mpiwg-berlin.mpg.de> |
|---|---|
| date | Mon, 19 Jan 2015 17:13:49 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:b12c99b7c3f0 |
|---|---|
| 1 /* | |
| 2 * PlacenamePopup.js | |
| 3 * | |
| 4 * Copyright (c) 2012, Stefan Jänicke. All rights reserved. | |
| 5 * | |
| 6 * This library is free software; you can redistribute it and/or | |
| 7 * modify it under the terms of the GNU Lesser General Public | |
| 8 * License as published by the Free Software Foundation; either | |
| 9 * version 3 of the License, or (at your option) any later version. | |
| 10 * | |
| 11 * This library is distributed in the hope that it will be useful, | |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 * Lesser General Public License for more details. | |
| 15 * | |
| 16 * You should have received a copy of the GNU Lesser General Public | |
| 17 * License along with this library; if not, write to the Free Software | |
| 18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, | |
| 19 * MA 02110-1301 USA | |
| 20 */ | |
| 21 | |
| 22 /** | |
| 23 * @class PlacenamePopup | |
| 24 * specific map popup for showing and interacting on placename labels | |
| 25 * @author Stefan Jänicke (stjaenicke@informatik.uni-leipzig.de) | |
| 26 * @release 1.0 | |
| 27 * @release date: 2012-07-27 | |
| 28 * @version date: 2012-07-27 | |
| 29 */ | |
| 30 function PlacenamePopup(parent) { | |
| 31 | |
| 32 this.parentDiv = parent.gui.mapWindow; | |
| 33 | |
| 34 this.createPopup = function(x, y, labels) { | |
| 35 this.labels = labels; | |
| 36 var pnPopup = this; | |
| 37 var popup = new MapPopup(parent); | |
| 38 var onClose = function() { | |
| 39 parent.deselection(); | |
| 40 pnPopup.reset(); | |
| 41 } | |
| 42 popup.initialize(x, y, onClose); | |
| 43 $.extend(this, popup); | |
| 44 | |
| 45 this.content = document.createElement("div"); | |
| 46 this.inner = document.createElement("div"); | |
| 47 | |
| 48 this.resultsLabel = document.createElement("div"); | |
| 49 this.resultsLabel.setAttribute('class', 'popupDDBResults'); | |
| 50 this.content.appendChild(this.resultsLabel); | |
| 51 this.backward = document.createElement("div"); | |
| 52 this.backward.setAttribute('class', 'prevItem'); | |
| 53 this.content.appendChild(this.backward); | |
| 54 this.backward.onclick = function() { | |
| 55 pnPopup.descriptionIndex--; | |
| 56 pnPopup.showDescription(); | |
| 57 } | |
| 58 | |
| 59 this.number = document.createElement("div"); | |
| 60 this.content.appendChild(this.number); | |
| 61 this.number.style.display = 'none'; | |
| 62 this.number.style.fontSize = '13px'; | |
| 63 | |
| 64 this.forward = document.createElement("div"); | |
| 65 this.forward.setAttribute('class', 'nextItem'); | |
| 66 this.content.appendChild(this.forward); | |
| 67 this.forward.onclick = function() { | |
| 68 pnPopup.descriptionIndex++; | |
| 69 pnPopup.showDescription(); | |
| 70 } | |
| 71 if (parent.options.showDescriptions) { | |
| 72 this.descriptions = document.createElement("div"); | |
| 73 this.descriptions.setAttribute('class', 'descriptions'); | |
| 74 this.descriptions.onclick = function() { | |
| 75 pnPopup.switchToDescriptionMode(); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 this.back = document.createElement("div"); | |
| 80 this.back.setAttribute('class', 'back'); | |
| 81 this.popupDiv.appendChild(this.back); | |
| 82 this.back.onclick = function() { | |
| 83 pnPopup.back.style.display = "none"; | |
| 84 pnPopup.backward.style.display = "none"; | |
| 85 pnPopup.forward.style.display = "none"; | |
| 86 pnPopup.number.style.display = 'none'; | |
| 87 pnPopup.showLabels(); | |
| 88 } | |
| 89 | |
| 90 this.content.appendChild(this.inner); | |
| 91 this.listLabels(); | |
| 92 this.showLabels(); | |
| 93 | |
| 94 }; | |
| 95 | |
| 96 this.switchToDescriptionMode = function() { | |
| 97 this.descriptionIndex = 0; | |
| 98 this.descriptionContents = this.activeLabel.descriptions; | |
| 99 this.number.style.display = 'inline-block'; | |
| 100 this.inner.style.minWidth = "300px"; | |
| 101 this.showDescription(); | |
| 102 this.count = this.activeLabel.weight; | |
| 103 this.setCount(); | |
| 104 this.back.style.display = "inline-block"; | |
| 105 } | |
| 106 | |
| 107 this.showDescription = function() { | |
| 108 $(this.inner).empty(); | |
| 109 this.inner.appendChild(this.descriptionContents[this.descriptionIndex]); | |
| 110 this.setContent(this.content); | |
| 111 if (this.descriptionContents.length == 1) { | |
| 112 this.backward.style.display = "none"; | |
| 113 this.forward.style.display = "none"; | |
| 114 } else { | |
| 115 if (this.descriptionIndex == 0) { | |
| 116 this.backward.style.display = "none"; | |
| 117 } else { | |
| 118 this.backward.style.display = "inline-block"; | |
| 119 } | |
| 120 if (this.descriptionIndex == this.descriptionContents.length - 1) { | |
| 121 this.forward.style.display = "none"; | |
| 122 } else { | |
| 123 this.forward.style.display = "inline-block"; | |
| 124 } | |
| 125 } | |
| 126 if (this.descriptionContents.length > 1) { | |
| 127 this.number.innerHTML = "#" + (this.descriptionIndex + 1); | |
| 128 } else { | |
| 129 this.number.style.display = 'none'; | |
| 130 } | |
| 131 this.decorate(); | |
| 132 } | |
| 133 | |
| 134 this.setCount = function() { | |
| 135 var c = this.count; | |
| 136 if (c > 1) { | |
| 137 this.resultsLabel.innerHTML = c + " " + GeoTemConfig.getString('results'); | |
| 138 } else { | |
| 139 this.resultsLabel.innerHTML = c + " " + GeoTemConfig.getString('result'); | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 this.listLabels = function() { | |
| 144 var pnPopup = this; | |
| 145 this.labelDivs = []; | |
| 146 this.labelCount = 0; | |
| 147 this.labelsWidth = 0; | |
| 148 for (var i = 0; i < this.labels.length; i++) { | |
| 149 var div = document.createElement("div"); | |
| 150 var content = document.createElement("div"); | |
| 151 this.labels[i].allStyle += "position: relative; white-space: nowrap;"; | |
| 152 content.appendChild(this.labels[i].div); | |
| 153 content.setAttribute('class', 'ddbPopupLabel'); | |
| 154 div.appendChild(content); | |
| 155 this.labels[i].div.setAttribute('style', this.labels[i].allStyle + "" + this.labels[i].selectedStyle); | |
| 156 this.input.appendChild(div); | |
| 157 if (this.input.offsetWidth > this.labelsWidth) { | |
| 158 this.labelsWidth = this.input.offsetWidth; | |
| 159 } | |
| 160 this.labels[i].div.setAttribute('style', this.labels[i].allStyle + "" + this.labels[i].unselectedStyle); | |
| 161 this.labelDivs.push(div); | |
| 162 var descriptions = []; | |
| 163 for (var j = 0; j < this.labels[i].elements.length; j++) { | |
| 164 var div = document.createElement("div"); | |
| 165 div.innerHTML = this.labels[i].elements[j].description; | |
| 166 descriptions.push(div); | |
| 167 } | |
| 168 this.labels[i].descriptions = descriptions; | |
| 169 if (this.labels[i].place != "all" || i == 0) { | |
| 170 this.labelCount += this.labels[i].weight; | |
| 171 } | |
| 172 } | |
| 173 if ( typeof this.descriptions != 'undefined') { | |
| 174 this.labelsWidth += 20; | |
| 175 } | |
| 176 } | |
| 177 | |
| 178 this.showLabels = function() { | |
| 179 $(this.inner).empty(); | |
| 180 this.count = this.labelCount; | |
| 181 this.setCount(); | |
| 182 for (var i = 0; i < this.labelDivs.length; i++) { | |
| 183 this.inner.appendChild(this.labelDivs[i]); | |
| 184 } | |
| 185 this.inner.style.width = this.labelsWidth + "px"; | |
| 186 this.inner.style.minWidth = this.labelsWidth + "px"; | |
| 187 this.setContent(this.content); | |
| 188 this.decorate(); | |
| 189 } | |
| 190 | |
| 191 this.showLabelContent = function(label) { | |
| 192 for (var i = 0; i < this.labels.length; i++) { | |
| 193 if (this.labels[i] == label) { | |
| 194 this.activeLabel = this.labels[i]; | |
| 195 if ( typeof this.descriptions != 'undefined') { | |
| 196 this.labelDivs[i].appendChild(this.descriptions); | |
| 197 } | |
| 198 this.decorate(); | |
| 199 break; | |
| 200 } | |
| 201 } | |
| 202 } | |
| 203 | |
| 204 this.setLanguage = function(language) { | |
| 205 this.language = language; | |
| 206 if (this.visible) { | |
| 207 this.updateTexts(); | |
| 208 } | |
| 209 } | |
| 210 }; |
