Commit f8fc45a1 authored by Tobias Jeger's avatar Tobias Jeger

ESSENTIALS-1017 Reintegrate 'bugfix/ESSENTIALS-1017' into master

parents f4e8dea6 5287dc7a
<#include "../include/imports.ftl">
<#-- @ftlvariable name="componentId" type="java.lang.String" -->
<#-- @ftlvariable name="cparam" type="org.onehippo.cms7.essentials.components.info.EssentialsGoogleMapsComponentInfo" -->
<#if cparam.apiKey?has_content>
<#assign mapsUrl = "https://maps.googleapis.com/maps/api/js?key=${cparam.apiKey?html}"/>
<#else>
<#assign mapsUrl = "https://maps.googleapis.com/maps/api/js"/>
</#if>
<@hst.headContribution keyHint="api" category="htmlHead">
<script type="text/javascript" src="${mapsUrl}"></script>
<div id="map-canvas-${componentId}" style="width: ${cparam.width}px; height: ${cparam.height}px;"></div>
<@hst.headContribution category="htmlBodyEnd">
<script type="text/javascript">
(function(win) {
var he, gm;
if (!win.HippoEssentials) {
win.HippoEssentials = {};
}
he = win.HippoEssentials;
if (!he.GoogleMaps) {
he.GoogleMaps = {
queue: []
};
}
gm = he.GoogleMaps;
gm.queue.push(function() {
gm.render('map-canvas-${componentId}', '${cparam.address?html}', ${cparam.longitude}, ${cparam.latitude}, ${cparam.zoomFactor}, '${cparam.mapType}');
});
})(window);
</script>
</@hst.headContribution>
<@hst.headContribution keyHint="maps" category="htmlHead">
<@hst.webfile path="/js/essentials-google-maps.js" var="customMapsJSUrl" />
<script type="text/javascript" src="${customMapsJSUrl}"></script>
<@hst.headContribution keyHint="essentials-google-maps" category="htmlBodyEnd">
<@hst.webfile path="/js/essentials-google-maps.js" var="essentialsGoogleMapsJs" />
<script type="text/javascript" src="${essentialsGoogleMapsJs}"></script>
</@hst.headContribution>
<@hst.headContribution keyHint="initializeGoogleMaps" category="htmlBodyEnd">
<script type="text/javascript">
initializeGoogleMaps("${cparam.address?html}", ${cparam.longitude}, ${cparam.latitude}, ${cparam.zoomFactor}, "${cparam.mapType}");
</script>
<@hst.headContribution keyHint="google-maps-api" category="htmlBodyEnd">
<#if cparam.apiKey?has_content>
<#assign mapsUrl = "https://maps.googleapis.com/maps/api/js?key=${cparam.apiKey?html}&callback=HippoEssentials.GoogleMaps.init"/>
<#else>
<#assign mapsUrl = "https://maps.googleapis.com/maps/api/js?callback=HippoEssentials.GoogleMaps.init"/>
</#if>
<script type="text/javascript" src="${mapsUrl}" async="async" defer="defer"></script>
</@hst.headContribution>
<#if cmsrequest>
<script type="text/javascript">
initializeGoogleMaps("${cparam.address?html}", ${cparam.longitude}, ${cparam.latitude}, ${cparam.zoomFactor}, "${cparam.mapType}");
</script>
<#if editMode>
<script type="text/javascript">
if (window.HippoEssentials && window.HippoEssentials.GoogleMaps) {
window.HippoEssentials.GoogleMaps.render('map-canvas-${componentId}', '${cparam.address?html}', ${cparam.longitude}, ${cparam.latitude}, ${cparam.zoomFactor}, '${cparam.mapType}');
}
</script>
</#if>
<div id="map-canvas" style="width: ${cparam.width}px; height: ${cparam.height}px;"></div>
\ No newline at end of file
"use strict";
/*
* Copyright 2015 Hippo B.V. (http://www.onehippo.com)
* Copyright 2015-2016 Hippo B.V. (http://www.onehippo.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -14,50 +13,90 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var myGoogleMap;
function getMapType(mapType) {
if (mapType=="ROADMAP") {
return google.maps.MapTypeId.ROADMAP;
(function () {
'use strict';
function getMapType(mapType) {
if (mapType === 'ROADMAP') {
return google.maps.MapTypeId.ROADMAP;
}
else if (mapType === 'SATELLITE') {
return google.maps.MapTypeId.SATELLITE;
}
else if (mapType === 'TERRAIN') {
return google.maps.MapTypeId.TERRAIN;
}
else {
return google.maps.MapTypeId.HYBRID;
}
}
else if (mapType=="SATELLITE") {
return google.maps.MapTypeId.SATELLITE;
function geoCodeAddress(address, map) {
var myGeoCoder = new google.maps.Geocoder();
myGeoCoder.geocode({
address: address
},
function (results, status) {
if (status === google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
});
}
else if (mapType=="TERRAIN") {
return google.maps.MapTypeId.TERRAIN;
var he, gm;
if (!window.HippoEssentials) {
window.HippoEssentials = {};
}
else {
return google.maps.MapTypeId.HYBRID;
he = window.HippoEssentials;
if (!he.GoogleMaps) {
he.GoogleMaps = {
queue: []
};
}
}
gm = he.GoogleMaps;
function initializeGoogleMaps(address, longitude, latitude, zoomFactor, mapType) {
var latlng = new google.maps.LatLng(0, 0);
if (latitude != "" || longitude != "") {
latlng = new google.maps.LatLng(latitude, longitude);
if (!gm.init) {
gm.init = function() {
for (var i = 0; i < gm.queue.length; i++) {
gm.queue[i]();
}
gm.queue = [];
};
}
var mapOptions = {
center: latlng,
zoom: zoomFactor,
mapTypeId: getMapType(mapType)
};
myGoogleMap = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
if (address != "") {
geoCodeAddress(address);
if (!gm.render) {
gm.render = function (elementId, address, longitude, latitude, zoomFactor, mapType) {
if (!google) {
if (window.console) {
console.warn('Could not find Google Maps API, please make sure it is loaded correctly before creating a ' +
'new Google Map instance. This is typically done by inserting ' +
'<script src="https://maps.googleapis.com/maps/api/js"></script> into the page.');
}
return;
}
var latlng;
if (latitude !== '' || longitude !== '') {
latlng = new google.maps.LatLng(latitude, longitude);
} else {
latlng = new google.maps.LatLng(0, 0);
}
var el = document.getElementById(elementId);
var mapOptions = {
center: latlng,
zoom: zoomFactor,
mapTypeId: getMapType(mapType)
};
var map = new google.maps.Map(el, mapOptions);
if (address !== '') {
geoCodeAddress(address, map);
}
};
}
}
function geoCodeAddress(address) {
var myGeoCoder = new google.maps.Geocoder();
myGeoCoder.geocode( {'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
myGoogleMap.setCenter(results[0].geometry.location);
new google.maps.Marker({
map: myGoogleMap,
position: results[0].geometry.location
});
} else {
// geocode failed, do nothing
}
});
}
})();
<%@ include file="/WEB-INF/jsp/include/imports.jsp" %>
<%--@elvariable id="componentId" type="java.lang.String"--%>
<%--@elvariable id="cparam" type="org.onehippo.cms7.essentials.components.info.EssentialsGoogleMapsComponentInfo"--%>
<c:choose>
<c:when test="${not empty requestScope.cparam.apiKey}">
<c:set var="mapsUrl">https://maps.googleapis.com/maps/api/js?key=${fn:escapeXml(requestScope.cparam.apiKey)}</c:set>
</c:when>
<c:otherwise>
<c:set var="mapsUrl">https://maps.googleapis.com/maps/api/js</c:set>
</c:otherwise>
</c:choose>
<hst:headContribution keyHint="api" category="htmlHead">
<script type="text/javascript" src="${mapsUrl}"></script>
<div id="map-canvas-${componentId}" style="width: ${requestScope.cparam.width}px; height: ${requestScope.cparam.height}px;"></div>
<hst:headContribution category="htmlBodyEnd">
<script type="text/javascript">
(function(win) {
var he, gm;
if (!win.HippoEssentials) {
win.HippoEssentials = {};
}
he = win.HippoEssentials;
if (!he.GoogleMaps) {
he.GoogleMaps = {
queue: []
};
}
gm = he.GoogleMaps;
gm.queue.push(function() {
gm.render('map-canvas-${componentId}', '${fn:escapeXml(requestScope.cparam.address)}', ${requestScope.cparam.longitude}, ${requestScope.cparam.latitude}, ${requestScope.cparam.zoomFactor}, '${requestScope.cparam.mapType}');
});
})(window);
</script>
</hst:headContribution>
<hst:headContribution keyHint="maps" category="htmlHead">
<hst:webfile path="/js/essentials-google-maps.js" var="customMapsJSUrl" />
<script type="text/javascript" src="${customMapsJSUrl}"></script>
<hst:headContribution keyHint="essentials-google-maps" category="htmlBodyEnd">
<hst:webfile path="/js/essentials-google-maps.js" var="essentialsGoogleMapsJs" />
<script type="text/javascript" src="${essentialsGoogleMapsJs}"></script>
</hst:headContribution>
<hst:headContribution keyHint="initializeGoogleMaps" category="htmlBodyEnd">
<script type="text/javascript">
initializeGoogleMaps("${fn:escapeXml(requestScope.cparam.address)}", ${requestScope.cparam.longitude}, ${requestScope.cparam.latitude}, ${requestScope.cparam.zoomFactor}, "${requestScope.cparam.mapType}");
</script>
<hst:headContribution keyHint="google-maps-api" category="htmlBodyEnd">
<c:choose>
<c:when test="${not empty requestScope.cparam.apiKey}">
<c:set var="mapsUrl">https://maps.googleapis.com/maps/api/js?key=${fn:escapeXml(requestScope.cparam.apiKey)}&callback=HippoEssentials.GoogleMaps.init</c:set>
</c:when>
<c:otherwise>
<c:set var="mapsUrl">https://maps.googleapis.com/maps/api/js?callback=HippoEssentials.GoogleMaps.init</c:set>
</c:otherwise>
</c:choose>
<script type="text/javascript" src="${mapsUrl}" async="async" defer="defer"></script>
</hst:headContribution>
<c:if test="${requestScope.cmsrequest}">
<script type="text/javascript">
initializeGoogleMaps("${fn:escapeXml(requestScope.cparam.address)}", ${requestScope.cparam.longitude}, ${requestScope.cparam.latitude}, ${requestScope.cparam.zoomFactor}, "${requestScope.cparam.mapType}");
</script>
<c:if test="${editMode}">
<script type="text/javascript">
if (window.HippoEssentials && window.HippoEssentials.GoogleMaps) {
window.HippoEssentials.GoogleMaps.render('map-canvas-${componentId}', '${fn:escapeXml(requestScope.cparam.address)}', ${requestScope.cparam.longitude}, ${requestScope.cparam.latitude}, ${requestScope.cparam.zoomFactor}, '${requestScope.cparam.mapType}');
}
</script>
</c:if>
<div id="map-canvas" style="width: ${requestScope.cparam.width}px; height: ${requestScope.cparam.height}px;"></div>
\ No newline at end of file
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