Commit 32572456 authored by Matija Obreza's avatar Matija Obreza
Browse files

Google Maps V3

parent a8f9ed6b
......@@ -145,14 +145,25 @@
<c:if test="${accessionEnvironment ne null}">
<c:if test="${accessionEnvironment.latitude ne null}">
<tr>
<td><spring:message code="accession.geolocation" /></td>
<td>${accessionEnvironment.latitude}, ${accessionEnvironment.longitude}</td>
</tr>
</c:if>
<c:if test="${accessionEnvironment.altitude ne null}">
<tr>
<td><spring:message code="accession.altitude" /></td>
<td>${accessionEnvironment.altitude}<span class="uom">m</span></td>
</tr>
</c:if>
<c:if test="${accessionEnvironment.latitude ne null}">
<tr>
<td colspan="2">
<div id="accessionMap" style="width: 100%; height: 300px">Loading Google Maps...</div>
</td>
</tr>
</c:if>
</c:if>
......@@ -230,5 +241,12 @@
</ul>
</c:if>
<c:if test="${accessionEnvironment ne null and accessionEnvironment.latitude ne null}">
<script type="text/javascript">
jQuery(document).ready(function() {
var accessionMap=GoogleMaps.map($("#accessionMap"), { center: new GoogleMaps.LatLng(${accessionEnvironment.latitude}, ${accessionEnvironment.longitude}), markerTitle: "<spring:escapeBody javaScriptEscape="true">${accession.accessionName}, ${accession.instituteCode}</spring:escapeBody>" });
});
</script>
</c:if>
</body>
</html>
\ No newline at end of file
/**
* Copyright 2013 Global Crop Diversity Trust
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
GoogleMaps = {
LatLng: function(lat, lng) {
this.lat=lat;
this.lng=lng;
this.noWrap=true;
}
};
GoogleMaps = {
LatLng: GoogleMaps.LatLng,
loaded: false,
maps: [],
loadedMaps: [],
googleMaps: [],
defaultOptions: {
zoom: 5,
center: new GoogleMaps.LatLng(0, 0),
mapTypeId: "terrain"
},
map: function(doms, mapOptions) {
var mapOpt = {
zoom: mapOptions.zoom || this.defaultOptions.zoom,
center: mapOptions.center || this.defaultOptions.center,
mapTypeId: mapOptions.mapTypeId || this.defaultOptions.mapTypeId,
markerTitle: mapOptions.markerTitle || null
};
doms.each(function(idx,el) {
if ($.inArray(el, this.loadedMaps) < 0) {
el.googleMapsOptions = mapOpt;
GoogleMaps.maps.push(el);
}
});
this.loadGoogleMaps();
},
loadGoogleMaps: function() {
if (! this.loaded) {
this.loaded = true;
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&&callback=GoogleMaps.onLoad';
document.body.appendChild(script);
} else {
this.onLoad();
}
},
onLoad: function() {
var el=this.maps.shift();
while (el != null) {
var mapOptions=el.googleMapsOptions;
el.googleMapsOptions=null;
var pos=mapOptions.center;
mapOptions.center=new google.maps.LatLng(pos.lat, pos.lng, pos.noWrap);
var map = new google.maps.Map(el, mapOptions);
this.googleMaps.push(map);
// debugger;
var marker = new google.maps.Marker({
position: mapOptions.center,
map: map,
title: mapOptions.markerTitle
});
this.loadedMaps.push(el);
el=this.maps.shift();
}
}
};
jQuery(document).ready(function() {
$("body").on("click", ".acn .sel[x-aid]", function(event) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment