~berthold-daum/zora/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*******************************************************************************
 * Copyright (c) 2009 Berthold Daum.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Berthold Daum - initial API and implementation
 *******************************************************************************/

package com.bdaum.zoom.gps.gmap3.internal.views;

import java.net.URL;

import org.eclipse.osgi.util.NLS;

import com.bdaum.zoom.gps.gmap3.internal.Gmap3Activator;
import com.bdaum.zoom.gps.widgets.AbstractMapComponent;

public class MapComponent extends AbstractMapComponent {

	private URL markerclusterUrl;
	private URL iconmakerUrl;
	private URL zoomMapUrl;

	@Override
	protected void findResources() {
		markerclusterUrl = findUrl("/gmap/markerclusterer.js"); //$NON-NLS-1$
		iconmakerUrl = findUrl("/gmap/mapiconmaker.js"); //$NON-NLS-1$
		zoomMapUrl = findUrl("/gmap/zoomMap.js"); //$NON-NLS-1$
	}

	@Override
	protected String createSetPosDetailScript(HistoryItem item) {
		return NLS
				.bind("map.setZoom({0});\nmap.panTo({1});", (int) item.getDetail(), createLatLng(item.getLatitude(), item.getLongitude())); //$NON-NLS-1$
	}

	@Override
	protected String createLatLngBounds(double swLat, double swLon,
			double neLat, double neLon) {
		return NLS.bind("new google.maps.LatLngBounds({0},{1}", createLatLng(swLat, swLon), createLatLng(neLat, neLon)); //$NON-NLS-1$
	}

	private URL findUrl(String path) {
		return super.findUrl(Gmap3Activator.getDefault().getBundle(), path);
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.bdaum.zoom.gps.widgets.AbstractMapComponent#createLatLng(double,
	 * double)
	 */

	@Override
	protected String createLatLng(double lat, double lon) {
		return NLS
				.bind("new google.maps.LatLng({0},{1})", usformat.format(lat), usformat.format(lon)); //$NON-NLS-1$
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * com.bdaum.zoom.gps.widgets.AbstractMapComponent#createScriptEntries()
	 */

	@Override
	protected String createScriptEntries() {
		StringBuilder sb = new StringBuilder();
		sb.append("<script src=\"http://maps.google.com/maps/api/js?sensor=false\" type=\"text/javascript\"></script>\n"); //$NON-NLS-1$
		sb.append(createScriptEntry(markerclusterUrl)).append('\n');
		sb.append(createScriptEntry(iconmakerUrl)).append('\n');
		sb.append(createScriptEntry(zoomMapUrl));
		return sb.toString();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.bdaum.zoom.gps.IMapComponent#dispose()
	 */

	@Override
	public void dispose() {
		getControl().dispose();
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see
	 * com.bdaum.zoom.gps.widgets.AbstractMapComponent#createAdditionalVariables
	 * ()
	 */

	@Override
	protected String createAdditionalVariables() {
		return null;
	}

	@Override
	protected String getAppKey() {
		return null;
	}

	@Override
	protected String getMappingSystemName() {
		return "Google Maps 3"; //$NON-NLS-1$
	}


}