1/* 2 * Copyright (c) 2012-2017 Mark C. Prins <mprins@users.sf.net> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17/** 18 * add layers to the map based on the olMapOverlays object. 19 */ 20function olovAddToMap() { 21 if (olEnable) { 22 for (var key in olMapOverlays) { 23 var overlay = olMapOverlays[key]; 24 var m = olMaps[overlay.id]; 25 26 switch (overlay.type) { 27 case 'osm': 28 m.addLayer(new OpenLayers.Layer.OSM(overlay.name, overlay.url, { 29 isBaseLayer: !1, 30 opacity: parseFloat(overlay.opacity), 31 attribution: overlay.attribution, 32 visibility: (overlay.visible).toLowerCase() == 'true', 33 tileOptions: { 34 crossOriginKeyword: null 35 } 36 })); 37 break; 38 // case 'wmts': 39 // var format = new OpenLayers.Format.WMTSCapabilities(); 40 // OpenLayers.Request.GET({ 41 // url: overlay.url, 42 // params: { 43 // SERVICE: "WMTS", 44 // VERSION: "1.0.0", 45 // REQUEST: "GetCapabilities" 46 // }, 47 // success: function(request) { 48 // var doc = request.responseXML; 49 // if (!doc || !doc.documentElement) { 50 // doc = request.responseText; 51 // } 52 // var capabilities = format.read(doc); 53 // var layer = format.createLayer(capabilities, { 54 // name: overlay.name, 55 // layer: overlay.layer, 56 // matrixSet: overlay.matrixSet, 57 // format: overlay.format, 58 // style: overlay.style, 59 // opacity: parseFloat(overlay.opacity), 60 // isBaseLayer: !1 61 // }); 62 // map.addLayer(layer); 63 // }, 64 // failure: function() { 65 // alert("Trouble getting capabilities doc"); 66 // OpenLayers.Console.error.apply(OpenLayers.Console, arguments); 67 // } 68 // }); 69 70 // m.addLayer(new OpenLayers.Layer.WMTS({ 71 // name: overlay.name, 72 // url: overlay.url, 73 // layer: overlay.layer, 74 // style: overlay.style, 75 // isBaseLayer: !1, 76 // matrixSet: overlay.matrixSet, 77 // //matrixIds: overlay.matrixIds, 78 // format: overlay.format, 79 // opacity : parseFloat(overlay.opacity), 80 // attribution : overlay.attribution, 81 // visibility : (overlay.visible).toLowerCase() == 'true', 82 // tileOptions : { 83 // crossOriginKeyword : null 84 // } 85 // })); 86 break; 87 case 'wms': 88 m.addLayer(new OpenLayers.Layer.WMS(overlay.name, overlay.url, { 89 layers: overlay.layers, 90 version: overlay.version, 91 transparent: overlay.transparent, 92 format: overlay.format 93 }, { 94 opacity: parseFloat(overlay.opacity), 95 visibility: (overlay.visible).toLowerCase() == 'true', 96 isBaseLayer: !1, 97 attribution: overlay.attribution 98 })); 99 break; 100 case 'ags': 101 m.addLayer(new OpenLayers.Layer.ArcGIS93Rest(overlay.name, overlay.url, { 102 layers: overlay.layers, 103 transparent: overlay.transparent, 104 format: overlay.format 105 }, { 106 opacity: parseFloat(overlay.opacity), 107 visibility: (overlay.visible).toLowerCase() == 'true', 108 isBaseLayer: !1, 109 attribution: overlay.attribution 110 })); 111 break; 112 case 'mapillary': 113 var mUrl = 'http://api.mapillary.com/v1/im/search?'; 114 if (overlay.skey !== '') { 115 mUrl = 'http://api.mapillary.com/v1/im/sequence?'; 116 } 117 var mLyr = new OpenLayers.Layer.Vector( 118 "Mapillary", { 119 projection: new OpenLayers.Projection("EPSG:4326"), 120 strategies: [new OpenLayers.Strategy.BBOX({ 121 ratio: 1.1, 122 resFactor: 1.5 123 }) /* ,new OpenLayers.Strategy.Cluster({}) */], 124 protocol: new OpenLayers.Protocol.HTTP({ 125 url: mUrl, 126 format: new OpenLayers.Format.GeoJSON(), 127 params: { 128 // default to max. 250 locations 129 'max-results': 250, 130 'geojson': true, 131 'skey': overlay.skey 132 }, 133 filterToParams: function (filter, params) { 134 if (filter.type === OpenLayers.Filter.Spatial.BBOX) { 135 // override the bbox serialization of 136 // the filter to give the Mapillary 137 // specific bounds 138 params['min-lat'] = filter.value.bottom; 139 params['max-lat'] = filter.value.top; 140 params['min-lon'] = filter.value.left; 141 params['max-lon'] = filter.value.right; 142 // if the width of our bbox width is 143 // less than 0.15 degrees drop the max 144 // results 145 if (filter.value.top - filter.value.bottom < .15) { 146 OpenLayers.Console.debug('dropping max-results parameter, width is: ', 147 filter.value.top - filter.value.bottom); 148 params['max-results'] = null; 149 } 150 } 151 return params; 152 } 153 }), 154 styleMap: new OpenLayers.StyleMap({ 155 'default': { 156 cursor: 'help', 157 rotation: '${ca}', 158 externalGraphic: DOKU_BASE + 'lib/plugins/openlayersmapoverlays/icons/arrow-up-20.png', 159 graphicHeight: 20, 160 graphicWidth: 20, 161 }, 162 'select': { 163 externalGraphic: DOKU_BASE + 'lib/plugins/openlayersmapoverlays/icons/arrow-up-20-select.png', 164 label: '${location}', 165 fontSize: '1em', 166 fontFamily: 'monospace', 167 labelXOffset: '0.5', 168 labelYOffset: '0.5', 169 labelAlign: 'lb', 170 } 171 }), 172 attribution: '<a href="http://www.mapillary.com/legal.html">' + 173 '<img src="http://mapillary.com/favicon.ico" ' + 174 'alt="Mapillary" height="16" width="16" />Mapillary (CC-BY-SA)', 175 visibility: (overlay.visible).toLowerCase() == 'true', 176 }); 177 m.addLayer(mLyr); 178 selectControl.addLayer(mLyr); 179 break; 180 case 'search': 181 m.addLayer(new OpenLayers.Layer.Vector( 182 overlay.name, 183 overlay.url, 184 { 185 layers: overlay.layers, 186 version: overlay.version, 187 transparent: overlay.transparent, 188 format: overlay.format 189 }, { 190 opacity: parseFloat(overlay.opacity), 191 visibility: (overlay.visible).toLowerCase() == 'true', 192 isBaseLayer: !1, 193 attribution: overlay.attribution 194 } 195 )); 196 break; 197 } 198 } 199 } 200} 201 202var olMapOverlays = {}; 203 204jQuery(olovAddToMap); 205