Files
ofbiz-framework/framework/common/webcommon/includes/geolocation.ftl
T
Jacques Le Roux c28edba6d8 This fixes the geolocation in OFBiz, for both Google Maps and OpenLayers. It seems few changes, it took me more time than I thought. I hope this will last few years again, and it should be easier to maintain now.
What I did:
Upgraded from Google Maps API 2 to 3, which also means removing the keys in general.properties. They are no longer needed in API-3 (at least for our demo and local test uses), one worry less!
Refactored Google Maps code in geolocation.ftl: put more things in common,  simplified code (the API-3 is better from this POV).

For OpenLayers, due to most browsers now rejecting mixed content (HTTP vs HTTPS), I had to follow their advice and put OpenLayers-2.13.1.js + images and theme(finally not used) in the framework. Not a big deal in term of size but again one more lib to worry about. Anyway geolocation is not vital for OFBiz. I have also added a zoom and navigation widget in maps. Note that IE warns about mixed content, but you can bypass it.

While working on editGeoLocation (in Party) I noticed it does not update the elevation. I found it was possible http://www.daftlogic.com/sandbox-google-maps-find-altitude.htm but I did not implement it, lack of time...
Also I got once a NPE in CallSimpleMapProcessor (when using editGeoLocation) but was unable to reproduce (w/o changes before and after)

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1554536 13f79535-47bb-0310-9956-ffa450edef68
2013-12-31 15:22:21 +00:00

144 lines
6.8 KiB
Plaintext

<#--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<#if geoChart?has_content>
<#-- ================================= Golbal Init ======================================-->
<#if geoChart.id?has_content>
<#assign id = geoChart.id>
<#else>
<#assign id = "map_canvas">
</#if>
<#if geoChart.center?has_content>
<#assign center = geoChart.center>
<#assign zoom = geoChart.center.zoom>
<#elseif geoChart.points?has_content>
<#assign center = geoChart.points[0]>
<#assign zoom = 15> <#-- 0=World, 19=max zoom in -->
<#else>
<#-- hardcoded in GEOPT_ADDRESS_GOOGLE, simpler -->
</#if>
<#-- ================================= Google Maps Init ======================================-->
<#if geoChart.dataSourceId?has_content>
<#if geoChart.dataSourceId?substring(geoChart.dataSourceId?length-6 , geoChart.dataSourceId?length) == "GOOGLE">
<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>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false" type="text/javascript"></script>
</#if>
<#-- ================================= Here we go with different types of maps renderer ======================================-->
<#if geoChart.dataSourceId == "GEOPT_GOOGLE">
<script type="text/javascript">
function showAllMarkers(map, points) {
if (points.length > 1) {
var latlngbounds = new google.maps.LatLngBounds();
for (var i = 0; i < latlngs.length; i++) {
latlngbounds.extend(latlngs[i]);
}
map.fitBounds(latlngbounds);
}
}
var map = new google.maps.Map(document.getElementById("${id}"),
<#if geoChart.points?has_content>
{ center: new google.maps.LatLng(${center.lat?c}, ${center.lon?c}),
zoom: ${zoom},
mapTypeId: google.maps.MapTypeId.ROADMAP
});
<#list geoChart.points as point>
var marker_${point_index} = new google.maps.Marker({
position: new google.maps.LatLng(${point.lat?c}, ${point.lon?c}),
map: map
});
<#if point.link?has_content>
var infoWindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker_${point_index}, "click", function() {
infoWindow.setContent(("<div style=\"width:210px; padding-right:10px;\"><a href=${point.link.url}>${point.link.label}</a></div>"));
infoWindow.setPosition(marker_${point_index}.getPosition());
infoWindow.open(map);
});
</#if>
</#list>
var latlngs = [
<#list geoChart.points as point>
new google.maps.LatLng(${point.lat?c}, ${point.lon?c})<#if point_has_next>,</#if>
</#list>
];
showAllMarkers(map, latlngs);
</#if>
</script>
<#elseif geoChart.dataSourceId == "GEOPT_YAHOO">
<#elseif geoChart.dataSourceId == "GEOPT_MICROSOFT">
<#elseif geoChart.dataSourceId == "GEOPT_MAPTP">
<#elseif geoChart.dataSourceId == "GEOPT_ADDRESS_GOOGLE">
<script type="text/javascript">
var geocoder = new google.maps.Geocoder();
var map = new google.maps.Map(document.getElementById("${id}"),
{ center: new google.maps.LatLng(38, 15),
zoom: 15, // 0=World, 19=max zoom in
mapTypeId: google.maps.MapTypeId.ROADMAP
});
geocoder.geocode({'address': "${pointAddress}"}, function(result, status) {
if (status != google.maps.GeocoderStatus.OK) {
showErrorAlert("${uiLabelMap.CommonErrorMessage2}","${uiLabelMap.CommonAddressNotFound}");
} else {
var position = result[0].geometry.location;
map.setCenter(position);
map.fitBounds(result[0].geometry.viewport);
var marker = new google.maps.Marker({
position: position,
map: map
});
}
});
</script>
<#elseif geoChart.dataSourceId == "GEOPT_OSM">
<div id="${id}" style="border:1px solid #979797; background-color:#e5e3df; width:${geoChart.width}; height:${geoChart.height}; margin:2em auto;"></div>
<#-- due to https://github.com/openlayers/openlayers/issues/1025 rather use a local version loaded by framework/common/widget/CommonScreens.xml -->
<#-- script src="//www.openlayers.org/api/OpenLayers.js"></script-->
<script type="text/javascript">
map = new OpenLayers.Map("${id}");
map.addLayer(new OpenLayers.Layer.OSM());
var zoom = ${zoom};
var center= new OpenLayers.LonLat(${center.lon?c},${center.lat?c})
.transform(new OpenLayers.Projection("EPSG:4326"), // transform from WGS 1984
map.getProjectionObject() // to Spherical Mercator Projection
);
var markers = new OpenLayers.Layer.Markers("Markers");
map.addLayer(markers);
<#if geoChart.points?has_content>
<#list geoChart.points as point>
markers.addMarker(new OpenLayers.Marker(new OpenLayers.LonLat(${point.lon?c} ,${point.lat?c}).transform(
new OpenLayers.Projection("EPSG:4326"), map.getProjectionObject())));
</#list>
</#if>
map.addControl(new OpenLayers.Control.PanZoomBar());
map.addControl(new OpenLayers.Control.NavToolbar());
map.setCenter(center, zoom);
var newBound = markers.getDataExtent();
map.zoomToExtent(newBound);
</script>
</#if>
</#if>
<#else>
<h2>${uiLabelMap.CommonNoGeolocationAvailable}</h2>
</#if>