| 148 | 6. '''Make Quick Plot Support IPv6''' |
| 149 | Quick Plot calls Http API to generate the map picture on Web Server. The code is like below (in PHP): |
| 150 | {{{ |
| 151 | // Get the correct port number |
| 152 | // Just use the 127.0.0.1 specificly to point to localhost. Because the WebExtension will |
| 153 | // be always on the same server with map agent. |
| 154 | $mapAgent .= "://127.0.0.1:" . $_SERVER["SERVER_PORT"]; |
| 155 | // Get the correct virtual directory |
| 156 | $mapAgent .= substr($_SERVER["REQUEST_URI"], 0, strpos($_SERVER["REQUEST_URI"], "/", 1)); |
| 157 | $mapAgent .="/mapagent/mapagent.fcgi?VERSION=1.0.0&OPERATION=GETMAPIMAGE" . |
| 158 | "&SESSION=$sessionID" . |
| 159 | "&MAPNAME=" . rawurlencode($mapName) . |
| 160 | "&FORMAT=PNG" . |
| 161 | "&SETVIEWCENTERX=" . $center->GetX() . |
| 162 | "&SETVIEWCENTERY=" . $center->GetY() . |
| 163 | "&SETVIEWSCALE=$scaleDenominator" . |
| 164 | "&SETDISPLAYDPI=$printDpi" . |
| 165 | "&SETDISPLAYWIDTH=$toSize->width" . |
| 166 | "&SETDISPLAYHEIGHT=$toSize->height" . |
| 167 | "&CLIP=0"; |
| 168 | |
| 169 | $image = imagecreatefrompng($mapAgent); |
| 170 | }}} |
| 171 | It uses '''{{{127.0.0.1}}}''' explicitly to connect to the Web Extension. There reason why it was implemented this way is like below: |
| 172 | The url is actually a self-referencing URL (the http request is sent and responded by a same host). So the first idea would be just use '''{{{LOCALHOST}}}''' to connect to the Web Extension. But the problem is the php function '''{{{imagecreatefrompng(url)}}}''' will run into error if the the url contains '''{{{LOCALHOST}}}'''. So this solution doesn’t work. |
| 173 | The second idea would be use '''{{{$_SERVER[“SERVER_NAME”]}}}''' to get the host name at runtime. But it doesn’t work if the Web Extension Server is behind a proxy Http server. In this case '''{{{$_SERVER[“SERVER_NAME”]}}}''' will be the name of proxy server instead of web extension server. And it’s possible that web extension server cannot connect to the proxy server. Then the picture cannot be generated by that url. So this solution also doesn’t work. |
| 174 | '''{{{127.0.0.1}}}''' is the right solution considering above cases. |
| 175 | But after IPv6 has been introduced, the solution of '''{{{127.0.0.1}}}''' will not work with IPv6. |
| 176 | The solution is: don’t use the Http API to generate the map image. Use Web Tier API instead. The API should be one of the |
| 177 | {{{ |
| 178 | MgRenderingService::RenderMap(...) |
| 179 | }}} |
| 180 | The problem for the '''{{{MgRenderingService::RenderMap}}}''' API is: there is no way to set the DPI (In Http API, the DPI could be set by the '''{{{SETDISPLAYDPI}}}''' url parameter). So there is one new Web Tier API should be exposed: |
| 181 | {{{ |
| 182 | void MgMapBase::SetDisplayDpi(INT32 dpi) |
| 183 | }}} |
| 184 | |
| 185 | |