private java.awt.Point startPointOnScreen; ... @Override public void onMouseDragged(MouseEvent event) { // do not supper() to block the built-in navigation java.awt.Point pointScreen = event.getLocationOnScreen(); Point endPointOnMap = this.getMap().toMapPoint(pointScreen.x, pointScreen.y); Point startPointOnMap = this.getMap().toMapPoint(startPointOnScreen.x, startPointOnScreen.y); double dx = endPointOnMap.getX() - startPointOnMap.getX(); double dy = endPointOnMap.getY() - startPointOnMap.getY(); // PAN TO new extent Point currentCenter = this.getMap().getExtent().getCenter(); Point newCenter = new Point(currentCenter.getX() - dx, currentCenter.getY() - dy); this.getMap().panTo(newCenter); this.startPointOnScreen = pointScreen; } ... @Override public void onMousePressed(MouseEvent event) { // do not supper() to block the built-in navigation this.startPointOnScreen = event.getLocationOnScreen(); } ... @Override public void onMouseWheelMoved(MouseWheelEvent event) { // do not supper() to block the built-in navigation java.awt.Point pointScreen = MouseInfo.getPointerInfo().getLocation(); // java.awt.Point pointScreen = event.getLocationOnScreen(); // => always return 0,0 Point pointCenter = this.getMap().toMapPoint(pointScreen.x, pointScreen.y); // Turn ON animation - Add this to keep^a nice & smooth zoomIn/Out this.getMap().setAnimationMode(AnimationMode.ANIMATE); int notches = event.getWheelRotation(); if (notches < 0) { // Zoom in this.getMap().zoom(1/factor, pointCenter); } else { // Zoom out this.getMap().zoom(factor, pointCenter); } // Turn OFF animation - Add this to keep^a nice & smooth zoomIn/Out this.getMap().setAnimationMode(AnimationMode.NONE); }
// Desactivate Built-in navigation btnCustomizedPanTo = new JButton(); btnCustomizedPanTo.setText("ACTIVATE customized panTo"); btnCustomizedPanTo.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { btnBuiltInPanTo.setEnabled(true); btnCustomizedPanTo.setEnabled(false); // activate the MapOverlay to BLOCK Built-In navigation, and manage customized panTo mapEventsOverlay.setActive(true); // Turn OFF animation to improve customized PANTO - Here !! map.setAnimationMode(AnimationMode.NONE); } }); toolBar.add(btnCustomizedPanTo);
Is it possible to implement a customized PanTo which has the same nice and smooth behavior than built-in ?
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.