net.sf.jasperreports.components.map.imageprovider.MapElementImageProvider Maven / Gradle / Ivy
/*
* JasperReports - Free Java Reporting Library.
* Copyright (C) 2001 - 2023 Cloud Software Group, Inc. All rights reserved.
* http://www.jaspersoft.com
*
* Unless you have purchased a commercial license agreement from Jaspersoft,
* the following license terms apply:
*
* This program is part of JasperReports.
*
* JasperReports is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* JasperReports is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with JasperReports. If not, see .
*/
package net.sf.jasperreports.components.map.imageprovider;
import net.sf.jasperreports.components.map.MapComponent;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRGenericPrintElement;
import net.sf.jasperreports.engine.JasperReportsContext;
import net.sf.jasperreports.engine.type.OnErrorTypeEnum;
import net.sf.jasperreports.engine.util.JRColorUtil;
import net.sf.jasperreports.renderers.Renderable;
import net.sf.jasperreports.renderers.util.RendererUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.awt.Color;
import java.util.List;
import java.util.Map;
/**
* @author Sanda Zaharia ([email protected])
*/
public class MapElementImageProvider extends AbstractMapElementImageProvider
{
private static final Log log = LogFactory.getLog(MapElementImageProvider.class);
/**
* The character count limit for a static map URL request
*/
public static Integer MAX_URL_LENGTH = 8192;
@Override
protected Renderable createRenderable(JasperReportsContext jasperReportsContext, JRGenericPrintElement element) throws JRException
{
Renderable cachedRenderable = (Renderable)element.getParameterValue(MapComponent.PARAMETER_CACHE_RENDERER);
if (cachedRenderable == null)
{
OnErrorTypeEnum onErrorType =
element.getParameterValue(MapComponent.PARAMETER_ON_ERROR_TYPE) == null
? MapComponent.DEFAULT_ON_ERROR_TYPE
: OnErrorTypeEnum.getByName((String)element.getParameterValue(MapComponent.PARAMETER_ON_ERROR_TYPE));
String imageLocation = getImageLocation(element);
cachedRenderable = RendererUtil.getInstance(jasperReportsContext).getNonLazyRenderable(imageLocation, onErrorType);
element.setParameterValue(MapComponent.PARAMETER_CACHE_RENDERER, cachedRenderable);
}
return cachedRenderable;
}
protected String getImageLocation(JRGenericPrintElement element) {
Float latitude = (Float)element.getParameterValue(MapComponent.ITEM_PROPERTY_latitude);
latitude = latitude == null ? MapComponent.DEFAULT_LATITUDE : latitude;
Float longitude = (Float)element.getParameterValue(MapComponent.ITEM_PROPERTY_longitude);
longitude = longitude == null ? MapComponent.DEFAULT_LONGITUDE : longitude;
Integer zoom = (Integer)element.getParameterValue(MapComponent.PARAMETER_ZOOM);
zoom = zoom == null ? MapComponent.DEFAULT_ZOOM : zoom;
String mapType = (String)element.getParameterValue(MapComponent.ATTRIBUTE_MAP_TYPE);
String mapScale = (String)element.getParameterValue(MapComponent.ATTRIBUTE_MAP_SCALE);
String mapFormat = (String)element.getParameterValue(MapComponent.ATTRIBUTE_IMAGE_TYPE);
String reqParams = (String)element.getParameterValue(MapComponent.PARAMETER_REQ_PARAMS);
String markers ="";
List