rework map view and update leaflet to 1.6.0
This commit is contained in:
parent
8cbc7b2a07
commit
ccdb122afb
6 changed files with 59 additions and 42 deletions
|
@ -25,6 +25,10 @@
|
|||
user-select: none;
|
||||
-webkit-user-drag: none;
|
||||
}
|
||||
/* Prevents IE11 from highlighting tiles in blue */
|
||||
.leaflet-tile::selection {
|
||||
background: transparent;
|
||||
}
|
||||
/* Safari renders non-retina tile on retina better with this, but Chrome is worse */
|
||||
.leaflet-safari .leaflet-tile {
|
||||
image-rendering: -webkit-optimize-contrast;
|
||||
|
@ -237,7 +241,8 @@
|
|||
|
||||
.leaflet-marker-icon.leaflet-interactive,
|
||||
.leaflet-image-layer.leaflet-interactive,
|
||||
.leaflet-pane > svg path.leaflet-interactive {
|
||||
.leaflet-pane > svg path.leaflet-interactive,
|
||||
svg.leaflet-image-layer.leaflet-interactive path {
|
||||
pointer-events: visiblePainted; /* IE 9-10 doesn't have auto */
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -13,15 +13,16 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<style>
|
||||
#map{width:100%;height:100%;position:fixed;top:0px;left:0px;right:0px;bottom:0px}
|
||||
</style>
|
||||
|
||||
<div id='map'>
|
||||
</div>
|
||||
<div id='map'></div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var marker;
|
||||
|
||||
//get location from URL
|
||||
var getUrlParameter = function getUrlParameter(sParam) {
|
||||
var sPageURL = decodeURIComponent(window.location.search.substring(1)),
|
||||
sURLVariables = sPageURL.split('&'),
|
||||
|
@ -30,24 +31,33 @@
|
|||
|
||||
for (i = 0; i < sURLVariables.length; i++) {
|
||||
sParameterName = sURLVariables[i].split('=');
|
||||
|
||||
if (sParameterName[0] === sParam) {
|
||||
return sParameterName[1] === undefined ? true : sParameterName[1];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof getUrlParameter('lat') === 'undefined' && typeof getUrlParameter('lon') === 'undefined') {
|
||||
var map = L.map('map', {
|
||||
zoomControl: true,
|
||||
attributionControl: false
|
||||
}).fitWorld();
|
||||
} else {
|
||||
|
||||
// create map
|
||||
if (getUrlParameter('lat') != null && getUrlParameter('lon') != null) {
|
||||
var map = L.map('map', {
|
||||
zoomControl: true,
|
||||
attributionControl: true
|
||||
}).setView([getUrlParameter('lat'), getUrlParameter('lon')], 15);
|
||||
|
||||
// add marker
|
||||
if (!marker) {
|
||||
marker = L.marker([getUrlParameter('lat'), getUrlParameter('lon')]).addTo(map);
|
||||
marker.bindPopup((getUrlParameter('name')), {
|
||||
closeOnClick: false,
|
||||
closeButton: false,
|
||||
autoClose: false
|
||||
}).openPopup();
|
||||
}
|
||||
} else {
|
||||
var map = L.map('map', {
|
||||
zoomControl: true,
|
||||
attributionControl: true
|
||||
}).fitWorld();
|
||||
}
|
||||
|
||||
map.addLayer(new L.TileLayer("https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", {
|
||||
|
@ -55,16 +65,20 @@
|
|||
maxZoom: 19
|
||||
}));
|
||||
|
||||
if (typeof getUrlParameter('lat') !== 'undefined' && typeof getUrlParameter('lon') !== 'undefined' && typeof getUrlParameter('name') !== 'undefined') {
|
||||
var marker = L.marker([getUrlParameter('lat'), getUrlParameter('lon')]).addTo(map);
|
||||
marker.bindPopup(getUrlParameter('name'), {
|
||||
closeOnClick: false,
|
||||
closeButton: false,
|
||||
autoClose: false
|
||||
}).openPopup();
|
||||
} else if (typeof getUrlParameter('lat') !== 'undefined' && typeof getUrlParameter('lon') !== 'undefined' && typeof getUrlParameter('name') === 'undefined') {
|
||||
var marker = L.marker([getUrlParameter('lat'), getUrlParameter('lon')]).addTo(map);
|
||||
// Change view to coordinates
|
||||
function toCoordinates(latIntent, lonIntent, Name){
|
||||
map.setView([parseFloat(latIntent), parseFloat(lonIntent)], 15);
|
||||
if (!marker) {
|
||||
marker = L.marker([parseFloat(latIntent), parseFloat(lonIntent)]).addTo(map);
|
||||
marker.bindPopup(("..."), {
|
||||
closeOnClick: false,
|
||||
closeButton: false,
|
||||
autoClose: false
|
||||
}).openPopup();
|
||||
}
|
||||
marker.setLatLng([parseFloat(latIntent), parseFloat(lonIntent)]).update();
|
||||
marker.setPopupContent(Name);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
|
@ -104,12 +104,12 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
|
|||
if (snackBarCoordinator != null) {
|
||||
this.snackBar = Snackbar.make(snackBarCoordinator, R.string.location_sharing_disabled, Snackbar.LENGTH_INDEFINITE);
|
||||
snackBar.setAction(R.string.enable, view -> {
|
||||
showLocation(null, "");
|
||||
if (isLocationEnabled()) {
|
||||
if (hasLocationPermission(LocationActivity.REQUEST_LOCATION_PERMISSION)) {
|
||||
requestLocationUpdates();
|
||||
}
|
||||
} else {
|
||||
showLocation(null, null);
|
||||
setShareButtonEnabled(false);
|
||||
if (hasLocationPermission(LocationActivity.REQUEST_LOCATION_PERMISSION)) {
|
||||
requestLocationUpdates();
|
||||
|
@ -142,7 +142,7 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
|
|||
super.onResume();
|
||||
if (isLocationEnabled()) {
|
||||
this.snackBar.dismiss();
|
||||
showLocation(null, null);
|
||||
showLocation(null, "");
|
||||
} else {
|
||||
this.snackBar.show();
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
|
|||
}
|
||||
}
|
||||
|
||||
private void showLocation(@Nullable Location location, @Nullable String address) {
|
||||
private void showLocation(@Nullable Location location, String address) {
|
||||
if (location == null && TextUtils.isEmpty(address)) { // no location and no address available
|
||||
final WebView webView = findViewById(R.id.webView);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
|
@ -217,12 +217,12 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
|
|||
String LocationName = "<b>" + mLocationName + "</b>";
|
||||
final WebView webView = findViewById(R.id.webView);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
webView.loadUrl("file:///android_asset/map.html?lat=" + mLastLocation.getLatitude() + "&lon=" + mLastLocation.getLongitude() + "&name=" + LocationName);
|
||||
webView.loadUrl("javascript:toCoordinates(" + mLastLocation.getLatitude() + "," + mLastLocation.getLongitude() + "," + "'" + LocationName + "'" +");");
|
||||
} else if (location != null && !TextUtils.isEmpty(address)) { // location and address available
|
||||
String LocationName = "<b>" + mLocationName + "</b><br>" + address;
|
||||
final WebView webView = findViewById(R.id.webView);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
webView.loadUrl("file:///android_asset/map.html?lat=" + mLastLocation.getLatitude() + "&lon=" + mLastLocation.getLongitude() + "&name=" + LocationName);
|
||||
webView.loadUrl("javascript:toCoordinates(" + mLastLocation.getLatitude() + "," + mLastLocation.getLongitude() + "," + "'" + LocationName + "'" +");");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,12 +238,14 @@ public class ShareLocationActivity extends LocationActivity implements LocationL
|
|||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
showLocation(mLastLocation, null);
|
||||
showLocation(mLastLocation, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
address = getAddress(ShareLocationActivity.this, mLastLocation);
|
||||
if (mLastLocation != null) {
|
||||
address = getAddress(ShareLocationActivity.this, mLastLocation);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ public class ShowLocationActivity extends XmppActivity {
|
|||
setTitle(getString(R.string.show_location));
|
||||
setSupportActionBar(findViewById(R.id.toolbar));
|
||||
configureActionBar(getSupportActionBar());
|
||||
|
||||
showLocation(null, "");
|
||||
Intent intent = getIntent();
|
||||
|
||||
this.mLocationName = intent != null ? intent.getStringExtra("name") : null;
|
||||
|
@ -136,12 +136,8 @@ public class ShowLocationActivity extends XmppActivity {
|
|||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private void showLocation(@Nullable Location location, @Nullable String address) {
|
||||
if (location == null && TextUtils.isEmpty(address)) { // no location and no address available
|
||||
final WebView webView = findViewById(R.id.webView);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
webView.loadUrl("file:///android_asset/map.html");
|
||||
} else if (location != null && TextUtils.isEmpty(address)) { // location but no address available
|
||||
private void showLocation(Location location, String address) {
|
||||
if (location != null && TextUtils.isEmpty(address)) { // location but no address available
|
||||
String LocationName = "<b>" + mLocationName + "</b>";
|
||||
final WebView webView = findViewById(R.id.webView);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
|
@ -150,7 +146,7 @@ public class ShowLocationActivity extends XmppActivity {
|
|||
String LocationName = "<b>" + mLocationName + "</b><br>" + address;
|
||||
final WebView webView = findViewById(R.id.webView);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
webView.loadUrl("file:///android_asset/map.html?lat=" + location.getLatitude() + "&lon=" + location.getLongitude() + "&name=" + LocationName);
|
||||
webView.loadUrl("javascript:toCoordinates(" + location.getLatitude() + "," + location.getLongitude() + "," + "'" + LocationName + "'" +");");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -182,7 +178,7 @@ public class ShowLocationActivity extends XmppActivity {
|
|||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
showLocation(location, null);
|
||||
showLocation(location, "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Reference in a new issue