Improved: Allow to pass a Google API key for geolocation
Better way to handle a missing Google API key
@@ -35,15 +35,20 @@ under the License.
</#if>
<#-- ================================= Google Maps Init ======================================-->
- <#assign googleApiKey = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("general", "googleApiKey", delegator)>
- <#if geoChart.dataSourceId?has_content && googleApiKey?has_content>
+ <#if geoChart.dataSourceId?has_content>
<#if "GOOGLE" == geoChart.dataSourceId?substring(geoChart.dataSourceId?length-6 , geoChart.dataSourceId?length)>
+ <#assign googleApiKey = Static["org.apache.ofbiz.entity.util.EntityUtilProperties"].getPropertyValue("general", "googleApiKey", delegator)>
<div id="${id}"
style="border:1px solid #979797; background-color:#e5e3df; width:${geoChart.width}; height:${geoChart.height}; margin:2em auto;">
<div style="padding:1em; color:gray;">${uiLabelMap.CommonLoading}</div>
</div>
+ <#if !googleApiKey?has_content>
+ <h2>${uiLabelMap.CommonNoGoogleAPIkeyAvailable}</h2>
+ <script src="https://maps.googleapis.com/maps/api/js" type="application/javascript"></script>
+ <#else>
<script src="https://maps.googleapis.com/maps/api/js?key=googleApiKey" type="application/javascript"></script>
</#if>
+ </#if>
<#-- ========================== Here we go with different types of maps renderer ===========================-->
<#if "GEOPT_GOOGLE" == geoChart.dataSourceId>
<script type="application/javascript">
@@ -181,7 +186,3 @@ under the License.
<#else>
<h2>${uiLabelMap.CommonNoGeolocationAvailable}</h2>
</#if>
-
-<#if !googleApiKey?has_content>
- <h2>${uiLabelMap.CommonNoGoogleAPIkeyAvailable}</h2>
-</#if>
