Add openstreetmap with a mapbox.com layer. #420

This commit is contained in:
James Cole
2017-09-30 17:50:22 +02:00
parent c0d62dfc86
commit cc61281523
24 changed files with 14474 additions and 193 deletions

View File

@@ -1,15 +1,120 @@
<div class="{{ classes }}" id="{{ name }}_holder">
<label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label>
<div class="col-sm-8">
<div id="map-canvas" style="width:100%;height:300px;"></div>
<p class="help-block">Right-click to set the tag's location.
<a href="#" id="clearLocation">Clear location</a>
{% if env('MAPBOX_API_KEY','') == '' %}
<p class="text-danger">
To use map, get an API key from <a href="https://www.mapbox.com/">Mapbox</a>.
Open your <code>.env</code> file en enter this code after <code>MAPBOX_API_KEY=</code>.
</p>
{% else %}
<div id="{{ name }}_map" style="width:100%;height:300px;"></div>
<div id="map-canvas" ></div>
<p class="help-block">
{{ 'press_tag_location'|_ }}
<a href="#" id="{{ name }}_clear_location">{{ 'clear_location'|_ }}</a>
</p>
<input type="hidden" name="latitude" value=""/>
<input type="hidden" name="longitude" value=""/>
<input type="hidden" name="zoomLevel" value="6"/>
<input type="hidden" name="setTag" value=""/>
{# latitude #}
{% if old(name~'_latitude') %}
<input type="hidden" name="{{ name }}_latitude" value="{{ old('tag_position_latitude') }}"/>
{% else %}
<input type="hidden" name="{{ name }}_latitude" value="{{ tag.latitude }}"/>
{% endif %}
{# longitude #}
{% if old('tag_position_longitude') %}
<input type="hidden" name="{{ name }}_longitude" value="{{ old('tag_position_longitude') }}"/>
{% else %}
<input type="hidden" name="{{ name }}_longitude" value="{{ tag.longitude }}"/>
{% endif %}
{# zoomlevel #}
{% if old('tag_position_zoomlevel') %}
<input type="hidden" name="{{ name }}_zoomlevel" value="{{ old('tag_position_zoomlevel') }}"/>
{% else %}
<input type="hidden" name="{{ name }}_zoomlevel" value="{{ tag.zoomLevel }}"/>
{% endif %}
{% if tag.zoomLevel and tag.longitude and tag.latitude %}
<input type="hidden" name="{{ name }}_has_tag" value="true"/>
{% else %}
<input type="hidden" name="{{ name }}_has_tag" value="false"/>
{% endif %}
{% include 'form/feedback' %}
{% endif %}
</div>
</div>
{% if env('MAPBOX_API_KEY','') != '' %}
{% set latitudevar = name~'_latitude' %}
{% set longitudevar = name~'_longitude' %}
{% set zoomlevelvar = name~'_zoomlevel' %}
{% set hastagvar = name~'_has_tag' %}
{% set settagvar = name~'_set_tag' %}
{% set clearvar = name~'_clear_location' %}
<script type="text/javascript">
var mymap;
var marker;
if(typeof {{ latitudevar }} === "undefined") {
var {{ latitudevar }} = "52.3167";
}
if(typeof {{ longitudevar }} === "undefined") {
var {{ longitudevar }} = "5.5500";
}
if(typeof {{ zoomlevelvar }} === "undefined") {
var {{ zoomlevelvar }} = "6";
}
if(typeof mapboxToken === 'undefined') {
var mapboxToken = 'invalid';
}
//
document.getElementById('{{ clearvar }}').addEventListener('click', function() {
if (typeof marker !== 'undefined') {
marker.remove();
$('input[name="{{ hastagvar }}"]').val('false');
}
return false;
});
// set location thing:
function setTagLocation(e) {
$('input[name="{{ latitudevar }}"]').val(e.latlng.lat);
$('input[name="{{ longitudevar }}"]').val(e.latlng.lng);
$('input[name="{{ zoomlevelvar }}"]').val(mymap.getZoom());
$('input[name="{{ hastagvar }}"]').val('true');
// remove existing marker:
if(typeof marker !== 'undefined') {
marker.remove();
}
// new marker
marker = L.marker([e.latlng.lat, e.latlng.lng]).addTo(mymap);
}
console.log({{ longitudevar }});
document.addEventListener("DOMContentLoaded", function() {
"use strict";
// make map:
mymap = L.map('{{ name }}_map').setView([{{ latitudevar }}, {{ longitudevar }}], {{ zoomlevelvar }});
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',
maxZoom: 18,
id: 'mapbox.streets',
accessToken: mapboxToken
}).addTo(mymap);
mymap.on('contextmenu', setTagLocation);
// add marker
if(typeof {{ settagvar }} !== 'undefined' && {{ settagvar }} === true) {
marker = L.marker([{{ latitudevar }}, {{ longitudevar }}]).addTo(mymap);
}
});
</script>
{% endif %}

View File

@@ -24,7 +24,7 @@
<div class="col-sm-8">
<div class="radio"><label>
{{ Form.checkbox('return_to_edit', '1', Input.old('return_to_edit') == '1', {'id': name ~ '_return_to_edit'}) }}
{{ Form.checkbox('return_to_edit', '1', old('return_to_edit') == '1', {'id': name ~ '_return_to_edit'}) }}
{{ trans('form.returnHereUpdateExplanation') }}
</label>
</div>
@@ -39,7 +39,7 @@
<div class="col-sm-8">
<div class="radio"><label>
{{ Form.checkbox('split_journal', '1', Input.old('split_journal') == '1', {'id': name ~ 'split'}) }}
{{ Form.checkbox('split_journal', '1', old('split_journal') == '1', {'id': name ~ 'split'}) }}
{{ trans('form.split_journal_explanation') }}
</label>
</div>

View File

@@ -28,7 +28,7 @@
<div class="box-body">
{{ ExpandedForm.date('date') }}
{{ ExpandedForm.textarea('description') }}
{{ ExpandedForm.location('tagPosition') }}
{{ ExpandedForm.location('tag_position') }}
</div>
</div>
@@ -53,41 +53,45 @@
{% endblock %}
{% block scripts %}
<script type="text/javascript">
var latitude;
{% if Input.old('latitude') %}
latitude = "{{ Input.old('latitude') }}";
// pre-set latitude:
{% if old('tag_position_latitude') %}
var tag_position_latitude = "{{ old('tag_position_latitude') }}";
{% else %}
latitude = "52.3167";
var tag_position_latitude = "52.3167";
{% endif %}
var doPlaceMarker;
{% if Input.old('latitude') and Input.old('longitude') and Input.old('zoomLevel') %}
doPlaceMarker = true;
// pre-set longitude
{% if old('tag_position_longitude') %}
var tag_position_longitude = "{{ old('tag_position_longitude') }}";
{% else %}
doPlaceMarker = false;
var tag_position_longitude = "5.5500";
{% endif %}
{% if Input.old('longitude') %}
var longitude = "{{ Input.old('longitude') }}";
// pre-set zoom level
{% if old('tag_position_zoomlevel') %}
var tag_position_zoomlevel = "{{ old('tag_position_zoomlevel') }}";
{% else %}
var longitude = "5.5500";
var tag_position_zoomlevel = "6";
{% endif %}
{% if Input.old('zoomLevel') %}
var zoomLevel = {{ Input.old('zoomLevel') }};
// must draw a tag?
{% if old('tag_position_latitude') and old('tag_position_longitude') and old('tag_position_zoomlevel') %}
var tag_position_set_tag = true;
{% else %}
var zoomLevel = 6;
var tag_position_set_tag = false;
{% endif %}
var apiKey = "{{ apiKey }}";
// token for Mapbox:
var mapboxToken = "{{ env('MAPBOX_API_KEY','') }}";
</script>
<script src="https://maps.googleapis.com/maps/api/js?v=3&amp;key={{ apiKey }}"></script>
<script src="lib/leaflet/leaflet.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="js/lib/modernizr-custom.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
<script src="js/ff/tags/create-edit.js?v={{ FF_VERSION }}"></script>
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="lib/leaflet/leaflet.css?v={{ FF_VERSION }}" />
<link href="css/jquery-ui/jquery-ui.structure.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all">
<link href="css/jquery-ui/jquery-ui.theme.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all">
{% endblock %}

View File

@@ -30,7 +30,7 @@
<div class="box-body">
{{ ExpandedForm.date('date', tag.date.format('Y-m-d')) }}
{{ ExpandedForm.textarea('description') }}
{{ ExpandedForm.location('tagPosition') }}
{{ ExpandedForm.location('tag_position') }}
</div>
</div>
@@ -57,40 +57,45 @@
{% endblock %}
{% block scripts %}
<script type="text/javascript">
{% if Input.old('latitude') %}
var latitude = {{ Input.old('latitude') }};
// pre-set latitude:
{% if old('tag_position_latitude') %}
var tag_position_latitude = "{{ old('tag_position_latitude') }}";
{% else %}
var latitude = {{ tag.latitude|default("52.3167") }};
var tag_position_latitude = {{ tag.latitude|default("52.3167") }};
{% endif %}
{% if (Input.old('latitude') and Input.old('longitude') and Input.old('zoomLevel'))
or (tag.latitude and tag.longitude and tag.zoomLevel) %}
var doPlaceMarker = true;
// pre-set longitude
{% if old('tag_position_longitude') %}
var tag_position_longitude = "{{ old('tag_position_longitude') }}";
{% else %}
var doPlaceMarker = false;
var tag_position_longitude = {{ tag.longitude|default("5.5500") }};
{% endif %}
{% if Input.old('longitude') %}
var longitude = "{{ Input.old('longitude') }}";
// pre-set zoom level
{% if old('tag_position_zoomlevel') %}
var tag_position_zoomlevel = "{{ old('tag_position_zoomlevel') }}";
{% else %}
var longitude = {{ tag.longitude|default("5.5500") }};
var tag_position_zoomlevel = {{ tag.zoomLevel|default("6") }};
{% endif %}
{% if Input.old('zoomLevel') %}
var zoomLevel = {{ Input.old('zoomLevel') }};
{% if tag.zoomLevel and tag.longitude and tag.latitude %}
var tag_position_set_tag = true;
{% else %}
var zoomLevel = {{ tag.zoomLevel|default("6") }};
var tag_position_set_tag = false;
{% endif %}
var apiKey = "{{ apiKey }}";
// token for Mapbox:
var mapboxToken = "{{ env('MAPBOX_API_KEY','') }}";
</script>
<script src="https://maps.googleapis.com/maps/api/js?v=3&amp;key={{ apiKey }}"></script>
<script src="lib/leaflet/leaflet.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="js/lib/modernizr-custom.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="js/lib/jquery-ui.min.js?v={{ FF_VERSION }}"></script>
<script src="js/ff/tags/create-edit.js?v={{ FF_VERSION }}"></script>
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="lib/leaflet/leaflet.css?v={{ FF_VERSION }}" />
<link href="css/jquery-ui/jquery-ui.structure.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all">
<link href="css/jquery-ui/jquery-ui.theme.min.css?v={{ FF_VERSION }}" type="text/css" rel="stylesheet" media="all">
{% endblock %}

View File

@@ -99,7 +99,7 @@
</div>
<div class="box-body">
{% if tag.latitude and tag.longitude and tag.zoomLevel %}
<div id="map-canvas" style="width:100%;height:300px;"></div>
<div id="tag_location_map" style="width:100%;height:300px;"></div>
{% else %}
<p>{{ 'no_location_set'|_ }}</p>
{% endif %}
@@ -195,6 +195,9 @@
{% endif %}
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="lib/leaflet/leaflet.css?v={{ FF_VERSION }}" />
{% endblock %}
{% block scripts %}
<script type="text/javascript">
var latitude = {{ tag.latitude|default("52.3167") }};
@@ -207,9 +210,11 @@
var doPlaceMarker = false;
{% endif %}
var apiKey = "{{ apiKey }}";
// token for Mapbox:
var mapboxToken = "{{ env('MAPBOX_API_KEY','') }}";
</script>
<script src="https://maps.googleapis.com/maps/api/js?v=3&amp;key={{ apiKey }}"></script>
<script src="lib/leaflet/leaflet.js?v={{ FF_VERSION }}"></script>
<script src="js/ff/tags/show.js?v={{ FF_VERSION }}"></script>
<script type="text/javascript" src="js/ff/transactions/list.js?v={{ FF_VERSION }}"></script>
{% endblock %}