Xây dựng popup lấy vị trí map áp dụng pointfinder (ok)
PreviousLeaflet - Một thư viện JS mã nguồn mở cho việc xây dụng ứng dụng bản đồ map (ok)NextReverse Geocoding Convert Lat Long to Address map (ok)
Last updated
Was this helpful?
Last updated
Was this helpful?
C:\xampp\htdocs\test\wp-content\themes\pointfinder\footer.php
<div id="pfwidgetmaps"></div>
C:\xampp\htdocs\test\wp-content\plugins\pointfindercoreelements\public\js\theme-map-functions.js
jQuery(document).ready(function($) {
function pointfinderbuildmap_ct(handler) {
var $mapobject = $('#' + handler + '');
var we_special_key = 0;
var we_lat = 0;
var we_lng = 0;
var we_zoom = 12;
var we_maxzoom = 18;
console.log(we_lat);
console.log('tesssssssssssssssss1');
/* OSM */
var tiles = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: parseInt(we_maxzoom),
attribution: '© <a href="https://osm.org/copyright">OpenStreetMap</a> contributors'
});
/* Create Map */
var mapelement = L.map('' + handler + '', {
zoomControl: false,
center: [we_lat, we_lng],
zoom: 14,
layers: [tiles],
gestureHandling: true
});
mapelement.dragging.enable();
mapelement.scrollWheelZoom.enable();
L.control.zoom({
position: 'topleft'
}).addTo(mapelement);
$.pointfinderlocationmark = new L.Control.PFDMapLocate({
position: 'topleft',
setView: 'once',
strings: {
title: 'Locate me!',
metersUnit: "km",
feetUnit: "mile",
popup: 'You are here!'
},
metric: true,
icon: "fas fa-map-marker-alt",
iconLoading: 'fas fa-spinner fa-spin',
drawCircle: false,
showPopup: true,
returnToPrevBounds: false,
keepCurrentZoomLevel: false,
locateOptions: {
maxZoom: 12,
enableHighAccuracy: true
},
followCircleStyle: {
radius: 10000
}
}).addTo(mapelement);
return mapelement;
}
function pfgeolocation_findme_ct(we_geoc_type) {
var pointfinderbuildmap_ctv = pointfinderbuildmap_ct('pfwidgetmaps');
pointfinderbuildmap_ctv.off('locationfound');
pointfinderbuildmap_ctv.locate({
watch: false,
setView: false,
enableHighAccuracy: true,
custom: 'geobutton'
}).on('locationfound', function(e) {
console.log("lionelpham1");
$.pointfindersetbounds(e.latlng.lat, e.latlng.lng);
pointfinderbuildmap_ctv.stopLocate();
$.ajax({
url: theme_scriptspf.ajaxurl,
type: 'GET',
dataType: 'json',
data: {
action: "pfget_geocoding",
security: theme_scriptspf.pfget_geocoding,
lat: "" + e.latlng.lat + "",
lng: "" + e.latlng.lng + "",
option: 'reverse',
ctype: "" + we_geoc_type + ""
},
}).complete(function() {
console.log('data');
});
}).on('locationerror', function(e) {
console.log(e);
alert(e.message);
});
}
pfgeolocation_findme_ct('photon');
});