1 2 3 function koch_init_map(koch_map, qparams, autobound) { 4 if (typeof window.$ === 'undefined' && window.jQuery) 5 window.$ = window.jQuery; 6 7 8 9 10/* koch_map top level methods */ 11 koch_map.public = function () { 12 koch_map.getPostID = function (places) { 13 var pl = []; 14 if (typeof placees.postID !== 'undefined') 15 return places.postID 16 else 17 places.forEach( function(el) { 18 pl.push(el.postID) 19 }); 20 return pl; 21 } 22 23 koch_map.getPlaceByPostID = function(postID) { 24 if (typeof this.data === 'undefined' || typeof this.data.places === 'undefined') 25 return false; 26 var ret = []; 27 this.data.places.forEach( function (el) { 28 if (el.postID == postID) 29 ret.push(el) 30 }); 31 return ret; 32 } 33 34 koch_map.getPlacesInMarkers = function () { 35 var ret = []; 36 if (this.latlngbounds) { 37 38 var bounds = this.latlngbounds; 39 this.data.places.forEach( function(el) { 40 if (bounds.contains(el.position)) 41 ret.push(el); 42 43 }) 44 } 45 return ret; 46 } 47 48 koch_map.GetMarkerByID = function (id) { 49 var marker = null; 50 $.each(koch_map.markers, function(i, m){ 51 if (m.kg_post && m.kg_post.id == id) { 52 marker = m.kg_post.marker; 53 return false; 54 } 55 56 }); 57 return marker; 58 } 59 60 koch_map.maxZoom = function (zoom = false) { 61 if (!zoom) 62 zoom = 17; 63 if (koch_map.map.getZoom() > zoom) 64 koch_map.map.setZoom(zoom); 65 } 66 67 koch_map.setTaxonomies = function (posts, tax, select = false) { 68 this._set_ajax_load(this.id); 69 var m = this; 70 71 $.post(koch_ajax.ajaxurl, 72 { 73 action: 'koch_set_post_term', 74 posts: posts, 75 tax: tax 76 }, 77 function (data) { 78 var ret = JSON.parse(data); 79 m._clear_ajax_load(); 80 console.log(ret); 81 82 $.each(ret, function(id, taxr) { 83 el = m.getPlaceByPostID(id); 84 el.forEach(function(e) { 85 86 e.setTaxonomy(taxr,select); 87 }) 88 }); 89 90 }); 91 92 93 } 94 95 koch_map.zoomSelected = function (iftrue = true) { 96 var bounds = iftrue && !koch_map.getBoundsSelected().isEmpty() ? koch_map.boundsselected : koch_map.bounds; 97 koch_map.map.fitBounds(bounds,1); 98 koch_map.maxZoom(); 99 return bounds; 100 } 101 koch_map.showAll = function(selected = false) { 102 var m = []; 103 $.each(this.data.places, function (key, el){ 104 el.show(selected ? el.selected : true); 105 }); 106 koch_map._resetClusterHook(); 107 108 } 109 110 koch_map.hideAll = function() { 111 $.each(this.data.places, function (key, el){ 112 el.hide(); 113 }); 114 koch_map._resetClusterHook(); 115 } 116 117 koch_map.selectAll = function(select = true) { 118 $.each(this.data.places, function (key, el){ 119 if (typeof el.select !== 'undefined') 120 el.select(select); 121 }); 122 koch_map._resetClusterHook(); 123 } 124 125 koch_map.zoomRegion = function (region) { 126 var koch_map = this; 127 // console.log('zoom region', region); 128 if (!koch_map._isLoaded) 129 google.maps.event.addListenerOnce(koch_map, 'koch_map_loaded', function(map) { 130 // console.log('zoom region waits for next bound change', region); 131 google.maps.event.addListenerOnce(koch_map.map, 'bounds_changed', function(map) { 132 // console.log('trying zoom region', koch_map.map.getBounds()); 133 koch_map._zoomRegion(region); 134 }); 135 }); 136 else 137 koch_map._zoomRegion(region); 138 139 } 140 141 142 143 koch_map.showRegionBounds = function(region, propagate = false) { 144 145 if (typeof region === 'object' && (this.params.showbounds || this.params.loglatlng)) { 146 if (this.params.loglatlng) 147 this._set_boundery_marker(region); 148 this._region_rect(region); 149 this.latlngbounds = this.latlngrec.getBounds(); 150 } 151 else if (this.params.loglatlng) 152 this._init_lat_lng_markers(); 153 if (propagate) 154 this._propagate_bounds(region); 155 return region; 156 } 157 /* init a menu with standard operations */ 158 koch_map.initMenu = function() { 159 var km = this; 160 $('#click_tax_reset_' + km.id).click(function(e) { 161 // console.log(e); 162 km.showRegionBounds(km.region.bounds === true ? km.getBoundsSelected() : km.region.bounds, true); 163 }); 164 $('#click_tax_show_all_' + km.id).click(function(e) { 165 // console.log(e); 166 km.showAll(this.checked); 167 }); 168 $('#click_tax_zoom_region_' + km.id).click(function(e) { 169 // console.log(e); 170 if (km._region_rect) 171 km.map.fitBounds(km.latlngrec.getBounds()); 172 }); 173 $('#click_tax_show_cluster_' + km.id).click(function(e) { 174 // console.log(e); 175 koch_map.setClusterer(this.checked); 176 }); 177 178 } 179 180 koch_map.selectPlaces = function (tax, term, hide = false) { 181 var koch_map = this; 182 var icons = koch_map.data.result.icons; 183 var places = koch_map.data.places; 184 var bound = new google.maps.LatLngBounds(); 185 var icon;
186 places.forEach(function(el){ 187 if (el.select(el.hasTaxonomy(tax,term), hide)) 188 bound.extend(el.position); 189 190 }); 191 koch_map.map.fitBounds(bound,1); 192 koch_map.showRegionBounds(bound); 193 koch_map.maxZoom(); 194 return (bound); 195 } 196 197 koch_map.hasSelected = function (markers) { 198 var selected = 0; 199 markers.forEach(function(m) { 200 if (m.kg_post.selected) { 201 selected++; 202 } 203 }); 204 return selected; 205 } 206 207 koch_map.getClusterName = function(markers) { 208 var levels = new Object(); 209 var selected = koch_map.hasSelected(markers); 210 var labels = [], tmpl = []; 211 var markercnt = markers.length; 212 213 markers.forEach(function(m){ 214 if (m.kg_post.selected == ( selected > 0 ? true : false)) 215 $.each(m.kg_post.placeInfo.addressLevels, function(k, v) { 216 if (typeof levels[k] === 'undefined') 217 levels[k] = new Object(); 218 if (typeof levels[k][v.short_name] === 'undefined') { 219 levels[k][v.short_name] = {label: v.long_name, short: v.short_name, cnt: 0, level: k, places: new Array()}; 220 tmpl.push(levels[k][v.short_name]); 221 } 222 levels[k][v.short_name].cnt++; 223 levels[k][v.short_name].places.push(m.kg_post); 224 225 }); 226 }); 227 tmpl.forEach(function(el) { 228 if (el.cnt == (selected ? selected : markercnt)) 229 labels.push(el); 230 }) 231 var toplevel; 232 var nextbest = 'country'; 233 234 235 if (labels.length) { 236 nextbest = labels[0].level; 237 toplevel = labels[0]; 238 } 239 var best; 240 $.each(levels, function(k,v){ 241 if (k == nextbest) 242 return false; 243 if (selected == 1 || $.map(v, function(n, i) { return i; }).length == 2) 244 best = k; 245 246 247 }); 248 if (!best) 249 best = nextbest; 250 var nextlevel = null; 251 var use = false;
252 $.each(levels, function(k,v){ 253 if (!use) 254 use = (k == best); 255 else { 256 $.each(v, function(k,vl){ nextlevel = vl; return false}); 257 return false; 258 } 259 260 }); 261 var delim = ''; 262 var ltext = ''; 263 var loctype = ''; 264 $.each(levels[best], function(k,v){ 265 ltext += delim + v.label; 266 delim = "/"; 267 loctype = v.level; 268 269 }); 270 271 return({label: ltext, best: {label: ltext, type: loctype, levels: $.map(levels[best], function(n, i) { return i; })}, nextbest: toplevel, nextlevel: nextlevel, labels: labels, levels: levels}); 272 } 273 274 koch_map.setClusterer = function (set = true){ 275 var koch_map = this; 276 koch_map._useclusterer = set; 277 koch_map._cluster_styles = { 278 selected: [{ 279 url: '/wp-content/themes/kochgenossen/img/kg_icon_cluster_black.svg', 280 height: 30, 281 width: 30, 282 anchor: [8, 0], 283 textColor: 'white', 284 textWeight: 'bold', 285 textSize: 13 286 }], 287 unselected: 288 [{ 289 url: '/wp-content/themes/kochgenossen/img/kg_icon_cluster_grey.svg', 290 height: 30, 291 width: 30, 292 anchor: [8, 0], 293 textColor: 'white', 294 textWeight: 'bold', 295 textSize: 13 296 }], 297 298 } 299 if (koch_map.clusterer && typeof koch_map.clusterer === 'object' && typeof koch_map.clusterer.clearMarkers !== 'undefined') 300 koch_map.clusterer.clearMarkers(); 301 if (set) { 302 if (!(koch_map.clusterer && typeof koch_map.clusterer === 'object' && typeof koch_map.clusterer.clearMarkers !== 'undefined')){ 303 // console.log("create clusterer"); 304 koch_map.clusterer = new MarkerClusterer(koch_map.map, null, 305 { 306 imagePath: '/wp-content/themes/kochgenossen/img/kg_map_icon_multi', 307 styles: koch_map._cluster_styles.selected, 308 gridSize: 20, 309 maxZoom: 14, 310 minimumClusterSize: 2, 311 onMouseoverCluster: function(e) { 312 313 // console.log("clustername", e, e.cluster_.markers_.length, koch_map.getClusterName(e.cluster_.markers_)); 314 koch_map._showClustererLabel(e,koch_map.getClusterName(e.cluster_.markers_).label); 315 return(true); 316 }, 317 318 onMouseoutCluster:function(e) { 319 koch_map._showClustererLabel(e,false, false); 320 321 return(true); 322 }, 323 // drawCluster: function(e) { 324 // console.log('drawcluster', e, koch_map.clusterer ); 325 // return(true); 326 // }, 327 // hideCluster: function(e) { 328 // console.log('hidecluster', e, koch_map.clusterer ); 329 // return(true); 330 // }, 331 // showCluster: function(e) { 332 // console.log('shwocluster', e, koch_map.clusterer ); 333 // return(true); 334 // }, 335 // onAddCluster: function(e) { 336 // console.log('addcluster', e, koch_map.clusterer ); 337 // return(true); 338 // }, 339 // onRemoveCluster: function(e) { 340 // console.log('removecluster', e, koch_map.clusterer ); 341 // return(true); 342 // }, 343 }); 344 koch_map._cluster_icon_label = document.createElement('DIV'); 345 koch_map.clusterer.addListener('clusterclick', function(e) { 346 koch_map._showClustererLabel(e.clusterIcon_, false, false); 347 }); 348 koch_map.clusterer.addListener('clusterscreated', function(e) { 349 if (koch_map._cluster_zoom == koch_map.clusterer.prevZoom_) 350 return; 351 352 koch_map.clusterer.getClusters().forEach(function(el) { 353 var selected = false; 354 var cnt = 0; 355 if (el.clusterIcon_.visible_) { 356 el.getMarkers().forEach(function (post) { 357 selected = selected ? selected : post.kg_post.selected ; 358 cnt += post.kg_post.selected ? 1 : 0; 359 }); 360 el.setIcon(selected ? koch_map._cluster_styles.selected : koch_map._cluster_styles.unselected); 361 el.updateIcon(cnt); 362 } 363 }); 364 });
365 koch_map.clusterer.addListener('clusterscreated_no', function(e) { 366 if (koch_map._cluster_zoom == koch_map.clusterer.prevZoom_) 367 return; 368 369 var changes = 0; 370 if (!koch_map._cluster_hide) { 371 var m = []; 372 // console.log("restore unselected to clustering", e); 373 374 koch_map.markers.forEach(function(el) { 375 376 if (el.clustremoved) { 377 378 el.clustremoved = false; 379 m.push(el); 380 381 } 382 }); 383 changes = m.length; 384 // console.log(changes); 385 if (changes) { 386 koch_map.clusterer.addMarkers(m); 387 388 } 389 } 390 391 koch_map._cluster_hide = false; 392 393 if(!changes) { 394 // console.log("hide unselected from clustering", e); 395 var m = []; 396 koch_map.markers.forEach(function(el) { 397 398 if(!el.kg_post.selected) { 399 clus = koch_map.clusterer.getMarkersCluster(el); 400 if (clus && clus.clusterIcon_.visible_) { 401 el.clustremoved = true; 402 m.push(el); 403 changes++; 404 } 405 } 406 }); 407 changes = m.length; 408 // console.log (changes, e); 409 if (changes) { 410 koch_map._cluster_hide = true; 411 koch_map.clusterer.removeMarkers(m); 412 413 } 414 koch_map._cluster_zoom = koch_map.clusterer.prevZoom_; 415 416 417 } 418 419 }); 420 } 421 422 // replace with markers from clusterer 423 var m = [] 424 koch_map.markers.forEach( function(el) { 425 el.setMap(null); 426 if (el.kg_post.visible() && el.kg_post.position) 427 m.push(el); 428 429 }); 430 431 koch_map.clusterer.addMarkers(m); 432 433 koch_map._cluster_zoom = -1; 434 435 // koch_map.markers = koch_map.clusterer.getMarkers(); 436 } else 437 koch_map.markers.forEach( function(el) { 438 if (el.kg_post.visible() && el.kg_post.position) 439 el.setMap(koch_map.map); 440 441 }); 442 } 443 444 koch_map.getBoundsSelected = function() { 445 if (!this.boundsselected_dirty) 446 return this.boundsselected; 447 this.boundsselected = new google.maps.LatLngBounds(); 448 var that = this; 449 var cnt = 0; 450 this.data.places.forEach(function(el) { 451 if (el.selected) { 452 that.boundsselected.extend(el.position); 453 cnt++; 454 } 455 }); 456 this.boundsselected_dirty = false; 457 return this.boundsselected; 458 459 } 460 461 /* add one marker */ 462 koch_map.addMarker = function(el) { 463 var map = koch_map.map 464 465 466 467 468 469 /* 470 hide, show, visible - methods for places (considering clusterer setting) 471 */ 472 el.hide = function () { 473 474 if (this.kg_map.clusterer) 475 this.kg_map.clusterer.removeMarker(this.marker); 476 else 477 this.marker.setMap(null); 478 this.visible(false); 479 return true; 480 } 481 el.show = function (show = true) { 482 if (!show) 483 return this.hide(); 484 if (this.visible()) 485 return true; 486 487 if (this.kg_map.clusterer) 488 this.kg_map.clusterer.addMarker(this.marker); 489 else 490 this.marker.setMap(this.kg_map.map); 491 this.visible(true); 492 return true; 493 } 494 495 el.visible = function (set = null) { 496 if (set === true || set === false) 497 this._visible = set; 498 if (typeof this._visible === 'undefined') 499 // initalize depending on value of marker 500 this._visible = (this.position && this.marker); 501 502 return this._visible; 503 } 504 505 el.select = function (selected = true, hide = false) { 506 this.kg_map.boundsselected_dirty = this.selected != selected; 507 508 this.selected = (selected ? true : false); 509 this.marker.setIcon(this.kg_map._getMarkerIcon(this.icon, this.selected)); 510 // this.marker.setIcon(this.selected ? this.kg_map.data.result.icons[this.icon].enabled : this.kg_map.data.result.icons[this.icon].disabled); 511 if (hide && !this.selected) 512 this.hide(); 513 if (!hide || this.selected) 514 this.show(); 515 516 return this.selected; 517 } 518 519 el.setTaxonomy = function (tax, select = false, replace = false) { 520 var el = this; 521 if (replace) 522 this.taxonomies = tax; 523 else 524 $.each(tax, function(t, terms) { 525 el.taxonomies[t] = terms; 526 }); 527 if(select && select.taxonomy !== 'undefined' && select.term !== 'undefined') { 528 this.select(this.hasTaxonomy(select.taxonomy,select.term )); 529 } 530 } 531 532 el.hasTaxonomy = function (tax, term) { 533 return (typeof this.taxonomies[tax] !== 'undefined' && this.taxonomies[tax][term] ? true : false); 534 } 535 el['kg_map'] = koch_map; 536 el['map'] = map; 537 538 el['marker'] = new google.maps.Marker({ 539 // position: el['position'] ? el['position'] : {lat: 0, lng: 0}, 540 // label: {text: el['label'] , fontSize: "12px", color: "black"}, 541 zIndex: 100, 542 icon: koch_map._getMarkerIcon(el['icon'], el.selected), 543 map: null}); 544 el['marker']['kg_post'] = el; 545 el['marker']['kg_map'] = koch_map; 546 if (el.position) { 547 el.marker.setPosition(el.position); 548 koch_map.bounds.extend(el.position); 549 if (el.selected) 550 koch_map.boundsselected.extend(el.position); 551 } 552 else 553 el.hide(); 554 555 el['marker']._set_infocontent = function () { 556 var m = this; 557 var content = ""; 558 var wrap_open = '<div id="kg_placeinfo_'+m.kg_map.id+'" class="kg-mapinfo">'; 559 var wrap_close = "</div>"; 560 if (m.kg_map.params.postedit) { 561 var wrap_open = '<div id="kg_placeinfo_'+m.kg_map.id+'" class="kg-mapinfo-postedit kg-mapinfo">'; 562 var wrap_close = "</div>"; 563 if (m.editinfo) { 564 content += '<h2 class= "kg-mapinfo-label kg-mapinfo-postedit-label'+(koch_map.editpostmarker === m ? " kg-selected" : '')+'">' + m.editinfo.label + '</h2>'; 565 } 566 content += '<ul>' 567 m._initCodePlace(); 568 if (koch_map.editpostmarker === m) { 569 570 571 if (!m.kg_post.geoCodeplaceInfo.address.selected) 572 content += '<li class= "kg-mapinfo-postedit-address"><a HREF="#" title="nur Adresse übernehmen" id="koch_edit_post_address" onclick="return koch_maps[\''+m.kg_map.id+'\'].editpostmarker._setFromAddress()">'+m.kg_post.geoCodeplaceInfo.address.name+'</a></li>'; 573 else 574 content += '<li class= "kg-mapinfo-postedit-address kg-selected">'+m.kg_post.geoCodeplaceInfo.address.name+"</li>"; 575 if (m.kg_post.geoCodeplaceInfo.place) { 576 var ind = 0; 577 m.kg_post.geoCodeplaceInfo.place.forEach(function(el) { 578 if (el){ 579 if (el.selected) 580 content += '<li class= "kg-mapinfo-postedit-place kg-selected">' + el.name + "</li>"; 581 else 582 content += '<li class= "kg-mapinfo-postedit-place"><a HREF="#" title="alle Details übernehmen" id="koch_edit_post_place" onclick="return koch_maps[\''+m.kg_map.id+'\'].editpostmarker._setFromPlace('+ind+')">
582'+el.name+'</a> <a class="kg-open-map" title="Ort in Google Maps öffnen" target="_maps" HREF="https://www.google.com/maps/search/'+el.name+','+el.address+'"></a></li>'; 583 ind++; 584 } 585 }); 586 } 587 if (m.kg_post.geoCodeplaceInfo.location) 588 if (!m.kg_post.geoCodeplaceInfo.location.selected) 589 content += '<li class= "kg-mapinfo-postedit-location"><a HREF="#" title="nur Koordinaten übernehmen" id="koch_edit_post_location" onclick="return koch_maps[\''+m.kg_map.id+'\'].editpostmarker._setFromPosition()">'+m.kg_post.geoCodeplaceInfo.location.string+'</a></li>'; 590 else 591 content += '<li class= "kg-mapinfo-postedit-location kg-selected">'+m.kg_post.geoCodeplaceInfo.location.string+"</li>"; 592 593 } 594 else { 595 content += '<li class= "kg-mapinfo-postedit-address kg-selected">'+m.kg_post.geoCodeplaceInfo.address.name+'</li>'; 596 if (m.kg_post.geoCodeplaceInfo.place) 597 m.kg_post.geoCodeplaceInfo.place.forEach(function(el) { 598 content += '<li class= "kg-mapinfo-postedit-place kg-selected">'+el.name + '</li>'; 599 }); 600 if (m.kg_post.geoCodeplaceInfo.location) 601 content += '<li class= "kg-mapinfo-postedit-location kg-selected">'+m.kg_post.geoCodeplaceInfo.location.string+"</li>"; 602 } 603 content += '</ul>'; 604 } 605 // set standard content 606 else { 607 content = '<div class="kg-mapinfo-label"><h2>'+m.kg_post.label+'</h2></div>'; 608 content += '<div class="kg-mapinfo-content">'; 609 610 if (m.kg_post.videos && m.kg_post.videos.embed){ 611 content += '<div class="kg-mapinfo-video video-format"><div class="fluid-width-video-wrapper" style="padding-top: 56.2963%;">'+m.kg_post.videos.embed+'</div>'; 612 content += '<div class="video-overlay" style="background-image: url('+m.kg_post.img+');"><div class="video-overlay-hover"><a href="#" class="video-play-button"></a></div></div></div>'; 613 } else 614 content += '<div class="kg-mapinfo-image"><img class="kg-mapinfo-img" src="'+m.kg_post.img+'"></div>'; 615 616 content += '<div class="kg-mapinfo-excerpt"><span class="kg-mapinfo-excerpt">'+m.kg_post.excerpt+'</span></div></div>'; 617 content += '<div class="kg-mapinfo-link"><a id="kg-mapinfo-link-'+m.kg_post.postID+'" HREF="'+m.kg_post.url+'">Zum Beitrag</a></div>'; 618 } 619 620 // content = m.kg_post.info; 621 var id = 'toggletax_'+m.kg_map.id; 622 var term = m.kg_map.params.region; 623 var tax = m.kg_map.params.regions; 624 if (m.kg_map.params.regionedit && m.kg_map.params.region && m.kg_map.params.regions) { 625 content = '<div><span id="'+id+'"></span> <span width="100px" id="loading_'+id+'"></span></div><div>'+content+'</div>'; 626 m.kg_map.infowindow.setContent(wrap_open + content + wrap_close); 627 var hastax = m.kg_post.hasTaxonomy(m.kg_map.params.regions,m.kg_map.params.region); 628 google.maps.event.addListenerOnce(m.kg_map.infowindow, 'domready', function(){ 629 jQuery("#"+id) 630 .append(jQuery('<a class="button-secondary" id="click_'+id+'">'+m.kg_map.params.region+" "+(hastax ? " entfernen" : "hinzufügen")+"</a>") 631 .data({marker: m }) 632 .click(function() { 633 // console.log(jQuery(this), jQuery(this).data()); 634 var hastax = m.kg_post.hasTaxonomy(m.kg_map.params.regions,m.kg_map.params.region); 635 m.kg_map._set_ajax_load('infowindow'); 636 $.post(koch_ajax.ajaxurl, 637 { 638 action: 'koch_set_post_term', 639 posts: [m.kg_post.postID], 640 tax: [{taxonomy: tax, term: term, set: !hastax}] 641 }, 642 function (data) { 643 var ret = JSON.parse(data); 644 m.kg_map._clear_ajax_load(); 645 // console.log(ret[m.kg_post.postID]); 646 if (typeof ret[m.kg_post.postID] !== 'undefined' && ret[m.kg_post.postID][tax] !== 'undefined') { 647 648 m.kg_post.setTaxonomy(ret[m.kg_post.postID], {taxonomy: tax, term: term}); 649 // m.kg_post.taxonomies[tax] = ret[m.kg_post.postID][tax] 650 // m.kg_post.selected = ret[m.kg_post.postID][tax][term] === true; 651 // m.kg_post.select(ret[m.kg_post.postID][tax][term] === true); 652 m.kg_map.infowindow.taxtoggleel.text(term +" "+(m.kg_post.selected ? " entfernen" : "hinzufügen")); 653 if (m.kg_map.region.bounds === true) 654 m.kg_map.showRegionBounds(m.kg_map.getBoundsSelected()); 655 } 656 } 657 ); 658 }) 659 ) 660 m.kg_map.infowindow.taxtoggleel= $('#click_'+ id); 661 662 663 }); 664 665 } else 666 m.kg_map.infowindow.setContent(wrap_open + content + wrap_close); 667 } 668 669 el.marker.openInfoWindow = function() { 670 this.kg_map._infowindow_opened = true; 671 this._set_infocontent(); 672 this.kg_map.infowindow.setPosition(this.getPosition()); 673 this.kg_map.infowindow.open(this.get('map'), this); 674 } 675 676 677 el['marker'].addListener('click', function () { 678 this.openInfoWindow(); 679 680 681 return false;
682 }); 683 684 el.marker._initCodePlace = function() { 685 if (!this.kg_post.geoCodeplaceInfo) { 686 this.kg_post.geoCodeplaceInfo = {address: {name: this.kg_post.placeInfo.address}}; 687 if (this.kg_post.placeInfo.place) { 688 this.kg_post.geoCodeplaceInfo.place = [this.kg_post.placeInfo.place]; 689 this.kg_post.geoCodeplaceInfo.place[0].selected = true; 690 this.kg_post.geoCodeplaceInfo.place[0].location = this.getPosition().toJSON(); 691 } 692 } 693 } 694 if (koch_map.params.postedit) { 695 el['marker']._setFromAddress = function() { 696 var that = this; 697 that._clearSelectedPlaces(); 698 console.log("set adress from", that); 699 $(that.editinfo.parent).find("input[name=koch_kontakt_adresse]").val(that.kg_post.geoCodeplaceInfo.address.name ? that.kg_post.geoCodeplaceInfo.address.name.replace(/, Österreich$/, '') : ""); 700 that.kg_post.label = that.kg_post.geoCodeplaceInfo.address.name; 701 that.kg_post.geoCodeplaceInfo.address.selected = true; 702 if (that.kg_post.geoCodeplaceInfo.address.geometry) 703 that.setPosition(that.kg_post.geoCodeplaceInfo.address.geometry.location); 704 that._set_infocontent(); 705 // $('html, body').animate({ 706 // scrollTop: ($(that.editinfo.parent).offset().top) 707 // },500); 708 return false; 709 } 710 711 el['marker']._setFromPosition = function() { 712 var that = this; 713 console.log("set adress from", that); 714 that._clearSelectedPlaces(); 715 $(that.editinfo.parent).find("input[name=koch_kontakt_center]").val(that.kg_post.geoCodeplaceInfo.location.position.lat + "," + that.kg_post.geoCodeplaceInfo.location.position.lng); 716 that.kg_post.label = that.kg_post.geoCodeplaceInfo.location.string ; 717 that.kg_post.geoCodeplaceInfo.location.selected = true; 718 if (that.kg_post.geoCodeplaceInfo.location.position) 719 that.setPosition(that.kg_post.geoCodeplaceInfo.location.position); 720 that._set_infocontent(); 721 // $('html, body').animate({ 722 // scrollTop: ($(that.editinfo.parent).offset().top) 723 // },500); 724 return false; 725 } 726 727 el['marker']._setFromPlace = function(ind = 0) { 728 var that = this; 729 console.log("set place from", that); 730 that._clearSelectedPlaces(); 731 $(that.editinfo.parent).find("input[name=koch_kontakt_adresse]").val(that.kg_post.geoCodeplaceInfo.place[ind].address ? that.kg_post.geoCodeplaceInfo.place[ind].address.replace(/, Österreich$/, '') : ""); 732 $(that.editinfo.parent).find("input[name=koch_kontakt_header]").val(that.kg_post.geoCodeplaceInfo.place[ind].name); 733 $(that.editinfo.parent).find("input[name=koch_kontakt_website]").val(that.kg_post.geoCodeplaceInfo.place[ind].website ? that.kg_post.geoCodeplaceInfo.place[ind].website.replace(/(^\w+:|^)\/\/|\/$/g, '') : ""); 734 $(that.editinfo.parent).find("input[name=koch_kontakt_telefon]").val(that.kg_post.geoCodeplaceInfo.place[ind].phone); 735 $(that.editinfo.parent).find("input[name=koch_kontakt_google_place]").val(that.kg_post.geoCodeplaceInfo.place[ind].name + "," + that.kg_post.geoCodeplaceInfo.place[ind].address); 736 $(that.editinfo.parent).find("input[name=koch_kontakt_address_info]").val(that.kg_post.geoCodeplaceInfo.place[ind].vicintity); 737 that.kg_post.geoCodeplaceInfo.place.forEach(function(el) {el.selected = false}); 738 that.kg_post.geoCodeplaceInfo.place[ind].selected = true; 739 that.kg_post.label = that.kg_post.geoCodeplaceInfo.place[ind].name + "/" + that.kg_post.geoCodeplaceInfo.place[ind].address; 740 if (that.kg_post.geoCodeplaceInfo.place[ind].location) 741 that.setPosition(that.kg_post.geoCodeplaceInfo.place[ind].location); 742 that._set_infocontent(); 743 // $('html, body').animate({ 744 // scrollTop: ($(that.editinfo.parent).offset().top) 745 // },500); 746 return false; 747 } 748 el.marker._clearSelectedPlaces = function () { 749 var that = this; 750 if (that.kg_post.geoCodeplaceInfo.place && that.kg_post.geoCodeplaceInfo.place.length) 751 that.kg_post.geoCodeplaceInfo.place.forEach(function(el) {el.selected = false}); 752 that.kg_post.geoCodeplaceInfo.address.selected = false;
753 if (that.kg_post.geoCodeplaceInfo.location) 754 that.kg_post.geoCodeplaceInfo.location.selected = false; 755 } 756 757 } 758 el['marker'].addListener('mouseover', function () { 759 760 this.oldScaledSize = this.getImageSize(); 761 this.setImageSize({height: this.oldScaledSize.height * 1.2, width: this.oldScaledSize.width * 1.2}); 762 this.oldZIndex = this.getZIndex(); 763 this.setZIndex(999); 764 this.setLabel ({text: this.kg_post.label ? this.kg_post.label : "unknown" , 765 fontFamily: "PT Sans, Helvetica, Arial", color: "#ff0000", 766 padding: "7px", 767 backgroundColor: "rgba(255, 255, 255, 0.7)", 768 fontWeight: "bold", fontSize: "14px"}); 769 770 }); 771 el['marker'].addListener('mouseout', function () { 772 this.setZIndex(this.oldZIndex); 773 this.setImageSize(this.oldScaledSize); 774 this.setLabel (null); 775 }); 776 el.marker.setImageSize = function(size) { 777 var icon = this.getIcon(); 778 icon.scaledSize = size; 779 this.setIcon(icon); 780 }; 781 el.marker.getImageSize = function() { 782 var icon = this.getIcon(); 783 return icon.scaledSize; 784 }; 785 koch_map.markers.push(el['marker']); 786 // oms.trackMarker(el['marker']); 787 return (el); 788 } 789 790 /* init markers for places */ 791 koch_map.setMarkers = function (autobound) { 792 var koch_map = this; 793 if (typeof koch_map.data !== 'undefined' && typeof koch_map.data.places !== 'undefined') { 794 795 var map = koch_map.map; 796 // koch_map.fmap = fmap; 797 // koch_map.map = map; 798 koch_map.markers = new Array(); 799 koch_map.bounds = new google.maps.LatLngBounds(); 800 koch_map.boundsselected = new google.maps.LatLngBounds(); 801 koch_map.infowindow = new InfoBubble({ 802 shadowStyle: 1, 803 padding: 10, 804 borderRadius: 0, 805 minWidth: 300, 806 arrowSize: 10, 807 borderWidth: 1, 808 borderColor: '#ccc', 809 810 hideCloseButton: false, 811 arrowPosition: 50, 812 disableAutoPan: false, 813 backgroundClassName: '', 814 closeSrc: "/wp-content/themes/kochgenossen/img/infobubble_close.png", 815 arrowStyle: 0 816 }); 817 // koch_map.infowindow = new google.maps.InfoWindow(); 818 819 /* init markers */ 820 koch_map.data.samelocations = koch_map._splitSamePositions().dubs; 821 koch_map.data.places.forEach(function(el) { 822 koch_map.addMarker(el); 823 824 825 }); 826 koch_map.data.result.markercnt = koch_map.markers.length; 827 koch_map.params.cluster = koch_map.params.postedit ? true : koch_map.params.cluster; 828 koch_map.setClusterer(!koch_map.params.cluster); 829 830 831 // if (autobound || ! (koch_map.region && koch_map.region.bounds && typeof koch_map.region.bounds === 'object')) { 832 // var bounds = koch_map.zoomSelected(koch_map.params.select); 833 // if (!koch_map.params.regionedit) 834 // koch_map.showRegionBounds(bounds); 835 // else 836 // koch_map.map.fitBounds(bounds,0); 837 // } 838 839 map.addListener('idle', function(e){ 840 // if (koch_map.infowindow.getMap() && koch_map.map.getBounds() && !koch_map.map.getBounds().contains(koch_map.infowindow.getAnchor().getPosition())) 841 if (!koch_map._infowindow_opened && koch_map.infowindow.getMap() && koch_map.map.getBounds() && !(koch_map.infowindow.position && koch_map.map.getBounds().contains(koch_map.infowindow.position))) 842 koch_map.infowindow.close(); 843 koch_map._infowindow_opened = false; 844 }); 845 map.addListener('click', function(e){ 846 koch_map.infowindow.close(); 847 }); 848 849 } 850 851 } 852 853 koch_map.visibleMarkers = function() { 854 var vis = []; 855 $.each(koch_map.markers, function(i,m) { 856 if (m.kg_post.visible()) 857 vis.push(m); 858 }); 859 return vis; 860 } 861 862 } 863/* koch_map private methods */ 864 koch_map.private = function () { 865 koch_map._getMarkerIcon = function (icon, selected) { 866 867 return { 868 url: selected ? this.data.result.icons[icon].enabled : this.data.result.icons[icon].disabled, 869 scaledSize: new google.maps.Size(25, 25), 870 origin: new google.maps.Point(0, 0), 871 size: new google.maps.Size(30, 30), 872 // anchor: new google.maps.Point(32,65), 873 labelOrigin: new google.maps.Point(15,40) 874 } 875 } 876 877 // This function returns the coordinate 878 // conversion string in DD to DMS. 879 koch_map.ddToDms = function (latlng) { 880 881 var lat = latlng.lat; 882 var lng = latlng.lng; 883 var latResult, lngResult, dmsResult; 884 885 lat = parseFloat(lat); 886 lng = parseFloat(lng); 887 888 latResult = (lat >= 0)? 'N' : 'S'; 889 890 // Call to getDms(lat) function for the coordinates of Latitude in DMS. 891 // The result is stored in latResult variable. 892 latResult += koch_map.getDms(lat); 893 894 lngResult = (lng >= 0)? 'E' : 'W'; 895
896 // Call to getDms(lng) function for the coordinates of Longitude in DMS. 897 // The result is stored in lngResult variable. 898 lngResult += koch_map.getDms(lng); 899 900 // Joining both variables and separate them with a space. 901 dmsResult = latResult + ' ' + lngResult; 902 903 // Return the resultant string 904 return dmsResult; 905 } 906 907 // Function that converts DMS to DD. 908 // Taking as example the value -40.601203. 909 koch_map.getDms = function (val) { 910 911 // Required variables 912 var valDeg, valMin, valSec, result; 913 914 // Here you'll convert the value received in the parameter to an absolute value. 915 // Conversion of negative to positive. 916 // In this step it does not matter if it's North, South, East or West, 917 // such verification was performed earlier. 918 val = Math.abs(val); // -40.601203 = 40.601203 919 920 // ---- Degrees ---- 921 // Stores the integer of DD for the Degrees value in DMS 922 valDeg = Math.floor(val); // 40.601203 = 40 923 924 // Add the degrees value to the result by adding the degrees symbol "º". 925 result = valDeg + "º"; // 40º 926 927 // ---- Minutes ---- 928 // Removing the integer of the initial value you get the decimal portion. 929 // Multiply the decimal portion by 60. 930 // Math.floor returns an integer discarding the decimal portion. 931 // ((40.601203 - 40 = 0.601203) * 60 = 36.07218) = 36 932 valMin = Math.floor((val - valDeg) * 60); // 36.07218 = 36 933 934 // Add minutes to the result, adding the symbol minutes "'". 935 result += valMin + "'"; // 40º36' 936 937 // ---- Seconds ---- 938 // To get the value in seconds is required: 939 // 1º - removing the degree value to the initial value: 40 - 40.601203 = 0.601203; 940 // 2º - convert the value minutes (36') in decimal ( valMin/60 = 0.6) so 941 // you can subtract the previous value: 0.601203 - 0.6 = 0.001203; 942 // 3º - now that you have the seconds value in decimal, 943 // you need to convert it into seconds of degree. 944 // To do so multiply this value (0.001203) by 3600, which is 945 // the number of seconds in a degree. 946 // You get 0.001203 * 3600 = 4.3308 947 // As you are using the function Math.round(), 948 // which rounds a value to the next unit, 949 // you can control the number of decimal places 950 // by multiplying by 1000 before Math.round 951 // and subsequent division by 1000 after Math.round function. 952 // You get 4.3308 * 1000 = 4330.8 -> Math.round = 4331 -> 4331 / 1000 = 4.331 953 // In this case the final value will have three decimal places. 954 // If you only want two decimal places 955 // just replace the value 1000 by 100. 956 valSec = Math.round((val - valDeg - valMin / 60) * 3600 * 1000) / 1000; // 40.601203 = 4.331 957 958 // Add the seconds value to the result, 959 // adding the seconds symbol " " ". 960 result += valSec + '"'; // 40º36'4.331" 961 962 // Returns the resulting string. 963 return result; 964 } 965 966 koch_map._resetClusterHook = function() { 967 if (koch_map.clusterer) { 968 koch_map._cluster_zoom = -1; 969 koch_map.clusterer.redraw(); 970 } 971 } 972 973 koch_map._splitSamePositions = function (fix = 4, min = 0.005, max = 0.04) { 974 var lat = new Object(); 975 $.each(this.data.places, function(i, el) { 976 if (el.position) { 977 var ind = el.position.lat.toFixed(fix) +':'+el.position.lng.toFixed(fix); 978 if (typeof lat[ind] === 'undefined') 979 lat[ind] = {pos: el.position, cnt: 0, posts: new Array()}; 980 lat[ind].cnt++; 981 lat[ind].posts.push(el); 982 } 983 }); 984 var dubs = new Array(); 985 986 $.each(lat, function(i, el) { 987 988 if (el.cnt > 1) { 989 el.newpos = new Array(); 990 // max = el.cnt * max / 2; 991 var first = true; 992 el.posts.forEach(function (p) { 993 if (!first){ 994 p.orig_position = p.position; 995 p.position = koch_destinationPoint(p.position, min, max, true); 996 el.newpos.push(p.position); 997 if (p.marker) 998 p.marker.setPosition(p.position); 999 } 1000 first = false;
1001 p.samepos = el.posts; 1002 }); 1003 dubs.push(el); 1004 } 1005 1006 1007 1008 1009 }); 1010 return {pos: lat, dubs: dubs}; 1011 } 1012 1013 koch_map._init_firstViewport = function(south, retry = 3) { 1014 koch_map.bounds_expected = {bounds: null, center: null, zoom: null, regionbounds: null}; 1015 if (koch_map.region && koch_map.region.region) 1016 koch_map.bounds_expected.bounds = koch_map._zoomRegion(koch_map.region.region); 1017 if (!koch_map.bounds_expected.bounds) { 1018 var visible = koch_map.visibleMarkers(); 1019 if (visible.length == 0) 1020 koch_map.bounds_expected.bounds = {"west":4.081935882568359, 1021 "south":44.62957319195104, 1022 "north":51.44031275716012, 1023 "east":16.84804916381836}; 1024 else if (visible.length > 1) 1025 koch_map.bounds_expected.bounds = koch_map.bounds; // koch_map.map.fitBounds(koch_map.bounds); 1026 else 1027 koch_map.bounds_expected= {bounds: null, zoom: 14, center: visible[0].getPosition()}; // koch_map.map.setZoom(11); 1028 } 1029 koch_map._set_firstViewport(); 1030 console.log("expecting view", koch_map.bounds_expected); 1031 google.maps.event.addListenerOnce(koch_map.map, 'idle', function(map) { 1032 koch_map._check_firstViewport(retry); 1033 }); 1034 1035 1036 1037 } 1038 1039 koch_map._set_firstViewport = function() { 1040 if (koch_map.bounds_expected.bounds && typeof koch_map.bounds_expected.bounds.toJSON !== 'undefined') 1041 koch_map.bounds_expected.bounds = koch_map.bounds_expected.bounds.toJSON(); 1042 if (koch_map.bounds_expected.bounds) 1043 koch_map.map.fitBounds(koch_map.bounds_expected.bounds); 1044 if (koch_map.bounds_expected.center){ 1045 koch_map.map.setCenter(koch_map.bounds_expected.center); 1046 if (!koch_map.bounds_expected.zoom) 1047 koch_map.maxZoom(); 1048 } 1049 if (koch_map.bounds_expected.zoom) 1050 koch_map.map.setZoom(koch_map.bounds_expected.zoom); 1051 koch_map.maxZoom(); 1052 1053 } 1054 1055 koch_map._check_firstViewport = function(retry = 3) { 1056 setTimeout(function() { 1057 console.log("try init viewport"); 1058 if (koch_map.bounds_expected.bounds && koch_map.bounds_expected.bounds.south == koch_map.map.getBounds().toJSON().south) 1059 return true; 1060 if (koch_map.bounds_expected.zoom && koch_map.bounds_expected.zoom == koch_map.map.getZoom()) 1061 return true; 1062 koch_map._set_firstViewport(); 1063 // console.log ("still not set", {expected: koch_map.bounds_expected, actual: koch_map.map.getBounds().toJSON()}); 1064 if (retry) 1065 google.maps.event.addListenerOnce(koch_map.map, 'bounds_changed', function(map) { 1066 koch_map._check_firstViewport(--retry); 1067 }); 1068 }, 100); 1069 } 1070 1071 // google.maps.event.addListener(koch_map.map, 'bounds_changed', function(map) { 1072 // console.log ("bounds changed to", koch_map.map.getBounds() ? koch_map.map.getBounds().toJSON() : "no bounds"); 1073 // }); 1074 1075 // google.maps.event.addListener(koch_map.map, 'idle', function(map) { 1076 // console.log ("map idle with", koch_map.map.getBounds() ? koch_map.map.getBounds().toJSON() : "no bounds"); 1077 // }); 1078 1079 // google.maps.event.addListener(koch_map.map, 'zoom_changed', function(map) { 1080 // console.log ("map zoom changed with", koch_map.map.getBounds() ? koch_map.map.getBounds().toJSON() : "no bounds"); 1081 // }); 1082 1083 koch_map._zoomRegion = function (region) { 1084 koch_map = this; 1085 var bounds = null; 1086 koch_map.bounds_expected = {bounds: null, center: null, zoom: null, region: null}; 1087 if (typeof koch_map.region !== 'undefined' && koch_map.region.region == region) { 1088 if (koch_map.region.bounds === true) 1089 bounds = koch_map.zoomSelected(); 1090 else if (koch_map.region.bounds && typeof koch_map.region.bounds === 'object' && koch_map.region.bounds.hasOwnProperty('south')) 1091 bounds = koch_map.region.bounds; 1092 else 1093 bounds = 'auto'; 1094 } 1095 else if(typeof koch_map.regionlinks !== 'undefined' && koch_map.regionlinks[region] !== 'undefined') 1096 bounds = koch_map.regionlinks[region].bounds; 1097 1098 if (bounds == 'auto' || typeof bounds !== 'object') { 1099 if (typeof koch_map.bounds === 'object') { 1100 koch_map.map.fitBounds(koch_map.bounds,1); 1101 koch_map.showRegionBounds(koch_map.bounds); 1102 } 1103 } else { 1104 koch_map.map.fitBounds(bounds,1); 1105 koch_map.showRegionBounds(bounds); 1106 koch_map.bounds_expected.bounds = bounds; 1107 1108 } 1109 return bounds; 1110 } 1111 1112 1113 1114 koch_map._showClustererLabel = function(c, text, show = true) { 1115 var l = koch_map._cluster_icon_label; 1116 if (!show) { 1117 l.style.visibility = 'none'; 1118 c.div_.parentNode.removeChild(l); 1119 return; 1120 } 1121 l.style.top = ($(c.div_).position().top + $(c.div_).outerHeight()) + "px"; 1122 l.style.left = $(c.div_).position().left + "px"; 1123 l.style.visibility = ''; 1124 l.style.fontSize = "14px"; 1125 l.style.fontWeight = "bold"; 1126 l.style.fontFamily = "PT Sans, Helvetica, Arial"; 1127 l.style.color = "#ff0000"; 1128 l.style.position = "absolute"; 1129 l.style.padding = "7px"; 1130 l.style.backgroundColor = "rgba(255, 255, 255, 0.7)"; 1131 // l.style.opacity = 0.3; 1132 l.innerHTML = " "+text+" "; 1133 1134 c.div_.parentNode.appendChild(l); 1135 l.style.left = ($(c.div_).position().left + $(c.div_).outerWidth() / 2 - $(l).outerWidth()/2) + "px"; 1136 1137 1138 } 1139 1140 1141 1142 koch_map._region_rect = function (bound) { 1143 if (typeof this.latlngrec !== 'object') 1144 this._init_lat_lng_rect(); 1145 if (bound && typeof bound.getJSON !== 'undefined') 1146 bound = bound.toJSON(); 1147 this.latlngrec.setBounds(bound); 1148 this.latlngrec.setMap(this.map) 1149 } 1150 1151 koch_map._init_lat_lng_rect = function (){ 1152 var koch_map = this; 1153 if (typeof koch_map.latlngrec === 'object' && typeof koch_map.latlngrec.setMap !== 'undefined') 1154 koch_map.latlngrec.setMap(null); 1155 koch_map.latlngrec= new google.maps.Rectangle({ 1156 strokeColor: '#000000', 1157 strokeOpacity: 0.2, 1158 strokeWeight: koch_map.params.loglatlng ? 2 : 0, 1159 fillColor: '#000000', 1160 fillOpacity: koch_map.params.loglatlng ? 0.2 : 0.1, 1161 draggable: koch_map.params.loglatlng ? true : false 1162 1163 }); 1164 if (koch_map.params.loglatlng) { 1165 koch_map.latlngrec.addListener('drag', function() { 1166 // console.log ("drag rect", koch_map.latlngrec.getBounds().toJSON()); 1167 koch_map._set_boundery_marker(koch_map.latlngrec.getBounds().toJSON()); 1168 }); 1169 koch_map.latlngrec.addListener('dragend', function() { 1170 // console.log ("dragend rect", koch_map.latlngrec.getBounds().toJSON()) 1171 koch_map._set_boundery_marker(koch_map.latlngrec.getBounds().toJSON()); 1172 koch_map._fit_lat_lng_markers(false,true); 1173 }); 1174 } 1175 } 1176 1177 /* logger for selecting bounds if param loglatlng is set */ 1178
1179 koch_map._log_latlng = function () { 1180 var koch_map = this; 1181 1182 // if (!koch_map.params.showbounds) 1183 // koch_map.params.showbounds = true; 1184 1185 /* map listener for lat lng logging*/ 1186 var gmap = koch_map.map; 1187 1188 /* set dummy markers to recieve further events */ 1189 koch_map._gmap_set_dummy_marker = function() { 1190 return; 1191 koch_map._add_lat_lng_marker({lat: -1, lng: -1}, "a", koch_map.latlngtrackers, false); 1192 koch_map._add_lat_lng_marker({lat: -1, lng: -1}, "b", koch_map.latlngtrackers, false); 1193 koch_map._add_lat_lng_marker({lat: -1, lng: -1}, "nw", false); 1194 koch_map._add_lat_lng_marker({lat: -1, lng: -1}, "sw", false); 1195 koch_map._add_lat_lng_marker( {lat: -1, lng: -1}, "ne", false); 1196 koch_map._add_lat_lng_marker({lat: -1, lng: -1}, "se", false); 1197 } 1198 1199 1200 koch_map._init_drag_draw_marker = function (create = true) { 1201 if (create) { 1202 koch_map._init_drag_draw_marker_marker = {a: null}; 1203 koch_map._add_lat_lng_marker(koch_map._init_drag_draw_position, "a", koch_map._init_drag_draw_marker_marker); 1204 } 1205 else 1206 koch_map._clear_markers(koch_map._init_drag_draw_marker_marker, {a: null}); 1207 1208 } 1209 1210 koch_map._init_drag_draw = function (e) { 1211 // console.log ("waited long enough"); 1212 1213 koch_map.map.setOptions({draggableCursor:'crosshair'}); 1214 koch_map._gmap_drag_listener_handle = []; 1215 1216 koch_map._init_drag_draw_marker(); 1217 koch_map._gmap_drag_listener_handle.push(gmap.addListener('dragstart', function(e) {koch_map._gmap_drag_listener();})); 1218 // koch_map._gmap_drag_listener_handle.push(gmap.addListener('mouseup', function(e) {koch_map._gmap_dragend();})); 1219 } 1220 1221 gmap.addListener('mouseup', function(e) { 1222 // console.log("mouse up - clear all"); 1223 clearTimeout(koch_map._init_drag_draw_timer); 1224 koch_map._gmap_dragend(e); 1225 1226 }); 1227 1228 gmap.addListener('mousedown', function(e) { 1229 koch_map._init_drag_draw_position = e.latLng.toJSON(); 1230 koch_map._init_drag_draw_timer = setTimeout(function () {koch_map._init_drag_draw(e);}, 500); 1231 return true; 1232 }); 1233 1234 gmap.addListener('drag', function(e) { 1235 clearTimeout(koch_map._init_drag_draw_timer); 1236 1237 return true; 1238 }); 1239 1240 koch_map._gmap_drag_listener = function(e) { 1241 // console.log ("disbale gmap scroll gestures"); 1242 gmap.setOptions({draggable: false}); 1243 koch_map.map.setOptions({draggableCursor:'crosshair'}); 1244 koch_map._init_lat_lng_markers(); 1245 koch_map._gmap_set_dummy_marker(); 1246 koch_map._init_track = true; 1247 koch_map._track = true; 1248 koch_map._gmap_mousemove_listener = gmap.addListener('mousemove', function(e) {koch_map._gmap_mousemove(e)}); 1249 return true; 1250 1251 }; 1252 koch_map._gmap_dragend = function(e) { 1253 google.maps.event.removeListener(koch_map._gmap_mousemove_listener); 1254 // console.log ("track gmap dragend"); 1255 koch_map._init_drag_draw_marker(false); 1256 if (koch_map._track) { 1257 1258 gmap.setOptions({draggable: true}); 1259 koch_map.map.setOptions({draggableCursor:null}); 1260 koch_map._gmap_mousedown = false; 1261 koch_map._track = false; 1262 koch_map._propagate_bounds(koch_map.latlngbounds); 1263 koch_map.latlngtrackers = koch_map._clear_markers(koch_map.latlngtrackers, {a: null, b: null}); 1264 1265 } 1266 if (koch_map._gmap_drag_listener_handle && koch_map._gmap_drag_listener_handle.length) 1267 koch_map._gmap_drag_listener_handle.forEach(function(el) { 1268 google.maps.event.removeListener(el);}) 1269 google.maps.event.removeListener(koch_map._gmap_mousemove_listener); 1270 koch_map.map.setOptions({draggableCursor:null}); 1271 gmap.setOptions({draggable: true}); 1272 1273 return true; 1274 }; 1275 1276 1277 koch_map._gmap_mousemove = function(e) { 1278 // console.log ("track: gmap mousemove ", e); 1279 if (koch_map._track) { 1280 koch_map._init_drag_draw_marker(false); 1281 if (koch_map._init_track) { 1282 koch_map._add_lat_lng_marker(e.latLng.toJSON(), "a", koch_map.latlngtrackers); 1283 koch_map._add_lat_lng_marker(e.latLng.toJSON(), "b", koch_map.latlngtrackers); 1284 // gmap.addListener('dragend', koch_map._gmap_dragend); 1285 // gmap.addListener('mouseup', koch_map._gmap_dragend); 1286 koch_map._init_track = false; 1287 1288 } else { 1289 koch_map._add_lat_lng_marker(e.latLng.toJSON(), "b", koch_map.latlngtrackers); 1290 var bounds = koch_map._get_latlngbounds(null, koch_map.latlngtrackers); 1291 if (bounds) 1292 koch_map.showRegionBounds(bounds); 1293 /* hack! events lost trigger with set timeout */ 1294 if (koch_map._gmap_mouse_timeout) 1295 clearTimeout(koch_map._gmap_mouse_timeout); 1296 koch_map._gmap_mouse_timeout = setTimeout(koch_map._gmap_dragend, 300); 1297 1298 } 1299 1300 } 1301 1302 return true; 1303 1304 } 1305 koch_map._set_boundery_marker = function (bounds) { 1306 var koch_map = this; 1307 if (typeof bounds == 'object') { 1308 1309 if (bounds && typeof bounds.toJSON !== 'undefined') 1310 bounds = bounds.toJSON(); 1311 if (bounds && bounds.north) { 1312 koch_map._add_lat_lng_marker({lat: bounds.north, lng: bounds.west}, "nw"); 1313 koch_map._add_lat_lng_marker({lat: bounds.south, lng: bounds.west}, "sw"); 1314 koch_map._add_lat_lng_marker( {lat: bounds.north, lng: bounds.east}, "ne"); 1315 koch_map._add_lat_lng_marker({lat: bounds.south, lng: bounds.east}, "se"); 1316 return true; 1317 } 1318 } 1319 return false;
1320 } 1321 koch_map._get_latlngbounds = function (corner = null, markers = null) { 1322 var koch_map = this; 1323 var bnd = new google.maps.LatLngBounds(); 1324 var cnt_marker = 0; 1325 if (!markers) 1326 markers = koch_map.latlngmarkers; 1327 if (typeof markers !== 'undefined') 1328 $.each(markers, function(k, el) { 1329 if (!corner || ((corner == "ne" || corner == "sw") && (k == "ne" || k == "sw")) || ((corner == "nw" || corner == "se") && (k == "nw" || k == "se") )) 1330 if (el && el.position) { 1331 bnd.extend(el.position); 1332 cnt_marker++; 1333 } 1334 }); 1335 if (cnt_marker > 0) 1336 koch_map.latlngbounds = bnd; 1337 else 1338 bnd = null; 1339 return bnd; 1340 } 1341 1342 koch_map._add_lat_lng_marker = function (pos, corner, markers = null, track = true) { 1343 var koch_map = this; 1344 if (!markers) { 1345 if (typeof koch_map.latlngmarkers === 'undefined') 1346 koch_map._init_lat_lng_markers(); 1347 markers = koch_map.latlngmarkers; 1348 } 1349 if (markers && markers[corner] && !(typeof markers[corner].setMap == "undefined")) { 1350 markers[corner].setPosition(pos); 1351 // markers[corner].setMap(koch_map.map); 1352 } 1353 else 1354 { var mark = new google.maps.Marker({ 1355 position: pos, 1356 draggable: true, 1357 map: koch_map.map, 1358 1359 icon: { 1360 url: "/wp-content/themes/kochgenossen/img/kg_corner_marker.png", 1361 anchor: new google.maps.Point(15, 20) 1362 1363 } 1364 }); 1365 mark.koch_map = koch_map; 1366 mark.corner = corner; 1367 1368 markers[corner] = mark; 1369 if (track) { 1370 mark.addListener('dragend', function() { 1371 // console.log(this); 1372 // this.koch_map._fit_lat_lng_markers(this.corner, true); 1373 this.koch_map._clear_markers(this.koch_map.latlngtrackers); 1374 this.koch_map._fit_lat_lng_markers(); 1375 // koch_map.showRegionBounds(koch_map.latlngbounds, true); 1376 this.koch_map.map.fitBounds(this.koch_map.latlngbounds); 1377 this.koch_map._propagate_bounds(this.koch_map.latlngbounds); 1378 // this.koch_map._set_boundery_marker(this.koch_map.latlngbounds.toJSON()); 1379 }); 1380 mark.addListener('drag', function() { 1381 // console.log(this.position.toJSON(), this.corner); 1382 this.koch_map._add_lat_lng_marker(this.position.toJSON(), "a", this.koch_map.latlngtrackers); 1383 var bound = this.koch_map._get_latlngbounds(null, this.koch_map.latlngtrackers); 1384 if (bound) 1385 this.koch_map.showRegionBounds(bound); 1386 1387 1388 }); 1389 mark.addListener('dragstart', function() { 1390 1391 var opo = {nw: "se", ne: "sw", sw: "ne", se: "nw"}; 1392 // swap markers 1393 // this.koch_map.latlngmarkers[this.corner] = this.koch_map.latlngtrackers.a; 1394 this.koch_map._add_lat_lng_marker(this.position.toJSON(), "a", this.koch_map.latlngtrackers); 1395 this.koch_map._add_lat_lng_marker(this.koch_map.latlngmarkers[opo[this.corner]].position.toJSON(), "b", this.koch_map.latlngtrackers); 1396 // console.log(this.corner, this.koch_map.latlngtrackers); 1397 1398 1399 1400 }); 1401 } 1402 } 1403 } 1404 1405 koch_map._clear_markers = function (markers, init = null) { 1406 if (typeof markers === 'object') 1407 $.each(markers, function(k, el) { 1408 if (el && typeof el.setMap !== 'undefined') 1409 el.setMap(null) 1410 }); 1411 markers = init; 1412 return markers; 1413 } 1414 koch_map._init_lat_lng_markers = function (){ 1415 var koch_map = this; 1416 koch_map.latlngmarkers = koch_map._clear_markers(koch_map.latlngmarkers, {nw: null, sw: null, ne: null, se: null}); 1417 koch_map.latlngtrackers = koch_map._clear_markers(koch_map.latlngtrackers,{a: null, b: null}); 1418 if (koch_map.latlngrec && typeof koch_map.latlngrec.setMap !== 'undefined') { 1419 koch_map.latlngrec.setMap(null) 1420 } 1421 koch_map._init_lat_lng_rect(); 1422 } 1423 1424 1425 1426 koch_map._fit_lat_lng_markers = function (corner = false, prop
1426agate = false, markers = false) { 1427 var koch_map = this; 1428 var bound = koch_map._get_latlngbounds(corner, markers); 1429 if (bound) { 1430 if (koch_map.latlngrec && typeof koch_map.latlngrec.setMap !== 'undefined') { 1431 koch_map.latlngrec.setBounds(bound); 1432 koch_map.latlngrec.setMap(koch_map.map) 1433 } 1434 // in edit mode set textarea of specified field 1435 if (propagate) 1436 koch_map.map.fitBounds(bound,1); 1437 } 1438 if (propagate) 1439 koch_map._propagate_bounds(bound); 1440 return bound; 1441 } 1442 koch_map._init_lat_lng_markers(); 1443 } 1444 1445 koch_map._propagate_bounds = function(bound) { 1446 var evt = jQuery.Event('koch_map_latlngbounds'); 1447 evt.koch_map = this; 1448 var editval = ""; 1449 if (bound && typeof bound == 'object') { 1450 koch_map.latlngbounds = bound; 1451 if (bound && typeof bound.toJSON !== 'undefined') 1452 bound = bound.toJSON(); 1453 editval = JSON.stringify(bound); 1454 evt.bounds = bound; 1455 } else { 1456 koch_map.latlngbounds = null; 1457 evt.bounds = null; 1458 } 1459 1460 if (koch_map.params.editfield) 1461 jQuery("textarea[name="+koch_map.params.editfield+"]").val(editval); 1462 jQuery(window).trigger(evt); 1463 1464 1465 } 1466 1467 koch_map._set_ajax_load = function (ele) { 1468 if (ele == 'infowindow') 1469 ele = $("#kg_placeinfo_taxedit").closest(".gm-style-iw"); 1470 else 1471 ele = "#"+ ele; 1472 $("#"+this.id).Wload({el: ele}); 1473 } 1474 1475 koch_map._clear_ajax_load = function () { 1476 $('#' + this.id).Wload('hide', {time: 1}); 1477 } 1478 1479 koch_map._get_region_poly = function(region) { 1480 $.getJSON(koch_ajax.ajaxurl + '?region=' + region + "&action=koch_get_nominatim", function (data) { 1481 1482 // koch_maps[mapid] = new Object(); 1483 console.log(data); 1484 koch_map.map.data.setStyle( { 1485 fillColor: 'red', 1486 fillOpacity: 0.2, 1487 strokeColor: 'red', 1488 strokeOpacity: 0.4, 1489 strokeWeight: 1 }); 1490 if (data && data.geojson) 1491 koch_map.map.data.addGeoJson({type: "Feature", id: data.place_id, geometry: data.geojson, properties: {data: data}}); 1492 1493 }); 1494 } 1495 1496 1497 koch_map._finishLoad = function() { 1498 if (koch_map.data && koch_map.data.result) { 1499 if (typeof koch_map.data.result.termlinks !== 'undefined'){ 1500 var adtax = koch_map.data.result.termlinks.length > 1; 1501 var tl = ""; 1502 1503 koch_map.data.result.termlinks.forEach(function(el) { 1504 var txdef = koch_map.data.result.taxonomies; 1505 tl += adtax ? txdef[el].label + ": " : ""; 1506 var terms = Object.keys(txdef[el].terms); 1507 terms.forEach(function(elem){ 1508 tl+= '<a HREF="#" onclick="koch_maps[\''+koch_map.id+'\'].selectPlaces(\''+el+'\',\''+elem+'\'); return false">>'+txdef[el].terms[elem].label+'</a> '; 1509 }); 1510 tl += adtax ? "</br>" : ""; 1511 1512 }); 1513 $("#koch_termlinks_"+koch_map.id).html(tl); 1514 1515 } 1516 koch_map._clear_ajax_load(); 1517 1518 } 1519 1520 koch_map.initMenu(); 1521 koch_map._isLoaded = true; 1522 if (koch_map.params.postedit) { 1523 koch_map.geocoder = new google.maps.Geocoder(); 1524 koch_map.placesservice = new google.maps.places.PlacesService(koch_map.map); 1525 var m = koch_map; 1526 $.each(koch_map.markers, function (i,e) { 1527 if (e.kg_post.id) 1528 e.editinfo = {pos: parseInt(e.kg_post.id.substr(e.kg_post.id.length -1)), label: "Kontaktinfo " + (parseInt(e.kg_post.id.substr(e.kg_post.id.length -1)) + 1)}; 1529 }); 1530 1531 koch_map._resetEditMarkerPos = function () { 1532 // console.log (koch_map.editpostmarker); 1533 if (koch_map.editpostmarker && koch_map.editpostmarker.kg_post && koch_map.editpostmarker.kg_post.position) { 1534 koch_map.editpostmarker.setPosition(koch_map.editpostmarker.kg_post.position); 1535 koch_map.editpostmarker.kg_post.geoCodeplaceInfo = {address: {name: koch_map.editpostmarker.kg_post.placeInfo.address}} 1536 koch_map.editpostmarker._set_infocontent(); 1537 } 1538 } 1539 1540 koch_map._initEditMarker = function (address = false, zoom=true, create=true) { 1541 $.each(koch_map.markers, function(i, el) { 1542 el.kg_post.select(false); 1543 el.setOptions({draggable: false}); 1544 1545 }); 1546 if ((!address === false)) { 1547 address = address + ""; 1548 address = address.substr(address.length - 1); 1549 if (!parseInt(address)) 1550 address = false;
1551 } 1552 if (!(address === false)) { 1553 address = parseInt(address); 1554 koch_map.editpostmarker = koch_map.GetMarkerByID(koch_map.params.postid + "_" + address); 1555 1556 1557 1558 koch_map.editpostmarker.editinfo = {pos: address, label: "Kontaktinfo " + (address + 1), parent: '#update_container_koch_kontakt_info_'+ address}; 1559 if (zoom) { 1560 koch_map.map.setCenter(koch_map.editpostmarker.getPosition()); 1561 koch_map.maxZoom(); 1562 } 1563 koch_map.editpostmarker.openInfoWindow(); 1564 1565 } else { 1566 1567 var m = koch_map.GetMarkerByID("new"); 1568 if (!m && koch_map.editpostmarker && koch_map.editpostmarker.kg_post) { 1569 koch_map.markers.push(koch_map.editpostmarker); 1570 } else 1571 koch_map.editpostmarker = m; 1572 1573 1574 if (!koch_map.editpostmarker && create) { 1575 koch_map.editpostmarker = koch_map.addMarker( 1576 { 1577 id: "new", 1578 icon:"icon", 1579 1580 label: 'new address' 1581 }).marker; 1582 koch_map.editpostmarker.editinfo = {pos: -1, label: "Neue Kontaktinfo", parent: '#koch_kontakt_info'}; 1583 1584 1585 } else if (zoom && koch_map.editpostmarker.getPosition()) { 1586 koch_map.map.setCenter(koch_map.editpostmarker.getPosition()); 1587 koch_map.maxZoom(); 1588 } 1589 1590 } 1591 if (koch_map.editpostmarker && koch_map.editpostmarker.getPosition()){ 1592 koch_map.editpostmarker.setOptions({draggable: true}); 1593 koch_map.editpostmarker.kg_post.select(); 1594 google.maps.event.removeListener(koch_map.editpostmarker_listener); 1595 koch_map.editpostmarker_listener = koch_map.editpostmarker.addListener('dragend', function() { 1596 // console.log('get new position') 1597 koch_map.editpostmarker_wasdragged = true; 1598 koch_map.GeoCode({location: koch_map.editpostmarker.getPosition().toJSON()}); 1599 1600 }); 1601 } 1602 // console.log("current address set to: ", koch_map.editpostmarker); 1603 1604 1605 } 1606 1607 $('.document').bind("DOMSubtreeModified", function() { 1608 // console.log ("dom changed"); 1609 koch_map.listenedit(); 1610 }); 1611 /* 1612 reorganize ui - show only header and adress field in list 1613 */ 1614 $('#kontaktinfo').show(); 1615 $('#kontaktinfo tr[id^=element_] li[class^=row-koch_kontakt]').hide(); 1616 $('#kontaktinfo tr[id^=element_] li.row-koch_kontakt_header').show(); 1617 $('#kontaktinfo tr[id^=element_] li.row-koch_kontakt_adresse').show(); 1618 $('#kontaktinfo #koch_kontakt_info li').css('margin-bottom','5px'); 1619 var kidiv = $('#kontaktinfo').detach(); 1620 $('#koch_post_edit_map').after(kidiv); 1621 1622 1623 koch_map._getMarkerByPos = function (post, pos) { 1624 if (pos == -1) 1625 return koch_map.GetMarkerByID('new'); 1626 else 1627 return koch_map.GetMarkerByID(post + "_" + pos); 1628 } 1629 1630 koch_map._setMarkerPos = function (marker, post, pos) { 1631 post = (post == null ? koch_map.params.postid : post); 1632 if (pos == false) { 1633 marker.kg_post.id = marker.kg_post.id + "__"; 1634 marker.editinfo.pos = false; 1635 marker.kg_post.hide(); 1636 } else if(parseInt(pos) >= 0) { 1637 1638 marker.kg_post.id = post + "_" + pos; 1639 marker.editinfo.pos = parseInt(pos); 1640 } else { 1641 marker.kg_post.id = "new"; 1642 marker.editinfo.pos = -1; 1643 } 1644 1645 return marker; 1646 } 1647 1648 1649 if (!koch_map.wck_removeMeta) 1650 koch_map.wck_removeMeta = window.removeMeta; 1651 koch_map.editpost_removed = false; 1652 window.removeMeta = function(a,post,id,d) { 1653 koch_map.editpost_removed = false; 1654 // console.log ("wck remove meta called for", arguments); 1655 if (a === "koch_kontakt_info") { 1656 window.koch_map_confirm = window.confirm; 1657 1658 window.confirm = function(q) { 1659 // console.log ("wck confirm", {q: q, arguments:arguments}); 1660 var ret = window.koch_map_confirm(q); 1661 // console.log ("wck confirmed", ret); 1662 window.confirm = window.koch_map_confirm; 1663 koch_map.editpost_removed = ret; 1664 return ret; 1665 } 1666 } 1667 koch_map.wck_removeMeta(a,post,id,d); 1668 // console.log("wck finished"); 1669 if (koch_map.editpost_removed) { 1670 // console.log("item removed"); 1671 koch_map._refetchData(); 1672 // var m = koch_map._getMarkerByPos(post); 1673 // id = parseInt(id); 1674 // koch_map._setMarkerPos(m, post, false); 1675 // var ind = 0; 1676 // $.each(koch_map.markers, function(i,el) { 1677 // m = koch_map._getMarkerByPos(ind); 1678 // if(m) { 1679 // ind++; 1680 // } 1681 // if (m && m.editinfo.pos > id) { 1682 // koch_map._setMarkerPos(m, post, m.editinfo.pos -1 ); 1683 // } 1684 1685 // }); 1686 } 1687 1688 1689 1690 } 1691 $("#container_koch_kontakt_info").find("a[title='Edit this item']").click(function(){ 1692 var that = this; 1693 koch_map.waitforsecondedit_i = setInterval(function() {koch_map.waitforsecondedit(that)}, 100); 1694 return false;
1695 }); 1696 1697 $("#container_koch_kontakt_info").find("a[title='Delete this item']").click(function(){ 1698 var that = this; 1699 // console.log("delete item clicked"); 1700 return false; 1701 }); 1702 1703 1704 $("li.add-entry-button").find("a").click(function(){ 1705 // console.log ("add entry clicked"); 1706 var newPos = 0; 1707 $.each(koch_map.markers, function(i,e) { 1708 newPos = e.editinfo && (e.editinfo.pos >= newPos) ? e.editinfo.pos + 1 : newPos; 1709 }); 1710 // console.log ("add new entry clicked ", newPos); 1711 koch_map.editpostmarker.setMap(null); 1712 koch_map.editpostmarker = null; 1713 koch_map._refetchData(); 1714 return false; 1715 }) 1716 1717 koch_map._refetchData = function () { 1718 // console.log ("get new data in 3 secs"); 1719 koch_map._set_ajax_load(koch_map.id); 1720 $.each(koch_map.data.places, function(i,el) { 1721 el.marker.setMap(null); 1722 }); 1723 setTimeout(function () { 1724 1725 // $.getJSON('/places/places.json?postid=' + koch_map.params.postid + "&postedit=1&refetch", function (data) { 1726 $.getJSON(koch_ajax.ajaxurl + '?postid=' + koch_map.params.postid + "&postedit=1&refetch&action=koch_get_places", function (data) { 1727 1728 // koch_maps[mapid] = new Object(); 1729 1730 koch_map.data = data; 1731 koch_map.setMarkers( false); 1732 koch_map._finishLoad(); 1733 }); }, 5000); 1734 } 1735 1736 koch_map.waitforsecondedit = function(editbutton) { 1737 if ($("input[name=koch_kontakt_adresse]").length > 1) { 1738 clearInterval(koch_map.waitforsecondedit_i); 1739 var addr = $(editbutton).closest("tr").attr('id') 1740 if (addr) 1741 addr = parseInt(addr.substr(addr.length - 1)); 1742 console.log ("edit kochinfo clicked", addr); 1743 1744 $('#kontaktinfo #koch_kontakt_info').hide(); 1745 $('#kontaktinfo tr[id^=update_container_koch_kontakt_info]').hide(); 1746 $('#kontaktinfo #update_container_koch_kontakt_info_'+addr).show(); 1747 $('#kontaktinfo #update_container_koch_kontakt_info_'+addr+" li").css('margin-bottom','5px'); 1748 $($('#kontaktinfo #update_container_koch_kontakt_info_'+addr+' a')[1]) 1749 .after( 1750 $('<a id="koch_edit_cancel" href="#" class="button-secondary" style="margin-left: 10px; display: inline-block;" ><span>Cancel</span></a>')); 1751 $('#koch_edit_cancel').click(function () { 1752 console.log ("cancel clicked"); 1753 $('#kontaktinfo #update_container_koch_kontakt_info_'+addr+' a')[1].click(); 1754 $('#kontaktinfo #koch_kontakt_info').show(); 1755 koch_map.infowindow.close(); 1756 koch_map._resetEditMarkerPos(); 1757 1758 koch_map.editpostmarker.kg_post.geoCodeplaceInfo = null; 1759 koch_map.editpostmarker = null; 1760 1761 koch_map._initEditMarker(false, false, false); 1762 return false; 1763 1764 }); 1765 1766 $($('#kontaktinfo #update_container_koch_kontakt_info_'+addr+' a')[0]).click(function() { 1767 console.log ("save clicked"); 1768 $('#kontaktinfo #koch_kontakt_info').show(); 1769 koch_map._refetchData(); 1770 }) 1771 1772 $($('#kontaktinfo #update_container_koch_kontakt_info_'+addr+' a')[1]).hide(); 1773 $('html, body').animate({ 1774 scrollTop: $('#kontaktinfo #update_container_koch_kontakt_info_'+addr).offset().top 1775 },500); 1776 1777 1778 1779 koch_map.listenedit(addr); 1780 1781 // $("tr[id^='update_container_koch_kontakt_info']").find("a").click(function () { 1782 // console.log ("save clicked") 1783 // $("#container_koch_kontakt_info").find("tr[id^='element_']").show(); 1784 // $("#koch_kontakt_info").show(); 1785 // }); 1786 // $($("tr[id^='update_container_koch_kontakt_info']").find("a")[1]).click(function () { 1787 // console.log ("cancel clicked") 1788 // $("#container_koch_kontakt_info").find("tr[id^='element_']").show(); 1789 // $("#koch_kontakt_info").show(); 1790 // }); 1791 } 1792 else console.log ("wait for new edit field"); 1793 } 1794 // koch_map._listen_address_change = function() { 1795 // console.log({ text: $(this).val(), ele: $(this).closest(".update_container_koch_kontakt_info").attr('id')}); 1796 // var address = $(this).closest(".update_container_koch_kontakt_info").attr('id'); 1797 // if (address) 1798 // address = address.substr(address.length - 1); 1799 // koch_map._initEditMarker(address); 1800 // m.GeoCode({address: $(this).val()}, koch_map.params.postid, address); 1801 // } 1802 1803 1804 koch_map.listenedit = function (address = false) { 1805 console.log("now editing adress " + address); 1806 // hide others 1807 1808 koch_map._initEditMarker(address); 1809 /* 1810 No longer trigger google search from address fields - only textbox above the mao 1811 1812 */
1813 // $("input[name=koch_kontakt_adresse]").off("change.koch_map"); 1814 1815 // $("input[name=koch_kontakt_adresse]").on("change.koch_map", function() { 1816 1817 // var address = $(this).closest(".update_container_koch_kontakt_info").attr('id'); 1818 // console.log("find where we edit", { text: $(this).val(), ele: address}); 1819 1820 // koch_map._initEditMarker(address); 1821 // if ($(this).val()) 1822 // m.GeoCode({address: $(this).val()}, koch_map.params.postid, address); 1823 // else if (!address) 1824 // koch_map.editpostmarker.kg_post.hide(); 1825 // }); 1826 1827 1828 1829 $("input[name=koch_map_kontakt_google_search]").change(function() { 1830 if ($(this).val()) 1831 m.GeoCode({address: $(this).val()}, koch_map.params.postid); 1832 return false; 1833 1834 }); 1835 1836 $("#koch_map_kontakt_google_search_now").click(function() { 1837 1838 $("#koch_map_kontakt_google_search").trigger('change'); 1839 return false; 1840 }); 1841 1842 $("#koch_map_kontakt_google_search_title").click(function() { 1843 $("#koch_map_kontakt_google_search").val($('input[name="post_title"]').val()); 1844 $("#koch_map_kontakt_google_search").trigger('change'); 1845 return false; 1846 }); 1847 }; 1848 1849 1850 koch_map._searchNearby = function (types) { 1851 if (!Array.isArray(types) || !types.length) 1852 return false; 1853 var admintypes = { 1854 "street_number" : {radius: 100, zoom: 18 }, 1855 "street_address" : {radius: 200, zoom: 13 }, 1856 "sublocality_level_1": {radius: 2000, zoom: 10 }, 1857 "route": {radius: 1000, zoom: 11 }, 1858 "locality": {radius: 2000, zoom: 10 } 1859 }; 1860 return (typeof admintypes[types[0]] == 'undefined' ? {radius: false, zoom: false } : admintypes[types[0]] ); 1861 } 1862 1863 koch_map._searchNearbyhasTypes = function (types) { 1864 var hastypes = []; 1865 if (!Array.isArray(types) || !types.length) 1866 return hastypes; 1867 var looktypes = {"food" : true, "restaurant": true}; 1868 types.forEach( function (el) { 1869 if (looktypes[el]) 1870 hastypes.push(el); 1871 1872 }) 1873 return (hastypes); 1874 } 1875 1876 koch_map.GeoCode = function(param, postid = false, postpos = false, searchplace = false) { 1877 var m = koch_map.editpostmarker; 1878 if (!searchplace) { 1879 koch_map.geocoder.geocode(param, function(result,status){ 1880 // console.log("geocoder: ", {param: param, result: result, status: status}); 1881 if (status === 'OK') { 1882 koch_map.editpostmarker.setMap(koch_map.map); 1883 koch_map.editpostmarker.kg_post.show(); 1884 koch_map.editpostmarker.setOptions({draggable: true}); 1885 koch_map.editpostmarker.kg_post.geoCodeplaceInfo = {address: {name: result[0].formatted_address, data: result[0]}}; 1886 koch_map.editpostmarker.kg_post.label = result[0].formatted_address; 1887 koch_map.editpostmarker.kg_post.select(); 1888 var nearby = koch_map._searchNearby(result[0].address_components[0].types); 1889 if (!koch_map.editpostmarker_wasdragged) { 1890 koch_map.editpostmarker.kg_post.geoCodeplaceInfo.location = {position: result[0].geometry.location.toJSON(), selected: false, string: koch_map.ddToDms(result[0].geometry.location.toJSON())}; 1891 koch_map.editpostmarker.getMap().setCenter(result[0].geometry.location); 1892 koch_map.editpostmarker.getMap().fitBounds(result[0].geometry.viewport); 1893 if (nearby.zomm) 1894 koch_map.maxZoom(nearby.zoom); 1895 else 1896 koch_map.maxZoom(); 1897 koch_map.editpostmarker.setPosition(result[0].geometry.location); 1898 1899 } else 1900 koch_map.editpostmarker.kg_post.geoCodeplaceInfo.location = {position: koch_map.editpostmarker.getPosition().toJSON(), selected: false, string: koch_map.ddToDms(koch_map.editpostmarker.getPosition().toJSON())}; 1901 1902 koch_map.editpostmarker.openInfoWindow(); 1903 1904 1905 var getplacedetails = new Array(); 1906 if (koch_map._searchNearbyhasTypes(result[0].types).length) 1907 getplacedetails.push(result[0]); 1908 if (result[0].place_id || nearby.radius){ 1909 1910 if (param.location || nearby.radius){ 1911 if (!koch_map.nearbysearchtypes) 1912 koch_map.nearbysearchtypes = []; 1913 1914 var sparam = { 1915 location: param.location ? param.location : result[0].geometry.location.toJSON(), 1916 1917 1918 // types: koch_map.nearbysearchtypes, 1919 radius: nearby.radius ? nearby.radius : 100, 1920 }; 1921 // console.log("nearby search:", result[0].address_components[0].types.join(",") ); 1922 koch_maps.postedit.placesservice.nearbySearch( sparam , 1923 function (result, status) { 1924 // console.log("nearby search", {status: status, result: result}); 1925 if (status === 'OK') { 1926 koch_map.editpostmarker.kg_post.geoCodeplaceInfo.place = new Array(); 1927 koch_map.editpostmarker.kg_post.label = result[0].name + "/" + koch_map.editpostmarker.kg_post.label; 1928 var pos = 0; 1929 // console.log ('include', getplacedetails); 1930 getplacedetails = getplacedetails.concat(result); 1931 // console.log("getplace details", {status: status, getplacedetails: getplacedetails}); 1932 var placeIDs = new Object;
1933 getplacedetails.forEach(function(el) { 1934 1935 if (koch_map._searchNearbyhasTypes(el.types).length && pos < 10 && !placeIDs[el.place_id]) { 1936 placeIDs[el.place_id] = true; 1937 koch_maps.postedit.placesservice.getDetails({placeId: el.place_id , fields: ['name', 'rating', 'formatted_phone_number', 'formatted_address', 'opening_hours', 'type', 'international_phone_number','website'] }, 1938 function (result, status) { 1939 // console.log({status: status, result: result}); 1940 if (status === 'OK') { 1941 1942 koch_map.editpostmarker.kg_post.geoCodeplaceInfo.place.push({ 1943 name: result.name, 1944 address: result.formatted_address, 1945 phone: result.international_phone_number, 1946 types: result.types, 1947 website: result.website, 1948 data: result, location: 1949 el.geometry.location.toJSON() 1950 }); 1951 koch_map.editpostmarker._set_infocontent(); 1952 if (pos == 0) 1953 koch_map.editpostmarker.kg_post.label = result.name + "/" + koch_map.editpostmarker.kg_post.label; 1954 } 1955 }); 1956 pos++; 1957 1958 1959 } 1960 // else 1961 // console.log("skip place: ", {pos: pos, name: el.name, types: el.types.join(","), hasttypes: koch_map._searchNearbyhasTypes(el.types)}); 1962 1963 1964 1965 }); 1966 1967 } 1968 1969 1970 }); 1971 } else { 1972 console.log("get place details place (location types):", result[0].address_components[0].types.join(",")); 1973 1974 koch_maps.postedit.placesservice.getDetails({placeId: result[0].place_id , fields: ['name', 'rating', 'formatted_phone_number', 'formatted_address', 'opening_hours', 'type', 'international_phone_number','website'] }, 1975 function (result, status) { 1976 1977 console.log({status: status, result: result}); 1978 if (status === 'OK') { 1979 koch_map.editpostmarker.kg_post.label = result.name + "/" + koch_map.editpostmarker.kg_post.label; 1980 koch_map.editpostmarker.kg_post.geoCodeplaceInfo.place = 1981 [ 1982 {name: result.name, 1983 address: result.formatted_address, 1984 phone: result.international_phone_number, 1985 types: result.types, 1986 website: 1987 result.website, 1988 data: result 1989 }]; 1990 koch_map.editpostmarker._set_infocontent(); 1991 } 1992 }); 1993 } 1994 } 1995 else 1996 console.log("no nearby search, no place:", result[0].address_components[0].types.join(",") ); 1997 koch_map.editpostmarker_wasdragged = false; 1998 if (!koch_map.editpostmarker_listener) 1999 koch_map.editpostmarker_listener = koch_map.editpostmarker.addListener('dragend', function() { 2000 console.log('get new position') 2001 koch_map.editpostmarker_wasdragged = true; 2002 koch_map.GeoCode({location: koch_map.editpostmarker.getPosition().toJSON()}); 2003 2004 }); 2005 2006 } 2007 else if (koch_map.editpostmarker && koch_map.editpostmarker.kg_post && koch_map.editpostmarker.kg_post.id === 'new'){ 2008 koch_map.editpostmarker.kg_post.hide(); 2009 2010 2011 } 2012 2013 2014 }); 2015 } 2016 else { 2017 koch_maps.postedit.placesservice.findPlaceFromQuery({ 2018 query: param.address, 2019 // fields: ['name', 'rating', 'formatted_phone_number', 'formatted_address', 'opening_hours', 'type', 'international_phone_number','website' ] 2020 }, function(results, status) { 2021 console.log({status: status, result: result}); 2022 result.forEach(function(el) { 2023 console.log({name: el.name, vicinity: el.vicinity}); 2024 }); 2025 }); 2026 } 2027 } 2028 2029 koch_map.listenedit(); 2030 2031 2032 2033 2034 } 2035 if (koch_map.params.postedit) 2036 koch_map.selectAll(false); 2037 koch_map._init_firstViewport(); 2038 var evt = $.Event('koch_map_loaded'); 2039 evt.koch_map = koch_map; 2040 $(window).trigger(evt); 2041 google.maps.event.trigger(koch_map, 'koch_map_loaded', koch_map); 2042 2043 } 2044 } 2045 2046 koch_map.private(); 2047 koch_map.public(); 2048 2049 /* init map */ 2050 if (koch_map.params.regionedit && koch_map.params.region && koch_map.params.regions) { 2051 var m = koch_map; 2052 $("#click_tax_setall_"+koch_map.id).click(function() { 2053 m.setTaxonomies(m.getPostID(m.getPlacesInMarkers()), [{taxonomy: m.params.regions, term: m.params.region, set: true}], {taxonomy: m.params.regions, term: m.params.region}); 2054 2055 }); 2056 $("#click_tax_clearall_"+koch_map.id).click(function() { 2057 m.setTaxonomies(m.getPostID(m.getPlacesInMarkers()), [{taxonomy: m.params.regions, term: m.params.region, set: false}], {taxonomy: m.params.regions, term: m.params.region}); 2058 2059 }); 2060 } 2061 if (koch_map.params.postedit) { 2062 // initalize map size depending on current width 2063 // and add resize handle 2064 $('#' + koch_map.id).height($('#' + koch_map.id).width() / 4 * 2); 2065 2066 2067 } 2068 $('#' + koch_map.id).resizable({ 2069 handles: 's', 2070 stop: function(event, ui) { 2071 $(this).css("width", ''); 2072 } 2073 }); 2074 google.maps.event.addListenerOnce(koch_map, 'koch_map_loaded', function(koch_map) { 2075 // fallback if type not defined 2076 if (!koch_map.map.mapTypes[koch_map.map.getMapTypeId()]) { 2077 koch_map.map.setOptions({mapTypeControlOptions:{mapTypeIds: ['roadmap', 'satellite']}}); 2078 koch_map.map.setMapTypeId('roadmap'); 2079 2080 } 2081 // console.log('koch_map_loaded:\nid: '+koch_map.id, koch_map); 2082 }); 2083 2084 2085 if (koch_map.params.jsondata) { 2086 koch_map.data = qparams; 2087 koch_map.setMarkers( autobound); 2088 setTimeout (function() { 2089 koch_map._finishLoad();}, 2000); 2090 2091 } 2092 else if (typeof koch_map.params.content !== 'undefined') { 2093 koch_map._set_ajax_load(koch_map.id); 2094 // $.getJSON('/places/places.json' + qparams, function (data) { 2095 $.getJSON(koch_ajax.ajaxurl + qparams + "&action=koch_get_places", function (data) { 2096 // koch_maps[mapid] = new Object(); 2097 koch_map.data = data; 2098 koch_map.setMarkers( autobound); 2099 koch_map._finishLoad(); 2100 }); 2101 } 2102 else { 2103 koch_map._finishLoad(); 2104 } 2105 2106 if (koch_map.params.loglatlng) 2107 koch_map._log_latlng();
2108 if ((koch_map.params.showbounds || koch_map.params.loglatlng) && typeof koch_map.region !== 'undefined' && typeof koch_map.region.bounds === 'object') 2109 koch_map.showRegionBounds(koch_map.region.bounds); 2110 2111 } 2112 2113 2114 2115/* end koch_init_map */ 2116 2117 2118 2119 function koch_zoom_region(koch_map, region) { 2120 koch_map.zoomRegion(region); 2121 } 2122 2123 function koch_select_markers(koch_map, tax, term) { 2124 koch_map.selectMarkers(tax, term); 2125 } 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 jQuery(window).on('koch_map_latlngbounds', function (e) { 2137 2138 if (e.koch_map.params.loglatlng) { 2139 2140 console.log('koch_map_latlngbounds:\nid: ', e); 2141 2142 } 2143 }); 2144 2145 2146 Number.prototype.toRad = function() { 2147 return this * Math.PI / 180; 2148 } 2149 2150 Number.prototype.toDeg = function() { 2151 return this * 180 / Math.PI; 2152 } 2153 2154 function koch_destinationPoint (latlng, brng, dist, random = false) { 2155 if (random) { 2156 dist = Math.floor((Math.random()*(dist * 100 -brng * 100 +1)+brng * 100)) / 100; 2157 brng = Math.floor(Math.random() * 360 * 100)/100; 2158 2159 } 2160 dist = dist / 6371; 2161 brng = brng.toRad(); 2162 2163 2164 var lat1 = latlng.lat.toRad(), lon1 = latlng.lng.toRad(); 2165 2166 var lat2 = Math.asin(Math.sin(lat1) * Math.cos(dist) + 2167 Math.cos(lat1) * Math.sin(dist) * Math.cos(brng)); 2168 2169 var lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(dist) * 2170 Math.cos(lat1), 2171 Math.cos(dist) - Math.sin(lat1) * 2172 Math.sin(lat2)); 2173 2174 if (isNaN(lat2) || isNaN(lon2)) return null; 2175 2176 return {lat: lat2.toDeg(), lng: lon2.toDeg()}; 2177 } 2178 2179
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.