This class is deprecated; developers are recommended to use the open source MarkerManager instead.
/ * Copyright (c) 2007 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file. * You can get a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * * distributed under an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the license for the specific language permissions and * limitations under the License. * * Version: 1.0 * Author: Doug Ricket, others * * Marker manager Add to viewport changes. * * Algorithm: * When the user moves the grid cells * All the markers in those * cells. * (If the users scrolls the viewport beyond the markers that are loaded, * no markers will be visible until the EVENT_moveend triggers an update.) * * In practical consequences, this allows 10,000 markers to be distributed over * a large area, view as 100-200 * visible markers, * rather than poor performance corresponding to 10,000 markers. * * Note that some code is optimized for speed over space, * with the goal of accommodating thousands of markers. * * / The file is big and I didn’t upload it. You can watch it by the link http://ezem.ru/js/gmap/markermanager.js
public function getmarkersAction () { $ params = array (); foreach (array ('zoom', 'area_min', 'area_max', 'units') as $ k) { $ params [$ k] = (int) $ this -> _ getParam ($ k, 0); } foreach (array ('lat1', 'lat2', 'lng1', 'lng2') as $ k) { $ params [$ k] = round ((float) $ this -> _ getParam ($ k, 0.0), 4); } $ params ['no_groups'] = ('true' == $ this -> _ getParam ('no_groups', null)); $ params ['deal_type'] = ('sell' == $ this -> _ getParam ('deal_type', null))? 'sell': 'buy'; $ params ['appointment'] = explode (',', trim ($ this -> _ getParam ('appointment', ''))); $ params ['except_objects'] = explode (',', trim ($ this -> _ getParam ('except_objects', '')))); $ dbWhere = Medialab_Items :: getActiveItemsLimits (); if (@ $ this-> user-> id) { $ dbWhere = array ('(('. implode ('AND', $ dbWhere). ') OR o.uid ='. $ this-> user-> id. ')'); } $ dbWhere [] = "` deal`.`type` = '". $ params [' deal_type ']."' ""; $ dbWhere [] = '`marker`.`is_polygon` = 0'; $ markers = Medialab_Gmap_Marker :: getMarkersDynamic ($ params, $ dbWhere); $ qty = 0; $ s = "<m> \ n"; foreach ($ markers as $ marker) { $ isGroup = (1 <$ marker ['qty']); $ s. = '<mi = "'. $ marker ['id']. '"' .'o = "'. $ marker [' object_id '].'" '<BR /> .'t = "'. $ marker [' lat '].'" ' .'g = "'. $ marker [' lng '].'" ' .'q = "'. $ marker [' qty '].'" ' .'a = "'. ($ isGroup?' group ': $ marker [' appointment_type ']).'" /> '. "\ n"; $ qty + = $ marker ['qty']; } $ s. = '<info count = "'. $ qty." \ "/> \ n"; $ s. = '</ m>'; header ('Content-Type: text / xml; charset = windows-1251'); exit ($ s); }
class Medialab_Gmap_Marker {/ * * * Block size in degrees for a scale of 0. * 72x128 sets 6x6 blocks in the visible area * 64x96 - 8x8 * * * / public static $ blockSize = array ('lat' => 64.0, 'lng' = > 96.0); / ** * Calculate map * * @param int $ zoom Map zoom * @return array Block $ public = function ($ zoom = 10) {$ rect = array () ; foreach (array ('lat', 'lng') as $ k) {$ rect [$ k] = round (self :: $ blockSize [$ k] / (1 << $ zoom), 4); $ rect [$ k .'_ half '] = round ($ rect [$ k] / 2, 4); } return $ rect; } / ** * Fetches markers for visible map area, dynamically grouping them if needed * * @param array $ params Array of search params, provide at least (lat, lng) . * @param array $ dbWhere Additional SQL query conditions (*) *return array Found items * * TODO: w / Google Maps API * / public static function getMarkersDynamic (array $ params, array $ dbWhere = array ()) {$ block = self :: getBlockSize ($ params ['zoom']); $ dbWhere [] = '(`marker`.`lat` BETWEEN'. $ params ['lat1']. 'AND'. $ params ['lat2']. ')'; // Longitude 180 -> -180 degrees wrap workaround if ($ params ['lng2'] <$ params ['lng1']) {$ dbWhere [] = '((`` ```lng` BETWEEN'. $ Params ['lng1']. 'AND 180.0) OR (`marker`.`lng` BETWEEN -180.0 AND'. $ params ['lng2']. '))'; } else {$ dbWhere [] = '(`marker``lng` BETWEEN'. $ params ['lng1']. 'AND'. $ params ['lng2']. ')'; } if (($ params ['area_min'] || $ params ['area_max']) && $ params ['units']) {$ unit = DB :: FindFirst ('ezem_units', array ('rate'), array ('id' => $ params ['units'])); if ($ params ['area_min']) {$ dbWhere [] = '`o`.`area`> ='. ($ params ['area_min'] * $ unit ['rate']); } if ($ params ['area_max']) {$ dbWhere [] = '`o`.`area` <='. ($ params ['area_max'] * $ unit ['rate']); }} $ a = $ params ['appointment']; if (count ($ a) && $ a [0]) {$ dbWhere [] = "` appointment`.`type` IN ('".implode ("', '", $ a)."') "; } $ a = $ params ['except_objects']; if (count ($ a) && $ a [0]) {$ dbWhere [] = '`o`.`id` NOT IN (' .implode (',', $ a). ')'; } $ dbGroupBy = '`marker`.`id`'; if (($ params ['zoom'] <13) &&! $ params ['no_groups']) {// Group only for zooms <= 12 and with no' no_groups' flag set $ dbGroupBy = '`grp_lat`,` grp_lng` '; } $ query = 'SELECT `marker`.`id`,` marker``object_id`, `appointment`.`type` AS` appointment_type`, AVG (`marker`.`lat`) AS` lat`, AVG (`marker``lng`) AS` lng`, FLOOR ((`marker`.`lat` - '. $ params [' lat1 '].') / '. $ block [' lat '].') AS `grp_lat`, FLOOR ((` marker``lng` - '. $ Params [' lng1 '].') / '. $ Block [' lng '].') AS `grp_lng`, COUNT (` marker `.`id`) AS` qty` FROM `ezem_gmap` AS` marker` JOIN `ezem_object` AS` o` ON (`o`.`id` =` marker`.`object_id`) JOIN `ezem_appointment` AS` appointment` ON (`appointment`.`id` =` o`.`applement_id`) JOIN `ezem_deal` AS` deal` ON (`deal`.`id` =` o`.`deal_id`) WHERE '.implode ('AND', $ dbWhere). ' GROUP BY '. $ DbGroupBy; return DB :: Query ($ query); }}
Source: https://habr.com/ru/post/28621/
All Articles