/*- * ================================================================================ * eCOMP Portal SDK * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property * ================================================================================ * 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. * ================================================================================ */ package org.openecomp.portalsdk.analytics.gmap.map; import java.awt.Color; import java.awt.Font; import java.awt.Graphics2D; import java.awt.Rectangle; import java.awt.geom.AffineTransform; import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.HashSet; import javax.servlet.http.HttpServletRequest; import org.openecomp.portalsdk.analytics.gmap.line.Line; import org.openecomp.portalsdk.analytics.gmap.line.LineInfo; import org.openecomp.portalsdk.analytics.gmap.map.layer.SwingLayer; import org.openecomp.portalsdk.analytics.gmap.node.Node; import org.openecomp.portalsdk.analytics.gmap.node.NodeInfo; public class NovaMap { private static int[] shapeWidth; public static final Font TEXT_FONT = new Font("sans-serif", Font.BOLD, 12); public static final Font HEADER_FONT = new Font("sans-serif", Font.ITALIC+Font.BOLD, 12); private HashSet showList; private ArrayList swingLayers; private AffineTransform transform; private Node node; private Line line; private ColorProperties colorProperties; private Rectangle2D defaultBoundary; private int zoomLevel; private String currentYearMonth; private String dataLoaded = ""; /** * size in screen pixel */ private Rectangle boundingBox; /** * size in pixel web mercator projection */ private Rectangle2D mapArea; /** * size in longitude latitude */ private Rectangle2D geoArea; public static double[] meter2pixel; private boolean showLegend = false; static { initShapeWidth(); initMeter2Pixel(); } private static void initMeter2Pixel() { meter2pixel = new double[MapConstant.ZOOM_MAX - MapConstant.ZOOM_MIN+1]; meter2pixel[0] = 156543.04/2; for(int i=1; i 4 && i < 10) { width += 2; } else { width++; } shapeWidth[i] = width; } } public NovaMap() { boundingBox = new Rectangle(); mapArea = new Rectangle2D.Double(); geoArea = new Rectangle2D.Double(); showList = new HashSet(); swingLayers = new ArrayList(); } public int getBestZoomLevel(double Latitude1, double Longitude1, double Latitude2, double Longitude2, double height, double width) { if (height==0) height=700; if (width==0) width=1200; double lat1 = Math.min(Latitude1, Latitude1); double CosLat = Math.cos(Math.toRadians(lat1)); double Wmeter = getDistance( lat1, Longitude1, lat1, Longitude2)/CosLat; double Hmeter = getDistance( Latitude1, Longitude1, Latitude2, Longitude1)/CosLat; int zoom = 0; if(Latitude1 == Latitude2 && Longitude1 == Longitude2) zoom = 15; if (zoom <= 0) { for(; zoom < meter2pixel.length && (width*meter2pixel[zoom]) > Wmeter && (height*meter2pixel[zoom]) > Hmeter; ++zoom) ; } // && (1200*meter2pixel[zoom]) > Wmeter // && (700*meter2pixel[zoom]) > Hmeter; return zoom + MapConstant.ZOOM_MIN-1; } public static double getDistance(double Latitude1, double Longitude1, double Latitude2, double Longitude2) { Latitude1 = Math.toRadians(Latitude1); Longitude1 = Math.toRadians(Longitude1); Latitude2 = Math.toRadians(Latitude2); Longitude2 = Math.toRadians(Longitude2); final double R = 6371.0; // earth's mean radius in km double dSinLat05 = Math.sin( (Latitude2 - Latitude1)/2 ); double dSinLong05 = Math.sin( (Longitude2 - Longitude1)/2 ); double a = dSinLat05 * dSinLat05 + Math.cos(Latitude1) * Math.cos(Latitude2) * dSinLong05 * dSinLong05; double c = (0==a || 1==a) ? 0 : 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0-a)); return R * c * 1000.0; //in meters } public Rectangle getBoundingBox() { return boundingBox; } public void setBoundingBox(int width, int height) { boundingBox.setSize(width, height); } public void setNode(Node node) { this.node = node; } public Node getNode() { return node; } public void setLine(Line line) { this.line = line; } public Line getLine() { return line; } public void setColorProperties(ColorProperties colorProperties) { this.colorProperties = colorProperties; } public ColorProperties getColorProperties() { return colorProperties; } public void setZoomLevel(int zoomLevel) { this.zoomLevel = zoomLevel; } public int getZoomLevel() { return zoomLevel; } public void addShowList(String type) { showList.add(type.toUpperCase()); } public void addShowList(String type, int number) { showList.add(type.toUpperCase() + ":" + number); } public void removeShowList(String type) { showList.remove(type.toUpperCase()); } public void removeShowList(String type, int number) { showList.remove(type.toUpperCase() + ":" + number); } public void clearShowList() { showList.clear(); } public HashSet getShowList() { return showList; } public boolean containsShowList(String type) { return showList.contains(type.toUpperCase()); } public boolean containsShowList(String type, int number) { return showList.contains(type.toUpperCase() + ":" + number); } public int getShowListSize() { return showList.size(); } public void addSwingLayer(SwingLayer swingLayer) { swingLayers.add(swingLayer); } public void removeSwingLayer(SwingLayer swingLayer) { swingLayers.remove(swingLayer); } public void clearSwingLayers() { swingLayers.clear(); } public ArrayList getSwingLayers() { return swingLayers; } public int getShapeWidth() { return shapeWidth[getZoomLevel()>=22?21:(getZoomLevel()<=8 ? 8:getZoomLevel())]; } public Point2D getPixelPos(double latitude, double longitude) { double sinLatitude = Math.sin(Math.toRadians(latitude)); return new Point2D.Double( ((longitude + 180.0) / 360.0) * 256.0 * (1< existNodeInfo = node.nodeExist(screenPoint); if (existNodeInfo == null) { ArrayList existLineInfo = line.lineExist(screenPoint); if (existLineInfo == null) { } else { System.out.println("%%%%%%map.singleLeftClick end 1"); return existLineInfo; } } else { // if (existNodeInfo.size() == 1) { // NodeInfo nodeInfo = existNodeInfo.get(0); // node.getNodeCollection().clearSelectedNode(); // node.getNodeCollection().addSelectedNode(nodeInfo.getID(), nodeInfo.getLegendID()); // return getSelectedImage(geoArea); // } // else { // return existNodeInfo; // } System.out.println("%%%%%%map.singleLeftClick end 2"); return existNodeInfo; } System.out.println("%%%%%%map.singleLeftClick end 3"); return null; } public String getCurrentYearMonth() { return currentYearMonth; } public void setCurrentYearMonth(String currentYearMonth) { this.currentYearMonth = currentYearMonth; } public Rectangle2D getDefaultBoundary() { return defaultBoundary; } public void setDefaultBoundary(Rectangle2D defaultBoundary) { this.defaultBoundary = defaultBoundary; } public boolean isShowLegend() { return showLegend; } public void setShowLegend(boolean showLegend) { this.showLegend = showLegend; } public String getDataLoaded() { return dataLoaded; } public void setDataLoaded(String dataLoaded) { this.dataLoaded = dataLoaded; } }