version fixes
[civicrm-core.git] / templates / CRM / Contact / Form / Task / Map / OpenStreetMaps.tpl
CommitLineData
6a488035
TO
1{*
2 +--------------------------------------------------------------------+
2c4c49ca 3 | CiviCRM version 4.7 |
6a488035 4 +--------------------------------------------------------------------+
e7112fa7 5 | Copyright CiviCRM LLC (c) 2004-2015 |
6a488035
TO
6 +--------------------------------------------------------------------+
7 | This file is a part of CiviCRM. |
8 | |
9 | CiviCRM is free software; you can copy, modify, and distribute it |
10 | under the terms of the GNU Affero General Public License |
11 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
12 | |
13 | CiviCRM is distributed in the hope that it will be useful, but |
14 | WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
16 | See the GNU Affero General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU Affero General Public |
19 | License and the CiviCRM Licensing Exception along |
20 | with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
25*}
26{if $showDirectly}
27 {assign var=height value="350px"}
28 {assign var=width value="425px"}
31037a42 29{else}
6a488035
TO
30 {assign var=height value="600px"}
31 {assign var=width value="100%"}
32{/if}
31037a42 33{assign var=defaultZoom value=12}
6a488035 34{literal}
7a6c86ea 35<script src="https://cdnjs.cloudflare.com/ajax/libs/openlayers/2.13.1/OpenLayers.js" type="text/javascript"></script>
6a488035
TO
36<script type="text/javascript">
37 var popup = new Popup();
38
39 function Popup() {
40 this.popup = null;
41 this.active = false;
42 }
43
44 Popup.prototype.create = function(evt) {
45 this.destroy();
46
47 this.popup = new OpenLayers.Popup.FramedCloud
48 (
49 "data",
50 evt.object.customLonLat,
51 new OpenLayers.Size(200,200),
52 evt.object.customContent,
53 null,
54 true,
55 function() {
56 this.toggle();
57 }
58 );
59 evt.object.customMarkers.map.addPopup(this.popup);
60 OpenLayers.Event.stop(evt);
61 }
62
63 Popup.prototype.destroy = function() {
64 if(this.active) {
65 this.popup.destroy();
66 this.popup = null;
67 }
68 }
69
70 function initMap() {
71 var map = new OpenLayers.Map("osm_map");
7a6c86ea
CD
72 map.addLayer(new OpenLayers.Layer.OSM("MapQuest OSM", [
73 "https://otile1-s.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg",
74 "https://otile2-s.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg",
75 "https://otile3-s.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg",
76 "https://otile4-s.mqcdn.com/tiles/1.0.0/map/${z}/${x}/${y}.jpg",
77 ], {
78 attribution: "<p>Tiles Courtesy of <a href='http://www.mapquest.com/' target='_blank'>MapQuest</a>. Data &copy; <a href='http://www.openstreetmap.org/' target='_blank'>OpenStreetMap</a> contributors.</p>"
79 }));
6a488035
TO
80
81 var lonLat = new OpenLayers.LonLat(
31037a42 82 {/literal}{$center.lng}{literal},
6a488035
TO
83 {/literal}{$center.lat}{literal}).transform(
84 new OpenLayers.Projection("EPSG:4326"),
85 map.getProjectionObject()
86 );
87
88 map.setCenter(lonLat, {/literal}{$defaultZoom}{literal});
31037a42 89
6a488035
TO
90 setMapOptions(map);
91 }
31037a42 92
6a488035
TO
93 function setMapOptions(map) {
94 markers = new OpenLayers.Layer.Markers("Markers");
95 map.addLayer(markers);
96
97 bounds = map.calculateBounds();
98 {/literal}
99 {foreach from=$locations item=location}
100 {if $location.url and ! $profileGID}
101 {literal}
102 var data = "{/literal}<a href='{$location.url}'>{$location.displayName}</a><br />{if !$skipLocationType}{$location.location_type}<br />{/if}{$location.address}";
103 {else}
104 {capture assign="profileURL"}{crmURL p='civicrm/profile/view' q="reset=1&id=`$location.contactID`&gid=$profileGID"}{/capture}
105 {literal}
106 var data = "{/literal}<a href='{$profileURL}'>{$location.displayName}</a><br />{if !$skipLocationType}{$location.location_type}<br />{/if}{$location.address}";
107 {/if}
108 {literal}
109 var address = "{/literal}{$location.address}{literal}";
110 {/literal}
111 {if $location.lat}
112 point = new OpenLayers.LonLat(
31037a42 113 {$location.lng},
6a488035
TO
114 {$location.lat}).transform(
115 new OpenLayers.Projection("EPSG:4326"),
116 map.getProjectionObject()
117 );
118 {if $location.image && ( $location.marker_class neq 'Event' ) }
119 var image = '{$location.image}';
120 {else}
121 {if $location.marker_class eq 'Individual'}
122 var image = "{$config->resourceBase}i/contact_ind.gif";
123 {/if}
124 {if $location.marker_class eq 'Household'}
125 var image = "{$config->resourceBase}i/contact_house.png";
126 {/if}
127 {if $location.marker_class eq 'Organization' || $location.marker_class eq 'Event'}
128 var image = "{$config->resourceBase}i/contact_org.gif";
129 {/if}
130 {/if}
131 {literal}
132 createMarker(map, markers, point, data, image);
133 bounds.extend(point);
134 {/literal}
135 {/if}
136 {/foreach}
137 map.setCenter(bounds.getCenterLonLat());
31037a42 138 {if count($locations) gt 1}
6a488035
TO
139 map.zoomToExtent(bounds);
140 {elseif $location.marker_class eq 'Event' || $location.marker_class eq 'Individual'|| $location.marker_class eq 'Household' || $location.marker_class eq 'Organization' }
141 map.zoomTo({$defaultZoom});
31037a42
EM
142 {else}
143 map.zoomTo({$defaultZoom});
6a488035
TO
144 {/if}
145 {literal}
146 //attribution sits awkwardly high, move it down
147 jQuery('.olControlAttribution').css('bottom','0px');
148 }
149
150 function createMarker(map, markers, point, data, image) {
151 var marker = new OpenLayers.Marker(point);
31037a42 152
6a488035
TO
153 var size = new OpenLayers.Size(20,20);
154 var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
155 marker.icon.size = size;
156 marker.icon.offset = offset;
157 marker.icon.url = image;
158
159 marker.customContent = data;
160 marker.customLonLat = point;
161 marker.customMarkers = markers;
162
163 marker.events.register('mousedown', marker, markerClick);
164
165 markers.addMarker(marker);
166 }
167
168 function markerClick(evt) {
169 popup.create(evt);
170 }
171
172 if (window.addEventListener) {
173 window.addEventListener("load", initMap, false);
174 } else if (window.attachEvent) {
175 document.attachEvent("onreadystatechange", initMap);
176 }
177
178 function gpopUp() {
179 var from = document.getElementById('from').value;
31037a42 180 var to = document.getElementById('to').value;
6a488035
TO
181 var URL = "http://maps.google.com/maps?saddr=" + from + "&daddr=" + to;
182 day = new Date();
183 id = day.getTime();
184 eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=780,height=640,left = 202,top = 100');");
185 }
186</script>
187{/literal}
188<div id="osm_map" style="width: {$width}; height: {$height}"></div>