https://ptpubliclibrary.org/sites/default/files/js/js_invwULM9b7VQ2nudHQuMr7HTLePsGwdzWvs2II_7vtU.js
1/** 2 * @file 3 * JS Implementation of OpenLayers behavior. 4 */ 5 6/** 7 * OpenLayers Zoom to Layer Behavior 8 */ 9Drupal.openlayers.addBehavior('openlayers_behavior_zoomtolayer', function (data, options) { 10 var map = data.openlayers; 11 var zoomtolayer_scale = parseInt(options.zoomtolayer_scale, 10); 12 var point_zoom_level = parseInt(options.point_zoom_level, 10); 13 14 var layers = map.getLayersBy('drupalID', { 15 test: function(id) { 16 for (var i in options.zoomtolayer) { 17 if (options.zoomtolayer[i] == id) { 18 return true; 19 } 20 } 21 return false; 22 } 23 }); 24 25 // Combined extent of all layers. 26 var fullExtent = undefined; 27 // Number of layers that are still loading. 28 var pending_load_ends = 0; 29 30 // Go through selected layers to get full extent. 31 jQuery(layers).each(function(index, layer) { 32 accumulate_extent(layer); 33 34 if (layer instanceof OpenLayers.Layer.Vector) { 35 // This should not register the handler in case no data is available. 36 if (layer.getDataExtent() === null) { 37 // Try again to determine the extent after layer has loaded. 38 pending_load_ends = pending_load_ends + 1; 39 layer.events.register('loadend', layer, handle_loadend_once); 40 } 41 42 } 43 }); 44 // Zoom if all data was sychronously load. 45 show_extent_if_determined(); 46 47 /** 48 * Handler for loadend event of layer that is still loading. 49 */ 50 function handle_loadend_once(event) { 51 var layer = event.object; 52 layer.events.unregister('loadend', layer, handle_loadend_once); 53 pending_load_ends = pending_load_ends - 1; 54 55 accumulate_extent(layer); 56 // Zoom if no other layer is still loading. 57 show_extent_if_determined(); 58 } 59 60 /** 61 * Add data extent of layer to total data extent. 62 */ 63 function accumulate_extent(layer){ 64 var layerextent = layer.getDataExtent(); 65 if(fullExtent instanceof OpenLayers.Bounds){ 66 fullExtent.extend(layerextent); 67 } else { 68 fullExtent = layerextent; 69 } 70 } 71 72 /** 73 * Zooms map if all layers have finished loading. 74 */ 75 function show_extent_if_determined(){ 76 if(pending_load_ends===0 && fullExtent instanceof OpenLayers.Bounds){ 77 if (fullExtent.getWidth()===0 && fullExtent.getHeight()===0) { 78 // If extent is a single point, 79 // zoom in with point_zoom_level option. 80 map.setCenter(fullExtent.getCenterLonLat(), point_zoom_level) 81 } else { 82 var scaled = fullExtent.scale(zoomtolayer_scale); 83 map.zoomToExtent(scaled); 84 if(!map.getExtent().contains(scaled)){ 85 // OpenLayers silently ignores zoom in case the date line would need 86 // to be displayed more than once. Move map to where the data is at 87 // least. 88 map.setCenter(scaled.getCenterLonLat()); 89 } 90 } 91 } 92 } 93}); 94; 95/** 96 * @file 97 * JS Implementation of OpenLayers behavior. 98 */ 99 100/** 101 * Attribution Behavior. Implements the Attribution OpenLayers 102 * Control. 103 */ 104Drupal.openlayers.addBehavior('openlayers_behavior_attribution', function (data, options) { 105 Drupal.openlayers.addControl(data.openlayers, 'Attribution', options); 106}); 107; 108 109/** 110 * @file 111 * JS Implementation of OpenLayers behavior. 112 */ 113 114/** 115 * Keyboard Defaults Behavior. Implements the KeyboardDefaults OpenLayers 116 * Control. 117 */ 118Drupal.openlayers.addBehavior('openlayers_behavior_keyboarddefaults', function (data, options) { 119 Drupal.openlayers.addControl(data.openlayers, 'KeyboardDefaults'); 120}); 121; 122/** 123 * @file 124 * JS Implementation of OpenLayers behavior. 125 */ 126 127/** 128 * Layer Switcher Behavior 129 */ 130Drupal.openlayers.addBehavior('openlayers_behavior_layerswitcher', function (data, options) { 131 options.ascending = !! options.ascending; 132 Drupal.openlayers.addControl(data.openlayers, 'LayerSwitcher', options); 133 134 // Maximize if needed. 135 if (!! options.maximizeDefault == true) { 136 data.openlayers.getControlsByClass('OpenLayers.Control.LayerSwitcher')[0].maximizeControl(); 137 } 138}); 139; 140/** 141 * @file 142 * JS Implementation of OpenLayers behavior. 143 */ 144 145/** 146 * Pan Zoom Bar Behavior 147 */ 148Drupal.openlayers.addBehavior('openlayers_behavior_panzoom', function (data, options) { 149 Drupal.openlayers.addControl(data.openlayers, 'PanZoom'); 150}); 151; 152/** 153 * @file 154 * JS Implementation of OpenLayers behavior. 155 */ 156 157/** 158 * Navigation Behavior 159 */ 160Drupal.openlayers.addBehavior('openlayers_behavior_navigation', function (data, options) { 161 options.documentDrag = !!options.documentDrag; 162 Drupal.openlayers.addControl(data.openlayers, 'Navigation', options); 163}); 164; 165/** 166 * @file 167 * JS Implementation of OpenLayers behavior. 168 */ 169/** 170 * Class: OpenLayers.Control.GeofieldEditingToolbar
171 * The GeofieldEditingToolbar is a panel controls to modify or draw polygons, lines, 172 * points, or to navigate the map by panning. You can select which tool to enable 173 * with options.tools. 174 * 175 * Inherits from: 176 * - <OpenLayers.Control.Panel> 177 */ 178OpenLayers.Control.GeofieldEditingToolbar = OpenLayers.Class( 179 OpenLayers.Control.Panel, { 180 181 /** 182 * Constructor: OpenLayers.Control.GeofieldEditingToolbar 183 * Create an editing toolbar for a given layer. 184 * 185 * Parameters: 186 * layer - {<OpenLayers.Layer.Vector>} 187 * options - {Object} 188 */ 189 initialize: function(layer, options) { 190 OpenLayers.Control.Panel.prototype.initialize.apply(this, [options]); 191 192 var controls = []; 193 var tool = null; 194 195 if (options.allow_edit && options.allow_edit !== 0) { 196 // add an Edit feature 197 controls.push(new OpenLayers.Control.ModifyFeature(layer, { 198 deleteCodes: [46, 68, 100], 199 handleKeypress: function(evt) { 200 if (this.feature && OpenLayers.Util.indexOf(this.deleteCodes, evt.keyCode) > -1) { 201 // We must unselect the feature before we delete it 202 var feature_to_delete = this.feature; 203 this.selectControl.unselectAll(); 204 this.layer.removeFeatures([feature_to_delete]); 205 } 206 } 207 })); 208 } else { 209 controls = [new OpenLayers.Control.Navigation()]; 210 } 211 212 if (options.feature_types && options.feature_types.length) { 213 for (var i = 0, il = options.feature_types.length; i < il; i += 1) { 214 // capitalize first letter 215 tool = options.feature_types[i][0].toUpperCase() + options.feature_types[i].slice(1); 216 controls.push( 217 new OpenLayers.Control.DrawFeature(layer, OpenLayers.Handler[tool], {'displayClass': 'olControlDrawFeature' + tool}) 218 ); 219 } 220 } 221 222 this.addControls(controls); 223 }, 224 225 /** 226 * Method: draw 227 * calls the default draw, and then activates mouse defaults. 228 * 229 * Returns: 230 * {DOMElement} 231 */ 232 draw: function() { 233 OpenLayers.Control.Panel.prototype.draw.apply(this, arguments); 234 this.div.className += " olControlEditingToolbar"; 235 if (this.defaultControl === null) { 236 this.defaultControl = this.controls[0]; 237 } 238 return this.div; 239 }, 240 241 CLASS_NAME: "OpenLayers.Control.GeofieldEditingToolbar" 242}); 243 244 245(function($) { 246 /** 247 * Geofield Behavior 248 */ 249 Drupal.behaviors.openlayers_behavior_geofield = { 250 'attach': function(context, settings) { 251 252 // Only attach the behavior to a map 253 if (!$(context).hasClass('openlayers-map')) return; 254 255 var data = $(context).data('openlayers'), 256 dataProjection = new OpenLayers.Projection('EPSG:4326'), 257 features, wktFormat; 258 259 // helper to create a WKT format object with the right projections 260 function initWktFormat (inp, outp) { 261 var WktWriter = new OpenLayers.Format.WKT(); 262 WktWriter.internalProjection = inp; 263 WktWriter.externalProjection = outp || dataProjection; 264 return WktWriter; 265 } 266 267 // populate our wkt input field 268 function updateWKTField (features) { 269 var WktWriter = initWktFormat(features.object.map.projection); 270 // limits are to checked both server-side and here. 271 // for a single shape avoid GEOMETRYCOLLECTION 272 var toSerialize = features.object.features; 273 // don't serialize empty feature 274 if (toSerialize.length) { 275 if (toSerialize.length === 1) { toSerialize = toSerialize[0]; } 276 this.val(WktWriter.write(toSerialize)); 277 } 278 // but clear the value 279 else { 280 this.val(''); 281 } 282 } 283 284 // keep only one features for each map input 285 function limitFeatures (features) { 286 var cardinality = Drupal.settings.geofield.widget_settings.cardinality; 287 if (cardinality >= 1) { 288 // Calculate how many features we need to delete off the beginning of the feature array 289 var deleteNum = features.object.features.length - cardinality; 290 if (deleteNum > 0) { 291 var featuresToDelete = features.object.features.slice(0,deleteNum); 292 // we remove a lot of features, don't trigger events 293 features.object.destroyFeatures(featuresToDelete, {silient: true}); 294 } 295 } 296 } 297 298 if (!$(context).hasClass('geofield-processed')) { 299 // we get the .form-item wrapper which is a slibling of our hidden input 300 var $wkt = $(context).closest('.form-item').parent().find('input.geofield_wkt'); 301 // if there is no form input this shouldn't be activated 302 if ($wkt.length) { 303 var dataLayer = new OpenLayers.Layer.Vector(Drupal.t('Feature Layer'), { 304 projection: dataProjection, 305 drupalID: 'openlayers_behavior_geofield' 306 }); 307 308 dataLayer.styleMap = Drupal.openlayers.getStyleMap(data.map, 'openlayers_behavior_geofield'); 309 data.openlayers.addLayer(dataLayer); 310 311 // only one feature on each map register before adding our data 312 if (Drupal.settings.geofield.widget_settings.data_storage == 'single') { 313 dataLayer.events.register('featureadded', $wkt, limitFeatures); 314 } 315 316 if ($wkt.val() != '') { 317 wktFormat = initWktFormat(data.openlayers.projection); 318 features = wktFormat.read($wkt.val()); 319 dataLayer.addFeatures(features); 320 } 321 322 // registering events late, because adding data 323 // would result in a reprojection loop 324 dataLayer.events.register('featureadded', $wkt, updateWKTField); 325 dataLayer.events.register('featureremoved', $wkt, updateWKTField); 326 dataLayer.events.register('afterfeaturemodified', $wkt, updateWKTField); 327 328 // create toolbar 329 var geofieldControl = new OpenLayers.Control.GeofieldEditingToolbar(dataLayer, Drupal.settings.geofield.widget_settings); 330 data.openlayers.addControl(geofieldControl); 331 332 // Process features-modified on form submission: write features to WKT field / recalculate everything to be up to date. 333 var formData = { 334 'control': geofieldControl, 335 'dataLayer': dataLayer 336 }; 337 $(context).parents('form').bind('submit', formData, function(e) { 338 $.map(e.data.control.controls, function(c) { c.deactivate(); }); 339 dataLayer.events.triggerEvent('afterfeaturemodified'); 340 }); 341 } 342 $(context).addClass('geofield-processed'); 343 } 344 } 345 }; 346})(jQuery); 347; 348 349/** 350 * OpenLayers Raw Layer Handler 351 */ 352Drupal.openlayers.layer.openlayers_raw = function(title, map, options) { 353 options.options = options.options || {}; 354 355 // Note, so that we do not pass all the features along to the Layer 356 // options, we use the options.options to give to Layer 357 options.options.drupalID = options.drupalID; 358 options.options.styleMap = Drupal.openlayers.getStyleMap(map, options.drupalID); 359 360 var layer = new OpenLayers.Layer.Vector(title, options.options); 361 362 if (options.features) { 363 Drupal.openlayers.addFeatures(map, layer, options.features); 364 } 365 366 return layer; 367}; 368; 369 370/** 371 * @file 372 * Layer handler for XYZ layers 373 */ 374
375/** 376 * Openlayer layer handler for XYZ layer 377 */ 378Drupal.openlayers.layer.xyz = function(title, map, options) { 379 if (OpenLayers.Util.isArray(options.maxExtent)) { 380 options.maxExtent = OpenLayers.Bounds.fromArray(options.maxExtent); 381 } 382 383 // Legacy goodnes 384 if (typeof options.base_url == 'string' && typeof options.url == 'undefined') { 385 options.url = options.base_url; 386 } 387 388 // Server resolutions are very particular in OL 2.11 389 var r = options.serverResolutions; 390 if (r == null || typeof r == 'undefined' || r.length == 0) { 391 options.serverResolutions = null; 392 } 393 394 // Wrap Date Line does not seem to work for 2.10. This may 395 // have something to do with our extent definitions. 396 if (OpenLayers.VERSION_NUMBER.indexOf('2.10') >= 0) { 397 options.wrapDateLine = null; 398 } 399 400 options.projection = new OpenLayers.Projection(options.projection); 401 402 return new OpenLayers.Layer.XYZ(title, options.url, options); 403}; 404; 405/** 406 * @file 407 * JS Implementation of OpenLayers behavior. 408 */ 409 410/** 411 * Javascript Drupal Theming function for inside of Popups 412 * 413 * To override 414 * 415 * @param feature 416 * OpenLayers feature object. 417 * @return 418 * Formatted HTML. 419 */ 420Drupal.theme.prototype.openlayersPopup = function(feature) { 421 var output = ''; 422 423 if (feature.attributes.name) { 424 output += '<div class="openlayers-popup openlayers-tooltip-name">' + feature.attributes.name + '</div>'; 425 } 426 if (feature.attributes.description) { 427 output += '<div class="openlayers-popup openlayers-tooltip-description">' + feature.attributes.description + '</div>'; 428 } 429 430 return output; 431}; 432 433// Make sure the namespace exists 434Drupal.openlayers.popup = Drupal.openlayers.popup || {}; 435 436/** 437 * OpenLayers Popup Behavior 438 */ 439Drupal.openlayers.addBehavior('openlayers_behavior_popup', function (data, options) { 440 var map = data.openlayers; 441 var layers = []; 442 var selectedFeature; 443 444 // For backwards compatiability, if layers is not 445 // defined, then include all vector layers 446 if (typeof options.layers == 'undefined' || options.layers.length == 0) { 447 layers = map.getLayersByClass('OpenLayers.Layer.Vector'); 448 } 449 else { 450 for (var i in options.layers) { 451 var selectedLayer = map.getLayersBy('drupalID', options.layers[i]); 452 if (typeof selectedLayer[0] != 'undefined') { 453 layers.push(selectedLayer[0]); 454 } 455 } 456 } 457 458 // if only 1 layer exists, do not add as an array. Kind of a 459 // hack, see https://drupal.org/node/1393460 460 if (layers.length == 1) { 461 layers = layers[0]; 462 } 463 464 var popupSelect = new OpenLayers.Control.SelectFeature(layers, 465 { 466 onSelect: function(feature) { 467 // Create FramedCloud popup. 468 popup = new OpenLayers.Popup.FramedCloud( 469 'popup', 470 feature.geometry.getBounds().getCenterLonLat(), 471 null, 472 Drupal.theme('openlayersPopup', feature), 473 null, 474 true, 475 function(evt) { 476 while( map.popups.length ) { 477 map.removePopup(map.popups[0]); 478 } 479 Drupal.openlayers.popup.popupSelect.unselect(selectedFeature); 480 } 481 ); 482 483 // Assign popup to feature and map. 484 popup.panMapIfOutOfView = options.panMapIfOutOfView; 485 popup.keepInMap = options.keepInMap; 486 selectedFeature = feature; 487 feature.popup = popup; 488 Drupal.attachBehaviors(); 489 map.addPopup(popup); 490 }, 491 onUnselect: function(feature) { 492 map.removePopup(feature.popup); 493 feature.popup.destroy(); 494 feature.popup = null; 495 this.unselectAll(); 496 } 497 } 498 ); 499 500 map.addControl(popupSelect); 501 popupSelect.activate(); 502 Drupal.openlayers.popup.popupSelect = popupSelect; 503}); 504;
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.